Apache, PHP and MySQL on Mac OSX

If you are a Mac user, I have a small surprise for you. Mac OSX comes bundled with Apache, php and mysql. Yes the whole stack !

Generally on Mac the users are used to checking the application folder for installed apps, when they don’t find neither apache or mysql they tend to install a tech. stack from the net like XAMPP . Actually you don’t need to do so, you already have all what you need. For the rest of the blog, I will guide you how to configure and use them …

Apache

To start Apache Web Server, do the following steps

1. Open “System Preferences” Control  Panel [located in the Apple Menu]
2. Click on the icon named “Sharing”
3. The sharing screen is split into two sections, on the left section a list of sharing services are listed. Select “Web Sharing” and enable the check box beside it.
4. Now if everything went ok, apache should be working ..
To test, open browser and write http://localhost , a page should be saying “It Works”.

You can deploy your web applications in the “Sites” folder and access it using the following url http://localhost/~username [replace username with your mac user]

If you need to edit Apache’s configuration files, you can go to the folder “/etc/apache2″

You can also start  way to do this is to type the following in the Terminal application:
sudo apachectl start

PHP

By default, PHP is disabled along with other features of the Apache Web Server, but we are going to concentrate on enabling PHP.

1. Start the Terminal.app located in the “/Applications/Utilities/” directory.
2. Navigate to “/etc” and create the php configuration file
sudo cp php.ini.default php.ini
3. Edit “php.ini” , search for “mysql.default_socket editing it to the following
mysql.default_socket = /tmp/mysql.sock

4. Navigate to the apache directory “cd /etc/apache2″.
5. Use the root privilege to edit “httpd.conf” using your favorite editor.
6. Locate the following line and uncomment it by removing the “#“.
#LoadModule php5_module libexec/apache2/libphp5.so
7. Restart apache using the command
sudo apachectl restart
8. You can now test php by creating a new file with “test.php” extension containing the following line and placing it in the “Sites” folder.
< ?php phpinfo(); ?>
9. Acces it using the url and you should see the php info page if everything went ok.
http://localhost/~username/test.php

MySQL
Download the MySQL package for Mac OS X.5 (32 or 64 bits depending on your machine)
2. Install everything in the package in this order: mysql, the startup item, the preference pane.
3. Start MySQL in the preference pane.
4. Test it’s working:
/usr/local/mysql/bin/mysql
Bookmark and Share

Leave a Reply