Archive for July, 2010

Single .htaccess file in your git repo for both your dev and production server

Problem:

You want to have dev.yoursite.com and www.yoursite.com but you don’t want dev.yoursite.com visible to the public.

Solution:

If your using apache(which many of us are),

.htaccess and .htpasswd to the rescue.

In your .htaccess file add:

SetEnvIf Host yourstagingserver.com passreq AuthType Basic AuthName “Staging Server” AuthUserFile /path/to/.htpasswd Require valid-user Order allow,deny Allow from all Deny from env=passreq Satisfy any

Configure your password file on both dev & production

Wherever you specify the /path/to/.htpasswd file navigate to that folder from the console and type “htpasswd -c .htpasswd mark”   where mark is the first user you want to create a login for. For each additonal person type “htpasswd .htpasswd linda”  where linda is the next username you want to add to the .htpasswd file. Each time  it will  prompt you to type in the password twice.(your password will be stored in the .htpasswd file) encrypted next to the username you created.

*Note:

AuthUserFile expects an absolute path, but if you don't start your path with a forward slash, it defaults to the directory you specify in your httpd.conf file as ServerRoot.

Country Codes in PHP Array

A PHP array list of all of the countries.
$options["AF"] = "Afghanistan";  
$options["AX"] = "Åland Islands";  
$options["AL"] = "Albania ";  
$options["DZ"] = "Algeria ";  
$options["AS"] = "American Samoa";  
$options["AD"] = "Andorra";  
$options["AO"] = "Angola ";
$options["AI"] = "Anguilla ";
$options["AQ"] = "Antarctica ";
$options["AG"] = "Antigua and Barbuda ";
$options["AR"] = "Argentina";
$options["AU"] = "Australia ";
$options["AT"] = "Austria ";
$options["AZ"] = "Azerbaijan";
$options["BS"] = "Bahamas ";
$options["BH"] = "Bahrain ";
$options["BD"] = "Bangladesh ";
$options["BB"] = "Barbados ";
$options["BY"] = "Belarus";
$options["BE"] = "Belgium ";
$options["BZ"] = "Belize ";
$options["BJ"] = "Benin ";
$options["BM"] = "Bermuda ";
$options["BT"] = "Bhutan";
$options["BO"] = "Bolivia ";
$options["BA"] = "Bosnia and Herzegovina ";
$options["BW"] = "Botswana ";
$options["BV"] = "Bouvet Island ";
$options["BR"] = "Brazil";
$options["IO"] = "British Indian Ocean Territory ";
$options["BN"] = "Brunei Darussalam ";
$options["BG"] = "Bulgaria ";
$options["BF"] = "Burkina Faso ";
$options["BI"] = "Burundi";
$options["KH"] = "Cambodia ";
$options["CM"] = "Cameroon ";
$options["CA"] = "Canada ";
$options["CV"] = "Cape Verde ";
$options["KY"] = "Cayman Islands ";
$options["CF"] = "Central African Republic ";
$options["TD"] = "Chad ";
$options["CL"] = "Chile ";
$options["CN"] = "China ";
$options["CX"] = "Christmas Island";
$options["CC"] = "Cocos (Keeling) Islands ";
$options["CO"] = "Colombia ";
$options["KM"] = "Comoros ";
$options["CG"] = "Congo ";
$options["CD"] = "Congo, the Democratic Republic of the";
$options["CK"] = "Cook Islands ";
$options["CR"] = "Costa Rica ";
$options["CI"] = "Côte D'Ivoire";
$options["HR"] = "Croatia ";
$options["CU"] = "Cuba ";
$options["CY"] = "Cyprus ";
$options["CZ"] = "Czech Republic ";
$options["DK"] = "Denmark";
$options["DJ"] = "Djibouti ";
$options["DM"] = "Dominica ";
$options["DO"] = "Dominican Republic ";
$options["EC"] = "Ecuador ";
$options["EG"] = "Egypt";
$options["SV"] = "El Salvador ";
$options["GQ"] = "Equatorial Guinea ";
$options["ER"] = "Eritrea ";
$options["EE"] = "Estonia ";
$options["ET"] = "Ethiopia ";
$options["FK"] = "Falkland Islands (Malvinas) ";
$options["FO"] = "Faroe Islands ";
$options["FJ"] = "Fiji ";
$options["FI"] = "Finland ";
$options["FR"] = "France";
$options["GF"] = "French Guiana ";
$options["PF"] = "French Polynesia ";
$options["TF"] = "French Southern Territories ";
$options["GA"] = "Gabon ";
$options["GM"] = "Gambia ";
$options["GE"] = "Georgia ";
$options["DE"] = "Germany ";
$options["GH"] = "Ghana ";
$options["GI"] = "Gibraltar ";
$options["GR"] = "Greece";
$options["GL"] = "Greenland ";
$options["GD"] = "Grenada ";
$options["GP"] = "Guadeloupe ";
$options["GU"] = "Guam ";
$options["GT"] = "Guatemala";
$options["GG"] = "Guernsey ";
$options["GN"] = "Guinea ";
$options["GW"] = "Guinea-Bissau ";
$options["GY"] = "Guyana ";
$options["HT"] = "Haiti";
$options["HM"] = "Heard Island and Mcdonald Islands ";
$options["VA"] = "Holy See (Vatican City State) ";
$options["HN"] = "Honduras ";
$options["HK"] = "Hong Kong ";
$options["HU"] = "Hungary";
$options["IS"] = "Iceland ";
$options["IN"] = "India ";
$options["ID"] = "Indonesia ";
$options["IR"] = "Iran, Islamic Republic of ";
$options["IQ"] = "Iraq ";
$options["IE"] = "Ireland ";
$options["IM"] = "Isle of Man ";
$options["IL"] = "Israel ";
$options["IT"] = "Italy ";
$options["JM"] = "Jamaica";
$options["JP"] = "Japan ";
$options["JE"] = "Jersey ";
$options["JO"] = "Jordan ";
$options["KZ"] = "Kazakhstan ";
$options["KE"] = "KENYA";
$options["KI"] = "Kiribati ";
$options["KP"] = "Korea, Democratic People's Republic of ";
$options["KR"] = "Korea, Republic of ";
$options["KW"] = "Kuwait ";
$options["KG"] = "Kyrgyzstan";
$options["LA"] = "Lao People's Democratic Republic ";
$options["LV"] = "Latvia ";
$options["LB"] = "Lebanon ";
$options["LS"] = "Lesotho ";
$options["LR"] = "Liberia";
$options["LY"] = "Libyan Arab Jamahiriya ";
$options["LI"] = "Liechtenstein ";
$options["LT"] = "Lithuania ";
$options["LU"] = "Luxembourg ";
$options["MO"] = "Macao";
$options["MK"] = "Macedonia, the Former Yugoslav Republic of ";
$options["MG"] = "Madagascar ";
$options["MW"] = "Malawi ";
$options["MY"] = "Malaysia ";
$options["MV"] = "Maldives";
$options["ML"] = "Mali ";
$options["MT"] = "Malta ";
$options["MH"] = "Marshall Islands ";
$options["MQ"] = "Martinique ";
$options["MR"] = "Mauritania";
$options["MU"] = "Mauritius ";
$options["YT"] = "Mayotte ";
$options["MX"] = "Mexico ";
$options["FM"] = "Micronesia, Federated States of ";
$options["MD"] = "Moldova, Republic of";
$options["MC"] = "Monaco ";
$options["MN"] = "Mongolia ";
$options["ME"] = "Montenegro ";
$options["MS"] = "Montserrat ";
$options["MA"] = "Morocco";
$options["MZ"] = "Mozambique ";
$options["MM"] = "Myanmar ";
$options["NA"] = "Namibia ";
$options["NR"] = "Nauru ";
$options["NP"] = "Nepal";
$options["NL"] = "Netherlands ";
$options["AN"] = "Netherlands Antilles ";
$options["NC"] = "New Caledonia ";
$options["NZ"] = "New Zealand ";
$options["NI"] = "Nicaragua";
$options["NE"] = "Niger ";
$options["NG"] = "Nigeria ";
$options["NU"] = "Niue ";
$options["NF"] = "Norfolk Island ";
$options["MP"] = "Northern Mariana Islands";
$options["NO"] = "Norway ";
$options["OM"] = "Oman ";
$options["PK"] = "Pakistan ";
$options["PW"] = "Palau ";
$options["PS"] = "Palestinian Territory, Occupied";
$options["PA"] = "Panama ";
$options["PG"] = "Papua New Guinea ";
$options["PY"] = "Paraguay ";
$options["PE"] = "Peru ";
$options["PH"] = "Philippines";
$options["PN"] = "Pitcairn ";
$options["PL"] = "Poland ";
$options["PT"] = "Portugal ";
$options["PR"] = "Puerto Rico ";
$options["QA"] = "Qatar";
$options["RE"] = "Réunion ";
$options["RO"] = "Romania ";
$options["RU"] = "Russian Federation ";
$options["RW"] = "Rwanda ";
$options["SH"] = "Saint Helena";
$options["KN"] = "Saint Kitts and Nevis ";
$options["LC"] = "Saint Lucia ";
$options["PM"] = "Saint Pierre and Miquelon ";
$options["VC"] = "Saint Vincent and the Grenadines ";
$options["WS"] = "Samoa";
$options["SM"] = "San Marino ";
$options["ST"] = "Sao Tome and Principe ";
$options["SA"] = "Saudi Arabia ";
$options["SN"] = "Senegal ";
$options["RS"] = "Serbia";
$options["SC"] = "Seychelles ";
$options["SL"] = "Sierra Leone ";
$options["SG"] = "Singapore ";
$options["SK"] = "Slovakia ";
$options["SI"] = "Slovenia";
$options["SB"] = "Solomon Islands ";
$options["SO"] = "Somalia ";
$options["ZA"] = "South Africa ";
$options["GS"] = "South Georgia and the South Sandwich Islands ";
$options["ES"] = "Spain";
$options["LK"] = "Sri Lanka ";
$options["SD"] = "Sudan ";
$options["SR"] = "Suriname ";
$options["SJ"] = "Svalbard and Jan Mayen ";
$options["SZ"] = "Swaziland";
$options["SE"] = "Sweden ";
$options["CH"] = "Switzerland ";
$options["SY"] = "Syrian Arab Republic ";
$options["TW"] = "Taiwan, Province of China ";
$options["TJ"] = "Tajikistan";
$options["TZ"] = "Tanzania, United Republic of ";
$options["TH"] = "Thailand ";
$options["TL"] = "Timor-Leste ";
$options["TG"] = "Togo ";
$options["TK"] = "Tokelau";
$options["TO"] = "Tonga ";
$options["TT"] = "Trinidad and Tobago ";
$options["TN"] = "Tunisia ";
$options["TR"] = "Turkey ";
$options["TM"] = "Turkmenistan";
$options["TC"] = "Turks and Caicos Islands ";
$options["TV"] = "Tuvalu ";
$options["UG"] = "Uganda ";
$options["UA"] = "Ukraine ";
$options["AE"] = "United Arab Emirates";
$options["GB"] = "United Kingdom ";
$options["US"] = "United States ";
$options["UM"] = "United States Minor Outlying Islands ";
$options["UY"] = "Uruguay ";
$options["UZ"] = "Uzbekistan";
$options["VU"] = "Vanuatu ";
$options["VA"] = "Vatican City State ";
$options["VE"] = "Venezuela ";
$options["VN"] = "Viet Nam ";
$options["VG"] = "Virgin Islands, British ";
$options["VI"] = "Virgin Islands, U.S. ";
$options["WF"] = "Wallis and Futuna";
$options["EH"] = "Western Sahara ";
$options["YE"] = "Yemen ";
$options["CD"] = "Zaire ";
$options["ZM"] = "Zambia ";
$options["ZW"] = "Zimbabwe ";

Useful Rackspace Tutorials

Apache Configuration Virtual Hosts(sites-available & sites-active):

Security: (SSH Keys):
http://cloudservers.rackspacecloud.com/index.php/BasicCloudServerSecurity
IPTables :
http://cloudservers.rackspacecloud.com/index.php/Sampleiptables_ruleset
APT-GET Repositories : For some reason the ubunto distro 9.04 didn’t have these added to its apt-get sources.list. So I added them.
deb http://us.archive.ubuntu.com/ubuntu/ hardy universe deb-src http://us.archive.ubuntu.com/ubuntu/ hardy universe deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe deb-src http://us.archive.ubuntu.com/ubuntu/ hardy-updates universe
Installing Ruby:
sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev mkdir ~/src && cd ~/src wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.gz tar -xvf ruby-1.9.1-p0.tar.gz cd ruby-1.9.1-p0 ./configure make make test sudo make install
Install Git Install Rails
sudo gem update –system sudo gem install rails
Install Ruby Mysql Modul
sudo gem install mysql

Install Pecl src : http://www.markfosteronline.com/2009/01/04/how-to-install-a-php-pecl-extensionmodule-on-ubuntu/

  • sudo apt-get install php-pear
  • sudo apt-get install php5-dev
  • sudo apt-get install libcurl4-openssl-dev
  • sudo pecl install pecl_http     just hit enter and use defaults

Monitor ETH Port

  • Use tcpdump -i eth0   to watch the ports
Install DTach – which allows you to run a session in a console, then dtach it, then go to another pc/console and attach.
  • apt-get install dtach
  • ex: dtach -A sessionname program arguments
    • press ctrl+\ to detach it from the terminal
    • then (from another computer or terminal) run “dtach -a sessionname”
  • ex:
    • dtach -A MyBashSession bash -l
    • [press ctrl+]
    • dtach -a MyBashSession
MySQL / Socket Not Found
  • sudo /etc/init.d/service mysql start
Install Zip
  • pecal install zip
  • * If it fails because of some error on expected = “” sudo apt-get install libpcre3-dev
Sources: http://rudygems.com/post/99075288/ruby-191-install

Linux command that are handy when configuring a new server

  • To view a user’s groups:
    “id [user]”
  • Add a user to a group :
    useradd -G {group-name} username
  • Add a user to multiple groups:
    usermod -a -G group1,group2 username
  • Change a users primary group:
    usermod -g group user
  • Add a group to a user
    usermod -a -G group user
  • Get a list of the groups:
    less /etc/group

Dropbox & Git… Don’t drop a git repo in GIT

Today i accidentally dropped a folder that had a git repo inside it into a dropbox folder.

Massive Memory Hog trying to index it both on update and delete….