Php Mysql Apache For Mac Os X

Posted on

For a list of macOS versions that the MySQL server supports, see

MySQL for macOS is available in a number of different forms:

  • Native Package Installer, which uses the native macOS installer (DMG) to walk you through the installation of MySQL. For more information, see Chapter 2, Installing MySQL on macOS Using Native Packages. You can use the package installer with macOS. The user you use to perform the installation must have administrator privileges.

  • Compressed TAR archive, which uses a file packaged using the Unix tar and gzip commands. To use this method, you will need to open a Terminal window. You do not need administrator privileges using this method, as you can install the MySQL server anywhere using this method. For more information on using this method, you can use the generic instructions for using a tarball, Installing MySQL on Unix/Linux Using Generic Binaries.

    In addition to the core installation, the Package Installer also includes Chapter 3, Installing a MySQL Launch Daemon and Chapter 4, Installing and Using the MySQL Preference Pane, both of which simplify the management of your installation.

For additional information on using MySQL on macOS, see Chapter 5, General Notes on Installing MySQL on macOS.

Let's install a Full Web server with Apache, PHP, MySQL a. Skip navigation Sign in. Instalar PHP, Apache, MySQL sobre Mac OS X con Mamp - Duration: 9:10. 33,218. Part 1: macOS 10.15 Catalina Web Development Environment. Developing web applications on macOS is a real joy. There are plenty of options for setting up your development environments, including the ever-popular MAMP Pro that provides a nice UI on top of Apache, PHP and MySQL.However, there are times when MAMP Pro has slow downs, or out of date versions, or is simply behaving badly due to its.

My last week's blog post on running Apache, MySQL, PHP server on Windows with multiple, simultaneous PHP versions seems to have been a smash hit. This week we'll be doing the same thing on Mac OS X. For those of you who didn't click the link, I decided it would be a cool, geeky project to implement an Apache-MySQL-PHP web server without using a pre-packaged server like MAMP or Zend Server. My goal was to have the same sites run under different versions of PHP by just visiting a different URL on my browser. This makes cross-PHP testing of sites a piece of cake.

Until now I was using Zend Server as my primary development environment. Since the last two major versions were becoming a bit of a resource hog. The much touted Z-Ray never really worked for me. That sealed its fate. I had to replace it with something nimbler and more convenient. I also wanted to no longer have to use MAMP to test my software across different PHP versions. I certainly did not want to have to go through the stop servers - change PHP version - start servers routine ever again. The process on Mac OS X is much more involving that what I had done on Windows last week but I was determined to succeed. And yes, I did succeed!

Disclaimer: the configuration I am proposing is only suitable for a local development server. Do try this at home and only at home – or at least not in a production server. The instructions below worked for me on Mac OS X Mavericks but should work on Lion and Mountain Lion. At the time of this writing OS X Yosemite is not released yet so your mileage may vary (read: serious breakage may occur). Another major pitfall is that the PHP binaries I am using are only supported on 64-bit Macs. If you have an old machine with an Intel Core Duo you're out of luck.

Warning: Pretty much all of the instructions have to be carried out using the command line. You can use Terminal (easy way to get there: type ⌘Space, type Terminal and hit ENTER) or another terminal emulator application such as iTerm2. If you don't feel comfortable using the command line stop reading now and download MAMP.

Setting up MySQL

Go to MySQL's download page and download the appropriate DMG package. For Mac OS X Lion and above it's the 'Mac OS X 10.8 (x86, 64-bit), DMG Archive'. For detailed installation instructions read MySQL's documentation page on Mac OS X installation. MySQL is installed to /usr/local/mysql

After installing MySQL, edit the file ~/.bash_profile Easy way to do it from the command line

Add this line at the bottom of the file

Close the terminal and open it again. Verify that you can access MySQL command line (note that it's a capital V in the command)

You should see something like

Good to know: Even though MySQL auto-starts on boot, you can still start and stop MySQL from the Terminal using the commands

Pro tip: I recommend using Sequel Pro to manage your MySQL databases instead of phpMyAdmin. It's much faster.

Setting up PHP

We will be using the pre-built binaries offered at It's one of the binary distributions recommended on and by far the easiest to install.

Install all versions of PHP you want to use. I chose all four of them. Please note that due to PHP 5.3 missing the FastCGI binary you must install it last.

Edit the file ~/.bash_profile The easy way to do it from the command line is typing

Add these lines at the bottom of the file

Note that the php5-5.4.32-20140822-093224 part is most likely different on your machine. You can find out which directory to use by typing in the Terminal

If you want to use a version different than PHP 5.4 as your default command line PHP executable just substitute 5.4 with 5.3, 5.5 or 5.6 in the command above.

Close the terminal application and open it again. Verify that you can access PHP command line

You should see something like

If you get an error you need to run the following commands in the Terminal

These commands will relink the PHP binaries and extensions to use the correct directories for our multi-PHP server.

At this point all PHP versions try to load the same PHP modules from the PHP 5.4 directory. This won't work. Luckily, it's an easy fix with some command line kung-fu. In your trusted Terminal enter:

Setting up Apache

We will be using Apache 2.2 which is helpfully shipped with Max OS X. Unlike previous versions of Mac OS X there is no longer a GUI to activate it, so we'll have to do everything old school, using our trusted command line. That's the beauty of Mac OS X: no matter how fancy the interface grows, it's still a pretty standard BSD system under the hood. Being BSD we can go old school with it any time we want. That's exactly what makes a geek rejoice!

Enabling FastCGI support

We're using Apache 2.2 shipped with Mac OS X, but it doesn't have built-in support for FastCGI and we need it to support multiple PHP versions. No problem, we can work around that by using MacPorts to get the missing bits.

If you haven't done so already, install MacPorts. I had it installed since a long time ago so please forgive me if there's a missing step here.

Close and reopen the Terminal application. Now type

Php Mysql Apache For Mac Os X64

After mod_fcgid is downloaded (it takes several minutes to install all of the dependencies) we need to move it to somewhere Apache can find it.

Edit the Apache configuration file /etc/apache2/httpd.conf You can only do that through the command line due to the advanced security model of Mac OS X Lion and later. I know, you can't use your mouse. You have to go really old school, using the keyboard. nano helpfully displays a list of common commands at the bottom rows. Press ⌃g to get the full list of keyboard commands. Remember that ^ stands for the ctrl (⌃) key and M stands for the alt (⌥) key. Therefore ^ k means hold down the ctrl key and press the K key, M a means hold down the alt key and press the A key and M A means hold down the alt and shift keys and press the A key. Congrats, you had your crash course in UNIX file editing. OK, back to the command to edit the file:

Find all the LoadModule lines. After the last one add

Save and close the file by pressing ⌃x, then Y, then ENTER.

Now restart Apache

If you screwed up, Apache will complain. If you get no feedback after running this command it worked just fine. In true UNIX tradition you get a message only if something's wrong.

Auto-start Apache on boot

From the Terminal

Changing the user and group of Apache

Normally Apache runs as user _www and group _www. However, if you are developing locally you may want to sacrifice security over convenience. After all, the web server only serves local requests (Mac OS X firewall blocks access to Apache by default). Edit the Apache configuration file /etc/apache2/httpd.conf like before

Find these lines

and change them to

where myuser is your username.

If you don't know what your username is, from another Terminal give the command

and Mac OS X will tell reply with your username.

Save and close the file by pressing ⌃x, then Y, then ENTER.

Finally, restart Apache

Configuring PHP

First we need to know which directories PHP 5.3, 5.4, 5.5 and 5.6 is installed in. From the terminal window do

You should see something like

Note down these directory names. You will need to replace them in the instructions below.

Let's create a new web root inside your home directory

The final command will reply with something like

Copy that path. It's the absolute path to your web root and you will need it below.

Edit the Apache configuration file /etc/apache2/httpd.conf like before:

Find the line

It should be the last line. Put a hash sign in front of it

This removes the single PHP version configuration which was added by the PHP installation step.

While we are at it, let's change the web root to the new directory we created before. Find this line

and change it to

where /Users/myuser/Sites is the absolute path to your web root you previously noted down.

Important! Please remember to change all other instances of /Library/WebServer/Documents to /Users/myuser/Sites inside this file, especially the Directory open tag.

Next, find the line

and remove the hash sign in front

Save and close the file by pressing ⌃x, then Y, then ENTER.

Now let's edit the httpd-default.conf Again, due to Mac OS X security model we need to do this from the command line

Apache Mysql Php Install

Append these lines to the file

MacPhp mysql apache for mac os x64

Save and close the file by pressing CTRL-x, then Y, then ENTER.

Now restart Apache

Test PHP

Create a new file named phpinfo.php inside the Sites directory under your home directory with the content

On your browser visit http://localhost/phpinfo.php You should see the PHP information page. If you have got all the instructions right you should see that right below the top line, showing the version of PHP, there is this line

If not, review all the instructions above, you missed a step.

The Virtual Hosts

Our goal is to have every site on our local server run under a different PHP version depending on the domain name we are using. The domain names we will be using are:

  • local.web for PHP 5.4
  • local53.web for PHP 5.3
  • local55.web for PHP 5.5
  • local56.web for PHP 5.6

You need to change your hosts file to have Mac OS X map these fake domains to your local server. The easiest way is using Gas Mask. Add these lines to the hosts file:

We will also be implementing dynamic virtual hosts. This means that when you have a directory ~/Sites/foobar you will be able to access this site both as http://local.web/foobar and http://foobar.local.web The latter is a better way to develop sites locally since most web scripts store image paths relative to the domain root. For this trick to work you’d need to add a few more lines to your hosts file:

Now the site in the directory ~/Sites/foobar will be accessible as http://foobar.local.web (PHP 5.4), http://foobar.local53.web (PHP 5.3), http://foobar.local55.web (PHP 5.5) and http://foobar.local56.web (PHP 5.6). Cool! Let’s make the changes in our server’s configuration to make that happen.

Configure Apache for multiple PHP versions

Edit the /etc/apache2/httpd.conf. As we have already said, we have to use the Terminal

Find the line

and remove the trailing hash sign so that it becomes

Save and close the file by pressing ⌃x, then Y, then ENTER.

Now edit the /etc/apache2/extra/httpd-vhosts.conf file with

and change its contents with:

PHP 5.3 is left as an exercise to the reader.

Please remember to change /Users/myuser/Sites with the path to your web root. You will most likely need to change the paths to each individual PHP version, e.g. php5-5.6.0RC4-20140818-155418 with whatever is the directory name of your PHP 5.6 version.


Save and close the file by pressing ⌃x, then Y, then ENTER.

Now, let's restart Apache one final time

Test the solution

We can now use four different domains to access the same content as different PHP versions. Let’s try it:

http://www.local.web/phpinfo.php reports PHP 5.4

http://www.local53.web/phpinfo.php reports PHP 5.3

Php Mysql Apache For Mac Os X

http://www.local55.web/phpinfo.php reports PHP 5.5

http://www.local56.web/phpinfo.php reports PHP 5.6

All three URLs load the same file /Users/myuser/Sites/phpinfo.php.


At some point you'll probably need to change the PHP configuration. Inside each one of the /usr/local/php5-SOMETHING directories there's the php.d/99-liip-developer.ini file. This is where you are supposed to add your custom configuration variables. Since this file loads last it overrides the configuration in all other files. Also remember that each PHP version has its own INI file. Moreover, since PHP 5.3 loads as an Apache module it requires you to restart Apache before the changes have any effect.

If you are looking for the server access and error log files they can be found at the /var/log/apache2 directory. If you would rather remove your eye from its socket with a rusty fork instead of using the terminal to read the logs, I feel for you and have to propose a solution: just install Pimp My Log. It will make your life decidedly easier.

If you are trying to score extra geek points and make your PHP development process a tad easier you might also be interested in PHP Error, especially its 'I want it outside my project, but running on all dev sites' configuration. Since you're running all PHP versions, except 5.3, as FastCGI you can put the PHP configuration value php_error.autorun = On to enable it or php_error.force_disabled = On to disable it inside your .htaccess file.

Finally, remember that you can always install this custom server alongside MAMP as long as MAMP is set to use its custom ports (8888 for the web server and 8889 for MySQL).

Php Mysql Apache For Mac Os X

Good luck and have fun!