Configuring Apache2 and PHP on Mac OS X for Development

April 23, 2007 § 4 Comments

This article would serve as public cheat sheet on how to configure everything from scratch. Again…

  1. Grab the latest Apache 2.0 / 2.2 as well as PHP5
  2. Unzip them with this command: tar -xzf [your_file].tar
  3. Go to the created httpd directory (for apache) or php directory.
  4. Run: sudo ./configure. This is the crucial part. It is better to set installation path here instead of fiddling around later.

Sample .configure for PHP5:

$prompt: ./configure –with-curl=/usr –with-mysql=/usr/local/mysql –with-apxs2=/usr/local/apache2/bin/apxs

As you can see from –with-apxs2 flag, I installed apache2 on default location. It’s easier to find help and online documentation if you keep most installation on default location, IMHO.

The biggest problem with installing Apache is the httpd.conf monkey work. Below are things you might want to set:

  • Listen 80 (and/or other port number. This is needed for VirtualHost setup)
  • DocumentIndex index.php index.htm (add more if you need them, e.g. index.rhtml)
  • DocumentRoot /Users/{username}/Sites/{your_project} (This path is accessible by default)
  • <Directory /Users/{username}/Sites/{your_project}> </Directory>
  • AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
  • <VirtualHost *:{your port number}> {This tag can handle almost all Apache’s directives} </VirtualHost>

Mac OS X has Apache1.3 by default. That can be seen as both blessing and curse :P. If you would like to run Apache2 this is what you might do:

  • Stop Personal Web Sharing via System Preferences…
  • type: sudo /usr/local/apache2/bin apachectl start

AGAIN and AGAIN… If that aggravates you then this is what you could do:

  • cd /usr/sbin
  • mv apachectl apachectl1.3 {–> This rename default apache1.3/apachectl command}
  • ln -s /usr/local/apache2/bin/apachectl apachectl {–> This creates symlink for Apache2/apachectl command}

Quick Note: Symlink is something like Alias or Shortcut on the GUI realm.

There you have it. Hope the list is handy for you.

Advertisements

§ 4 Responses to Configuring Apache2 and PHP on Mac OS X for Development

  • […] ← I got a Mac! Configuring Apache2 and PHP on Mac OS X for Development […]

  • […] PHPmac (very helpful!) 2. semanticpool 3. a random blog (like mine) 4. Max OSX Hints 5. laughingmeme (more […]

  • Gustavo says:

    Configuring Apache2 and PHP on Mac OS X for Development

    I followed your instructions to configure Apache2 to start manually and, better, automatically. Something is preventing it to work. Specifics:

    1) my path for Apache2 is /opt/local/apache2/bin
    2) I renamed /usr/sbin/apachectl to apachectl1.3
    —2.1) somehow, right after this change, the Personal Web Sharing option is not longer clickable…so I do the stop and start manually from the /opt/… directory
    3) I created the ln -s pointing to /opt/local/apache2/bin
    4) I copied the httpd.conf from the apache2 to the /etc/httpd directory. Renamed the old one .1.3

    When I test the configuration from Firefox…

    …with the http://localhost I get the ” Index of” and files from the directory /opt/local/apache2/htdocs !!! good??? well….

    …with the http://127.0.0.1 I get the Apache 1.3 main page !

  • Michael Stelly says:

    New to Mac, PHP, and Zend Framework all at the same time. What a fun learning curve that is — not.

    Issues:

    — sudo ./configure does not work
    — Apache comes installed on OS X. I can access the localhost from a browser. I installed Zend Server CE and it’s supposed to install mysql, but I can’t find it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Configuring Apache2 and PHP on Mac OS X for Development at RAPD.

meta

%d bloggers like this: