Running PHP5.3.x and Apache on a Mac

Hi,

In 2007 I became a switcher and life got easier for me… everything got easier, except installing PHP and Apache. So, mainly for myself–I thought to write this small “handy”? tutorial on how to install this quickly. The reason behind is also because I recently re-installed my Mac and am at this point again. This lets me just copy-and-paste for me in the future 😛

Apache & PHP

So, Apache comes installed together with PHP on a Mac. Handy? No, not really. The bundle installed is not really that good and a lot is missing in the installation which you need later on. A real bitch is to get Magento to work on your mac (in case you use Magento for e.g. clients). Magento requires some modules that I am not even going to start thinking about in this manual (that will come later).

So, I assume you have a freshly installed Mac(Book?) as I have. I installed XCode as well before I started with this.

The first thing you need to do is to install MacPorts. When macports is installed you will need to install the PHP5.

When MacPorts is installed, it doesn’t always have the “/opt/local/bin” or “/opt/local/sbin” to your $PATH already. If those are not there, add them. Do:

and add this line:

Now lets start of with a selfupdate for macports. Write:

When done, write:

This will install PHP5 along with apache and a bunch of other stuff.
When this is done, you would like to make sure apache is loaded whenever you reboot, so write:

Now that PHP5 is installed, it is not yet loaded into Apache. What we need to do is to adapt the httpd.conf file. While we are editing this file anyways… lets also adapt the document root so that it is not set to some weird directory which you will never used, but to your Sites folder locatd in your home directory.

Write:

Scroll down a bit and you will find a bunch of “LoadModule” rows. Beneath them add the following two rows:

Now scroll a bit more until you see the “User / Group” section (show be right below where you added your lines).

Here, change this to your user settings. In my case my username is “paulp” so I set “User” to “paulp” (without “) and group should be set to “staff” (again, without “). You can find this out by checking you “/Users” folder. Your folder is called “/Users/paulp/…”.

Now, scroll a bit more until you see “DocumentRoot”. Change this to “/Users/MYUSERNAME/Sites”. MYUSERNAME should be replace with… you guessed it! Your username! (In my case: paulp).

Scroll down to “<Directory />” and change it so it looks like this:

Scroll down to “<Directory “/opt/local/apache2/htdocs”>” (should be right below) and change it to this:

Scroll down to “DirectoryIndex index.html” and add “index.php” (without “)

and… your done here. Save and close the file.

Now you can restart apache. Write:

Wait… this is anoying… write this as well:

So, now you will only have to write “httpd -k restart” in the future.

Now lets install some more packages for PHP. Write the following:

This should keep your terminal busy for a while. So why without mysql5-server? Don’t we need that one as well? Yep, but we are going to install that sucker manually after port is done installing.

Install MySQL

I prefer to install MySQL with the package from their website, so visit the download page for the latest X86 version: http://www.mysql.com/downloads/mirror.php?id=397978#mirrors and download MySQL.

When downloaded, install using the DMG file.

When MySQL is installed, in my case the /etc/my.cnf file was still missing, I fixed this using the MySQL GUI Workbench tool which you can download at mysql.com. It creates this file for you with your preffered settings.

Conclusion

Now everything should be installed and you should be able to go to localhost in your webbrowser. Also PHP should be able to connect to MySQL and do a lot more feaky stuff.

Cheers,

/Paul

Posted in Apache, Apple, Development, iTunes Connect, Mac, MySQL, Okategoriserade, OSX, PHP Tagged with: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

 

Categories