How to install apache, php, mysql with macport in Mac OS X

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:-

    sudo port selfupdate

  • Once macport selfupdate completed, you enter the command below at the terminal:-

    sudo port install gawk
    sudo port install nawk

  • Once gawk and nawk is installed, you can start install apache, php and mysql using the following command:-

    sudo 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 ***

  • Once it completed, 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. ***
  • Once done, you can configure apache and mysql to start automatically by enter the command below:-

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

  • To start your apache2 and mysql5 manually, type the command below:-

    sudo port /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start
    sudo port /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:-
/opt/local/apache2/htdocs/index.php

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:-

alias port=’/opt/local/bin/port’

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 port /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start

Credit: SamuraiCoder, 2 Tablespoon

Share and Enjoy:
  • Reddit
  • BlinkList
  • del.icio.us
  • Digg
  • Fark
  • IndianPad
  • StumbleUpon
  • YahooMyWeb
Posted at July 14th, 2008 by sogua

If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)

Related Post

One Response to “How to install apache, php, mysql with macport in Mac OS X”

  1. AenTan Says:

    I use MAMP. This looks more complicated. :P

Leave a Reply