Yesterday, I configured apache 2.2.3, php 5.2 and mysql 5.0.18. Alright, I know that’s not a big deal. But here are a few things that you must do in order for them to work seamlessly.

httpd.conf:
Add the following 4 lines to httpd.conf so that php will work correctly.

  • LoadModule php5_module /path/to/php/php5apache2_2.dll
  • PHPIniDir /path/to/php.ini (E.g. PHPIniDir “C:/PHP”. Note that the the path doesn’t end with “/php.ini”).
  • AddType application/x-httpd-php .php – This tells apache to handle PHP requests. If you want to add more extensions for php, E.g. say you want to process “.abc” files as PHP, then add “AddType application/x-httpd-php .abc”.
  • Find this line in your httpd.conf “DirectoryIndex index.html” and replace it with “DirectoryIndex index.html index.php”.

php.ini:
Go to the folder where you installed PHP. Open php.ini in your favourite text editor and find the line that says extension_dir = “./”. Replace that line with extension_dir = “/path/to/ext/folder”. Note that, there should be no trailing slash to the value of extension_dir.

my.ini:
Now go to the folder where you installed MySql. Try to start the MySQL daemon. I’m assuming that you haven’t installed MySQL as a service. If the mysql daemon (mysqld.exe) is running, try connecting to it by issuing the command on the command prompt.

“mysql -u <user_name>”

If you get an error like this “ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)”, open your my.ini file. Find the line that says “port=3306”. Replace it with a port number of your choice. There will be 2 such lines in my.ini. One is for server and the other is for client. Now try connecting again.

To run the mysql server in verbose mode, instead of just double clicking on mysqld.exe, open command prompt and type “mysqld –console“. This will give you a quick overview of what is happening.

When you run your php scripts that connects to mysql, you should now specify the port number also (if it is not 3306). E.g. $con = mysql_connect(“localhost:4000“, “user”, “password”);

After all these changes, don’t forget to restart your apache server. When you get an error dialog that says that some PHP extensions cannot be loaded, make a note of those extension names first. Now, open your php.ini. Search for “extension=php_”. Above the first extension line, add the missing extension DLLs. E.g. extension=php_pdo.dll etc.

These are some of the gotchas that I faced :-) Next I have to try and configure a Mongrel cluster for apache for running ruby on rails apps.

2 Responses to “Gotchas in installation of Apache, MySQL and PHP”

  1. Sathya Says:

    Thats cool work. I’ve done it in linux. Just edit the /etc/httpd/httpd.conf and start the server daemon, chmod +x /etc/rc.d/httpd and then run the script and /or add it to system startup.

  2. Aswin Anand Says:

    There’s a “install as a windows service” option available. But I didn’t use it coz the server need not be running all the time.