Installing PHP on a Mac

One great aspect of Mac OS is that it ships with a preinstalled Apache server and PHP4. So if you want to develop dynamic PHP based web sites on your local machine, you just have to enable the PHP4 module and start the server.

The sharing preferences provide the functionality to start the Apache server

As you might know, you can start the Apache server by switching to the sharing preferences and activating the option “Personal Web Sharing”. If you now launch Safari and connect to “http://localhost” you should get Apaches’s welcome page telling you that the server has been started successfully. By the way the content of your “sites” folder, located in your user home, can be accessed by appending “˜yourUsername” to the URL.

Apache’s welcome page

In order to determine whether the PHP module is already enabled or not, navigate to the “sites” folder and create a new PHP file called “phpinfo.php”. Open the file and insert the following piece of code:

<?php phpinfo() ?> The phpinfo file located in the sites folder Now if you open the file in your browser, you might notice that the php command is not interpreted by the server. This is because the PHP module is not enabled by default.

PHP4

In order to enable the preinstalled PHP4 module you have to open Apache’s configuration file, located under /etc/http/http.conf. Open the file in your favorite editor and uncomment the lines containing “LoadModule php4_module” and “AddModule mod_php4.c”. Save the file and restart your Apache.

If you now reload your phpinfo file you should get a detailed list, contaning information on the configuration of your PHP module. If you don’t want to make use of PHP5’s object oriented functionalities you can stop reading here and enjoy your new PHP enabled Apache server.

PHP5

But if you are like me and enjoy the new OOP functionality, navigate to Marc Liyanage’s Website and download the PHP5 package for Apache 1.3. The size of the package is about 27MB — so it might take a while before the download is finished. Now mount the disk image and run the installer. Afterwards restart your server and once again display the phpinfo file — you will notice that the version 5.04 of PHP has been installed successfully. Enjoy.

PHP5 installed successfully

11 comments

Bookmark created — I’ll need this as soon as I’ve got a mac…

Julian

Much better, quicker and more easily to install is MAMP by webedition: Link

HDberg

Wie kommts denn, dass du zwar nen deutsches OSX laufen hast, aber die Screenshots aus dem Tutorial (Creating organic Desctops) von einer englischen Photoshop-Version kommen? Hast du beide Versionen von Photoshop und Illustrator installiert?

Philipp Daun

Ich probiere gerade die Tryout-Version von Photoshop CS2 — die gibt’s derzeit jedoch nur auf Englisch. Daher die Unterschiede.

Wolfgang

Hier gibt es die deutsche Tryout Version von Photoshop CS 2: Link

Arne

Oh, danke für den Link.

Wolfgang

Can I see the directory /etc also in the Finder or only in Terminal?

Florian Siebert

Alternativly you may navigate to the folder via the Finder’s “Go to to folder” command.

Wolfgang

I have also installed the MAMP server on my iMac and it works well. But progamming on a Mac with the standard keyboard is terrible and the editors on Windows are much better. Apart form this, nice Homepage and wonderful Design! Bernd

Bernd Lutz

why being an apple fan and explaining about how to install php,…., is your site using ASP? i am not being cheeky just curious….

fishmouth

This has been created about two years ago — the PHP version is already finished. I’m just waiting for my provider to install PHP5. -----

Wolfgang

Commenting is not available in this channel entry.