Version 1 (modified by jaguarcy+macports@…, 14 years ago) (diff)


<- Back to the HOWTO section

Getting Apache, MySQL, and PHP Running under MacPorts

  • Audience: Users who don't like the default OS X installation
  • Requires: MacPorts


Some networks and proxies prevent or break the use of rsync or svn via http. For people on these networks, getting an updated port tree can be difficult. The rsync server makes a tarball daily and stores it on

These instructions are written for the following versions:

  • Apache 2.2.*
  • MySQL 5.0.*
  • PHP 5.2.*


Step 1: Turn off Apple's "Personal Web Sharing"

If you haven't already done so, make sure you turn off Apple's "Personal Web Sharing" in the System Preferences so that the default Apache server is not running. While you can set things up so that both servers run on different ports (e.g., port 80 and port 8080), it's not worth the hassle of maintaining two web server daemons. Just use the latest Apache from MacPorts and be done with it.

Step 2: Install Apache

sudo port install apache2

Create an initial httpd.conf configuration file:

cd /opt/local/apache2/conf
sudo cp httpd.conf.sample httpd.conf

Activate your Apache installation so that it autostarts when you boot your machine:

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

Start Apache (the previous step only activates the autostart; it didn't start it for the current boot cycle):

sudo /opt/local/apache2/bin/apachectl -k start

Point your browser to http://localhost/ and verify that Apache is running. (For Apache 2.2.8, you should see a giant "It works!" displayed.)

Reboot your machine, point your browser again to http://localhost/, and verify that Apache has started and is running.

You may want to enable local access to the "Apache HTTP Server Manual" and to User web pages. In /opt/local/apache2/conf/httpd.conf, uncomment the lines:

Include conf/extra/httpd-userdir.conf


Include conf/extra/httpd-manual.conf

In /opt/local/apache2/conf/extra/httpd-userdir.conf, change the line

UserDir public_html


UserDir Sites

(this may already be done for you by the MacPorts installation) and add the following lines to the end of the file:

# Include user configurations
Include /private/etc/httpd/users/*.conf

Restart Apache (sudo /opt/local/apache2/bin/apachectl -k restart) and verify that everything's running. You should now be able to go to http://localhost/manual/ to access the manual, and you should be able to access your personal user web site at http://localhost/~username/, where "username" is your login id.

<- Back to the HOWTO section