Thursday, March 25, 2010

Setting up a local virtual server in Linux

If you're like me, then you design web sites on your local server before pushing the update out to the site.  I tend to take http://www.domain.com and make my local server http://domain/.  This allows me to fully test and run the site just as it runs on the server, but without the lag/extra steps with working on the server itself, not to mention my changes don't effect the visitor's experience until I push the update.

To do this, go to:

/etc/hosts/

It will look like this:


127.0.0.1       localhost

You need to update this file so your browser knows to look locally for the domain.  Add a line for your domain name...

127.0.0.1       domain
OR
127.0.0.1       domain2.loc


Next you need to tell apache about your new domain. Go to /etc/apache2/sites-available/ and create a file for your new domain. Since my new domain is literally "domain" that's what I will call my file, with no file extension. Within that file I'll put this....

NameVirtualHost domain:80

<VirtualHost domain:80>
ServerName domain
DocumentRoot /var/www/domain/
</VirtualHost>

Once you've got this setup you're good to go. All you need to do is restart apache...

/etc/init.d/apache2 restart

Now I can access this local domain by simply typing http://domain/ and it won't effect the users browsing my site.

Wednesday, March 24, 2010

Internet Explorer (IE) and image/pjpeg, what's that all about?

I had a user report to me today that jpg image uploads were not functioning. I had him send me the images so that I could try uploading them to my site. They worked just fine. So what's the problem? Some genius over at Microsoft decided that instead of using image/jpeg as the mime type for JPG's they would use image/pjpeg.

If you're checking mime types for your image uploads, be sure to include image/pjpeg in the list or you'll find yourself dealing with bug reports.

Tuesday, March 16, 2010

Server Load Average and what to do about it

To take a look at your load average, to your server's command line and type "top" and it'll show you the top processes your server is running.

I was going to write up some descriptions on this as my research continued, but I found the perfect source. So rather than rewrite it the guide and try to explain things I don't have an expert's opinion on, I'm going to forward to a real source, that knows what they're talking about.

Understanding Linux CPU Load - when should you be worried?

Wednesday, March 10, 2010

Determine if PHP file is being access via Cron

I ran into an issue where I needed to determine which config settings to load in my API. It picks up automatically whether I'm working locally or on the server. It kept loading the local configuration based on my code. So I asked some smarter people for some assistance and was given the right answer. This will determine whether it's being loaded via command line.

if (php_sapi_name() == 'cli') {
    return true;
} else {
    return false;
}

Friday, December 4, 2009

Timezone List in MySQL

Below you can find a list of all timezones and their offsets.

CREATE TABLE IF NOT EXISTS `time_zone` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL DEFAULT '',
  `offset` float NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=40 ;

INSERT INTO `time_zone` (`id`, `name`, `offset`) VALUES
(1, '(-12:00) Enitwetok, Kwajalien', -12),
(2, '(-11:00) Midway Island, Samoa', -11),
(3, '(-10:00) Hawaii', -10),
(4, '(-9:30) French Polynesia', -9.5),
(5, '(-9:00) Alaska', -9),
(6, '(-8:00) Pacific Time (US & Canada)', -8),
(7, '(-7:00) Mountain Time (US & Canada)', -7),
(8, '(-6:00) Central Time (US & Canada), Mexico City', -6),
(9, '(-5:00) Eastern Time (US & Canada), Bogota, Lima', -5),
(10, '(-4:00) Atlantic Time (Canada), Caracas, La Paz', -4),
(11, '(-3:30) Newfoundland', -3.5),
(12, '(-3:00) Brazil, Buenos Aires, Falkland Is.', -3),
(13, '(-2:00) Mid-Atlantic, Ascention Is., St Helena', -2),
(14, '(-1:00) Azores, Cape Verde Islands', -1),
(15, 'Casablanca, Dublin, London, Lisbon, Monrovia', 0),
(16, '(+1:00) Brussels, Copenhagen, Madrid, Paris', 1),
(17, '(+2:00) Kaliningrad, South Africa', 2),
(18, '(+3:00) Baghdad, Riyadh, Moscow, Nairobi', 3),
(19, '(+3:30) Tehran', 3.5),
(20, '(+4:00) Abu Dhabi, Baku, Muscat, Tbilisi', 4),
(21, '(+4:30) Kabul', 4.5),
(22, '(+5:00) Ekaterinburg, Karachi, Tashkent', 5),
(23, '(+5:30) Bombay, Calcutta, Madras, New Delhi', 5.5),
(24, '(+5:45) Kathmandu', 5.75),
(25, '(+6:00) Almaty, Colombo, Dhaka', 6),
(26, '(+6:30) Yangon, Naypyidaw, Bantam', 6.5),
(27, '(+7:00) Bangkok, Hanoi, Jakarta', 7),
(28, '(+8:00) Hong Kong, Perth, Singapore, Taipei', 8),
(29, '(+8:45) Caiguna, Eucla', 8.75),
(30, '(+9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk', 9),
(31, '(+9:30) Adelaide, Darwin', 9.5),
(32, '(+10:00) Melbourne, Papua New Guinea, Sydney', 10),
(33, '(+10:30) Lord Howe Island', 10.5),
(34, '(+11:00) Magadan, New Caledonia, Solomon Is.', 11),
(35, '(+11:30) Burnt Pine, Kingston', 11.5),
(36, '(+12:00) Auckland, Fiji, Marshall Island', 12),
(37, '(+12:45) Chatham Islands', 12.75),
(38, '(+13:00) Kamchatka, Anadyr', 13),
(39, '(+14:00) Kiritimati', 14);

Country List in MySQL

Below you'll find a list of all the countries in the world. Useful for utilizing them on your web site.

CREATE TABLE IF NOT EXISTS `country` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=242 ;

INSERT INTO `country` (`id`, `name`) VALUES
(1, 'United States'),
(2, 'Canada'),
(3, 'Mexico'),
(4, 'Afghanistan'),
(5, 'Albania'),
(6, 'Algeria'),
(7, 'Andorra'),
(8, 'Angola'),
(9, 'Anguilla'),
(10, 'Antarctica'),
(11, 'Antigua and Barbuda'),
(12, 'Argentina'),
(13, 'Armenia'),
(14, 'Aruba'),
(15, 'Ascension Island'),
(16, 'Australia'),
(17, 'Austria'),
(18, 'Azerbaijan'),
(19, 'Bahamas'),
(20, 'Bahrain'),
(21, 'Bangladesh'),
(22, 'Barbados'),
(23, 'Belarus'),
(24, 'Belgium'),
(25, 'Belize'),
(26, 'Benin'),
(27, 'Bermuda'),
(28, 'Bhutan'),
(29, 'Bolivia'),
(30, 'Bophuthatswana'),
(31, 'Bosnia-Herzegovina'),
(32, 'Botswana'),
(33, 'Bouvet Island'),
(34, 'Brazil'),
(35, 'British Indian Ocean'),
(36, 'British Virgin Islands'),
(37, 'Brunei Darussalam'),
(38, 'Bulgaria'),
(39, 'Burkina Faso'),
(40, 'Burundi'),
(41, 'Cambodia'),
(42, 'Cameroon'),
(44, 'Cape Verde Island'),
(45, 'Cayman Islands'),
(46, 'Central Africa'),
(47, 'Chad'),
(48, 'Channel Islands'),
(49, 'Chile'),
(50, 'China, Peoples Republic'),
(51, 'Christmas Island'),
(52, 'Cocos (Keeling) Islands'),
(53, 'Colombia'),
(54, 'Comoros Islands'),
(55, 'Congo'),
(56, 'Cook Islands'),
(57, 'Costa Rica'),
(58, 'Croatia'),
(59, 'Cuba'),
(60, 'Cyprus'),
(61, 'Czech Republic'),
(62, 'Denmark'),
(63, 'Djibouti'),
(64, 'Dominica'),
(65, 'Dominican Republic'),
(66, 'Easter Island'),
(67, 'Ecuador'),
(68, 'Egypt'),
(69, 'El Salvador'),
(70, 'England'),
(71, 'Equatorial Guinea'),
(72, 'Estonia'),
(73, 'Ethiopia'),
(74, 'Falkland Islands'),
(75, 'Faeroe Islands'),
(76, 'Fiji'),
(77, 'Finland'),
(78, 'France'),
(79, 'French Guyana'),
(80, 'French Polynesia'),
(81, 'Gabon'),
(82, 'Gambia'),
(83, 'Georgia Republic'),
(84, 'Germany'),
(85, 'Gibraltar'),
(86, 'Greece'),
(87, 'Greenland'),
(88, 'Grenada'),
(89, 'Guadeloupe (French)'),
(90, 'Guatemala'),
(91, 'Guernsey Island'),
(92, 'Guinea Bissau'),
(93, 'Guinea'),
(94, 'Guyana'),
(95, 'Haiti'),
(96, 'Heard and McDonald Isls'),
(97, 'Honduras'),
(98, 'Hong Kong'),
(99, 'Hungary'),
(100, 'Iceland'),
(101, 'India'),
(102, 'Iran'),
(103, 'Iraq'),
(104, 'Ireland'),
(105, 'Isle of Man'),
(106, 'Israel'),
(107, 'Italy'),
(108, 'Ivory Coast'),
(109, 'Jamaica'),
(110, 'Japan'),
(111, 'Jersey Island'),
(112, 'Jordan'),
(113, 'Kazakhstan'),
(114, 'Kenya'),
(115, 'Kiribati'),
(116, 'Kuwait'),
(117, 'Laos'),
(118, 'Latvia'),
(119, 'Lebanon'),
(120, 'Lesotho'),
(121, 'Liberia'),
(122, 'Libya'),
(123, 'Liechtenstein'),
(124, 'Lithuania'),
(125, 'Luxembourg'),
(126, 'Macao'),
(127, 'Macedonia'),
(128, 'Madagascar'),
(129, 'Malawi'),
(130, 'Malaysia'),
(131, 'Maldives'),
(132, 'Mali'),
(133, 'Malta'),
(134, 'Martinique (French)'),
(135, 'Mauritania'),
(136, 'Mauritius'),
(137, 'Mayotte'),
(139, 'Micronesia'),
(140, 'Moldavia'),
(141, 'Monaco'),
(142, 'Mongolia'),
(143, 'Montenegro'),
(144, 'Montserrat'),
(145, 'Morocco'),
(146, 'Mozambique'),
(147, 'Myanmar'),
(148, 'Namibia'),
(149, 'Nauru'),
(150, 'Nepal'),
(151, 'Netherlands Antilles'),
(152, 'Netherlands'),
(153, 'New Caledonia (French)'),
(154, 'New Zealand'),
(155, 'Nicaragua'),
(156, 'Niger'),
(157, 'Niue'),
(158, 'Norfolk Island'),
(159, 'North Korea'),
(160, 'Northern Ireland'),
(161, 'Norway'),
(162, 'Oman'),
(163, 'Pakistan'),
(164, 'Panama'),
(165, 'Papua New Guinea'),
(166, 'Paraguay'),
(167, 'Peru'),
(168, 'Philippines'),
(169, 'Pitcairn Island'),
(170, 'Poland'),
(171, 'Polynesia (French)'),
(172, 'Portugal'),
(173, 'Qatar'),
(174, 'Reunion Island'),
(175, 'Romania'),
(176, 'Russia'),
(177, 'Rwanda'),
(178, 'S.Georgia Sandwich Isls'),
(179, 'Sao Tome, Principe'),
(180, 'San Marino'),
(181, 'Saudi Arabia'),
(182, 'Scotland'),
(183, 'Senegal'),
(184, 'Serbia'),
(185, 'Seychelles'),
(186, 'Shetland'),
(187, 'Sierra Leone'),
(188, 'Singapore'),
(189, 'Slovak Republic'),
(190, 'Slovenia'),
(191, 'Solomon Islands'),
(192, 'Somalia'),
(193, 'South Africa'),
(194, 'South Korea'),
(195, 'Spain'),
(196, 'Sri Lanka'),
(197, 'St. Helena'),
(198, 'St. Lucia'),
(199, 'St. Pierre Miquelon'),
(200, 'St. Martins'),
(201, 'St. Kitts Nevis Anguilla'),
(202, 'St. Vincent Grenadines'),
(203, 'Sudan'),
(204, 'Suriname'),
(205, 'Svalbard Jan Mayen'),
(206, 'Swaziland'),
(207, 'Sweden'),
(208, 'Switzerland'),
(209, 'Syria'),
(210, 'Tajikistan'),
(211, 'Taiwan'),
(212, 'Tahiti'),
(213, 'Tanzania'),
(214, 'Thailand'),
(215, 'Togo'),
(216, 'Tokelau'),
(217, 'Tonga'),
(218, 'Trinidad and Tobago'),
(219, 'Tunisia'),
(220, 'Turkmenistan'),
(221, 'Turks and Caicos Isls'),
(222, 'Tuvalu'),
(223, 'Uganda'),
(224, 'Ukraine'),
(225, 'United Arab Emirates'),
(226, 'Uruguay'),
(227, 'Uzbekistan'),
(228, 'Vanuatu'),
(229, 'Vatican City State'),
(230, 'Venezuela'),
(231, 'Vietnam'),
(232, 'Virgin Islands (Brit)'),
(233, 'Wales'),
(234, 'Wallis Futuna Islands'),
(235, 'Western Sahara'),
(236, 'Western Samoa'),
(237, 'Yemen'),
(238, 'Yugoslavia'),
(239, 'Zaire'),
(240, 'Zambia'),
(241, 'Zimbabwe');

Saturday, November 21, 2009

Setting up a local Virtual Host using WAMP/Apache

Setting up a virtual host will allow you to essentially run an exact copy of your site locally.  You'll need to decide on a local domain name.  My standard is to only maintain the primary name.  So for instance if the site is http://www.domain.com then I will use http://domain/ for the local copy.  Some people decide to use http://domain.loc/.

Once you've decided, open C:\Windows\System32\drivers\etc and open the hosts file.

It should look like this when opened:

127.0.0.1       localhost
::1             localhost

Add a new line

127.0.0.1       localhost
127.0.0.1       domain
::1             localhost

Replace "domain" with "domain.loc" if you want.

Next you're going to need to locate your Apache installation. In WAMP, you're going to need to open C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf and add the line:



    ServerAdmin webmaster@localhost
    DocumentRoot "c:/wamp/www/domain"
    ServerName domain
    ErrorLog "logs/domain.log"
    CustomLog "logs/domain.log" common
    
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Allow,Deny
        Allow from all
        Allow from 127.0.0.1
    

AFTER

NameVirtualHost *:80



    DocumentRoot "c:/wamp/www"
    ServerName localhost

If you're using .loc, all you should have to do is add .loc to the ServerName, NOT to the paths defining the location to load.