USINGMAC.com

USINGMAC.com

FUN WITH USING A MAC

FUN WITH USING A MAC

FEB
11

I will write series of articles about Web Development Using PHP, this is the part one of those, about activating and installing PHP first. Mac OS X Leopard comes with Apache 2.2 bundle with PHP 5 by default. Beside they still provide option to switch back to PHP4 and also you can actually activate back Apache 1.3 web server. But for PHP, we need to activate it with few steps, which we will cover on this tutorial. We can start the apache web server use the System Preferences » Sharing » Just check the Web Server option.

Start Web Server

Once it start, you can go to http://127.0.0.1/~username/ for your own personal website which located at /Users/username/Sites. And for the root website, which you can access from http://127.0.0.1/ and it located at

The configuration file for apache2 located at /private/etc/apache2/httpd.conf, we will need to edit the file to activate PHP5, by default PHP5 module is not activated. Open the file by clicking on your finder then press G then key in /private/etc/apache2/ then open up httpd.conf using your TextEdit application.

Location of httpd.conf

Location of httpd.conf

Search for the line with:


#LoadModule php5_module libexec/apache2/libphp5.so

Then uncomment the line to become:


LoadModule php5_module libexec/apache2/libphp5.so

Save first, then go to System Preferences » Sharing and restart the web server again to get PHP up and running. To test whether the PHP its ON, lets create a file called: index.php inside ~/Sites/ folder. Below is the content of index.php:

phpinfo

You can see this page, mean you already success activate PHP

php info

Another way to do this is to type the following in the Terminal application:


sudo apachectl start

You will be prompted to enter your root password. After that, your apache server should now be running. If you need to restart the server from the terminal, you can type this:


sudo apachectl restart

You also may prefer to use one of the 3rd party distributions of PHP, such as MAMP, XAMPP and Marc Liyanage.

Filed in categories: Development

Related topics :

COMMENTS

Mojo

February 20th, 2008 at 05:35 AM

You can't save httpd.conf without sudo.

K

March 31st, 2008 at 12:20 PM

Mojo is correct. Use this command (in the terminal) to open the file in TextEdit so that it can be modified: sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /private/etc/apache2/httpd.conf


LEAVE.A.REPLY

Your Name:

Your Email:

Your Website: