In this post I'm going to show you how to enable your PHP bundle that ships together with your Mac OS X Leopard. Done that, you can test your PHP scripts on a local basis, provided that you make the underlying Apache web server run (this is also included in your operating system). To accomplish this task, all you need is a free text editor like TextWrangler. First of all, a word of caution: Mac OS X uses Apache to share your web resources. You have to make sure that when you work with it you're properly protected by your system firewall (you can set it up on System Preferences > Sharing.
Step 1. Editing the httpd.conf file
- Open TextWrangler
- Select Open Hidden from your File menu
- Navigate to the folder /etc/apache2/
- Select the httpd.conf file
If the procedure is correct, you should see the following image:
Now open the httpd.conf file. Locate the following line:
#LoadModule php5_module libexec/apache2/libphp5.so
Now remove the '#' from this line and save the file. TextWrangler will prompt you to unlock the file. Click Unlock. Then Mac OS X will prompt you to insert your password, as shown below.
If you don't have any password set, just press Enter. After making sure that the file has been properly saved, close TextWrangler.
Step 2. Running the Apache web server
Go to System Preferences and select Sharing. Then select Web Sharing as shown below.
Step 3. Creating a phpinfo() file
Open TextWrangler, type the following and save the file as
<?php phpinfo(); ?>
Step 4. Viewing your PHP version
Copy or move
info.php to /Library/WebServer/Documents. Open your browser and type
http://localhost/info.php in the address bar. After opening the URL, you should see something like this:
The PHP version varies depending on your Leopard version. Anyway, now you're ready to use PHP on your system!