The easiest way to install apache, php and mysql in Mac is thru mac port. You can also install apache, php and mysql by compiling each of the service but it’s too time consuming. If you just wan to install apache, php and mysql for development use, Mac Port install is good enough.
Follow the steps below to install apache, php and mysql in Mac OS X:-
- Download and install Mac Port.
They have good documentation, just refer to the documentation if you have problem.
- Once Mac Port is running, ensure you have the administrator right because all the steps below need administrator right.
- start your “Terminal” and type:-
1sudo port selfupdate
- Once macport selfupdate completed, you enter the command below at the terminal:-
12sudo port install gawksudo port install nawk
- Once gawk and nawk is installed, you can start install apache, php and mysql using the following command:-
1<del datetime="2010-02-08T08:26:40+00:00">sudo port install php5 +apache2 +mysql5 +server</del>
1sudo port install php5 +apache2 +mysql5-server
** This process take quite some time, go take a walk and come back after 30 min ***
*** you must put the +server at the back, else you wont be able to configure it to auto start at boot up ***
- Now you need to stop the local apache process.
- Go to System Preference -> Sharing -> uncheck the Personal Web sharing.
*** You must disable the Personal Web Sharing to avoid any conflict between your apache2 and the default apache. ***
- Now use the command below to setup the mysql db.
1sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
Once done, change your root password1/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
- Next, you can configure apache and mysql to start automatically by enter the command below:-
12sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plistsudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
- Now you need to configure apache to load php file, open /opt/local/apache2/conf/httpd.conf and add this 2 line:-
12LoadModule php5_module modules/libphp5.soAddType application/x-httpd-php .php
Once saved, you may restart your apache.
* Thanks to Yolabingo for your comment *
- To start your apache2 and mysql5 manually, type the command below:-
12sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper startsudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start
- Done, you just install apache2, php5 and mysql5 with macport in Mac OS X
To test if your apache is running, create a file name index.php with content:-
<?php phpinfo(); ?>
and save it at:-
Then, Point your browser to http://localhost, and you should see your phpinfo page.
FAQ for How to install Apache, PHP and MySQL with Macport in Mac OS X
Q. Where is port located?
Answer: instead of using “port” you can use “/opt/local/bin/port”. Or you may create an alias for it by using this command:-
Q. I’ve done everything but when my browser point to http://localhost it show “Page Not Found”.
Answer: Please make sure you have disable your Mac default apache. By default, Mac OS X already installed with apache. You have to make sure you have disable the apache at System Preference -> Sharing -> Personal Web Sharing.
Q. Where is my apache located?
Answer: If you install your apache with MacPort, your all apache files will be located at /opt/local/apache2. Or may be i should said, all MacPort installed program will be store in /opt folder.
Q. Where is my apache configuration file (httpd.conf)?
Answer: Your apache configuration file (httpd.conf) located at /opt/local/apache2/conf/httpd.conf
Q. How to restart my apache?
Answer: You can restart your apache by using this command:-
sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start