Installing PHP To Run With Your Web Server 1


Installing PHP To Run With Your Web Server


Did you know that your Mac has a fully built Apache web server built right in. You can access it through http://localhost/~User/ with all of the files stored in /Users/~User/Sites/ . This is a full apache install. When you turn web sharing on from System Preferences (System Preferences > Sharing > Web Sharing), a very important step, you can surf you Mac and serve a very basic web page/site. The problem with this is that it doesn’t have php enabled. This is a problem for anyone who wants to take it a step further and start developing more dynamic websites. As a result I have written this guide which will show you how to enable it. There are two methods the long and hard way which usually encounters many problems or the quick and easy way. This guide is intended for Leopard so it may differ on older systems. If you do encounter any problems leave a comment. I will try and answer them with the best of my knowledge, although it is out of the scope of this piece. As a side note enabling this is usually for development only and not to actually serve websites on the net, since it is highly unsecure. They are designed for developing websites. If you do want to serve websites on the internet I suggest finding a web host or reading more in depth into how this technology works.

Hard Long Way

This first method is for actually modifying the default install of Apache on your Mac, it will involve fiddling with system files and will need an Admin password. I tried this first on my Mac and I was met with limited success. Hence the long hard way. I have eventually given up and used the 2nd method. But I will put it in here for people who know a bit more about the system and want to actually change the files.

First open find and go to Go > Go To Folder and search for /etc this will open a system folder. Open Apache2. This is your default Apache install. Drag and drop httpd.conf to the desktop. It will not allow you to edit it in its current place unless you are a super user.

Open httpd.conf in text edit and search for the following line.
#LoadModule php5_module
Remove the hash (#) and save the file.

Copy and paste the file back into Apache2 and authenticate and replace the files. Hopefully if all goes well, PHP will be enabled and you are ready to go. On my computer it didn’t work so well and as a result I have found a better method that is a lot easier and anyone can do it. It doesn’t involve messing with system files and it is push button setup.

Easy Way

The easy way is actually to install xampp. It is a program that not just installs and configures PHP, but a whole load of other things including PHPmyAdmin, PHPmySQLAdmin, as well as a whole host of other features. As well as this it is easy to start and stop the service.

The first step is to download the install from the downloads page. Use the installer and disk image. Once it has download extract and install the package file. It may require you to ask for your password.

Once it has installed you find an application under Applications > xampp called control panel. Open this up and press start. PHP and other plugins will run and work on your computer. You don’t even have to have web sharing turned on.

You can then navigate to http://localhost/ and see the installation running with all plugins working. Its a lot easier and has hundreds of other options. This should be installed by default.

If you want to make a new site tree I recommend creating a new folder in Applications > xampp > htdocs (alias) > New Folder. This way you can create new sites and not mess with the existing files, since they are probably needed. You then in your browser navigation to http://localhost/New Folder/ and everything should run ok. Just remember this is design to be a development tool and not to be used as an actual installation. It does have some glaring security holes in it.

Hopefully you have successfully understood what I mean and you have managed to get php to work and run. The next part is to start developing websites. If you have any comments please leave them below.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips