Install Apache2, MySQL5.5 and PHP5.3 on OSX Lion

If you just installed OS X Lion or upgraded from Snow Leopard to Lion and want to use it as a developer web-server so it is possible.

This guide will help you get Apache2, MySQL5.5 and PHP5.3 to work on your machine so you are ready to develop without internet.

What you are installing when you follow this guide:
- Apache 2.2
- PHP 5.3
- MySQL 5.5

PHP modules are also being installed:
- php5_xdebug
- php5_mysql

Why I have chose PHP 5.3 instead of PHP 5.2 or older version of PHP:
This is due to PHP 5.3 allows me to use the namespace which only come in PHP 5.3, with the namespace I muglihed to bursting with my code even better.

Not only that I have personally afferet that with namespaces involved, I have the opportunity to wrong my files into very small bites are also known from C # when this is a natural thing for many developers.

Before you install:
The first thing you should do is to download and install MacPorts from their website MacPorts remember to have our latest Xcode installed to suit OS X Lion

Once installed, you can now open your terminal and install both Apache, PHP and MySQL

Start you basic setup:
Open your terminal and type the following lines

sudo port install apache2
sudo port install php5-devel
sudo port install mysql5-server-devel

It may take a little time, so take it one cup of coffee, cola or tea.

Now you are ready to install the following PHP modules which now must be on your system in my personal opinion, you can obviously do without the modules you do not want to install.

sudo port install php5-gd
sudo port install php5-imagick
sudo port install php5-memcache
sudo port install php5-memcached
sudo port install php5-mysql
sudo port install php5-openssl
sudo port install php5-soap
sudo port install php5-xdebug
sudo port install php5-curl
sudo port install php5-gettext

Once all your models are installed for PHP, we now config your MySQL database, it is done by us to install mysql’s database and then set the password for the root user.

sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'

For Apache and MySQL to even start up, you then use these 2 command lines!

sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

Now go into the Apache config file and paste the following 2 lines, search for AddType and LoadModule when you insert each simple line, it is very nemer, you use “nano” as a terminal editor, press the button (ctrl + w) to search

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php

Search DirectoryIndex and add filename “index.php” and then you save again by pressing ( CTRL + O ) and then ( Y )

To start Apache and MySQL up without having to reboot your machine, type 2 command lines.

sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start
sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start

Are you unlucky as I was that Apache gives this error message “httpd: Could not reliably Determine the server’s Fully Qualified Domain name, med Pariss-MacBook-Air.local for server name” you need to find ServerName in the httpd.conf file as you continue to have open and write your hostname as you can see the error message, what you write may look like this.

ServerName Pariss-MacBook-Air.local:80
 
Now you can save the file and pressing ( CTRL + O ), followed by "Y"

To create shortcuts to both MySQL and Apache which makes it faster for the restart, stop and start if someone were to go wrong can be done by writing these 2 lines.

alias apache2ctl='sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper'
alias mysql5='sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper'

Good luck and happy development

8 comments

  1. this is a failure says:

    “sudo: port: command not found”

  2. Lexa says:

    Just to clarify:
    sudo port install php5-gd
    sudo port install php5-imagick

  3. Lexa: Thanks for bug repport! :) now i have make the changes.

  4. sam says:

    What do you do with the apache that is already installed by default with Lion ?

    Thank you,
    Sam

  5. sam says:

    Thank you for the reply.

    Sam

  6. Christian says:

    You might like this http://php-osx.liip.ch/
    Also try out Brew https://github.com/mxcl/homebrew. So much better than Ports

Leave a Reply

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

*