Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

After using MAMP for ages, I found out I could actually use Snow Leopard's built-in Apache server. Now that I've upgraded to Lion, I have no idea how to do this anymore.

Do you know how to turn my Mac OS X Lion into a web server, so that I can easily run the latest version of PHP and MySQL in it? Also, how do I set the "localhost" aliases? I remember it was a httpd.conf file — something that I don't seem to find anymore on Lion.

share|improve this question
    
Just a little help for GUI editor lovers: For using TextMate as default editor from Terminal you can call it as mate. sudo mate /etc/apache2/httpd.conf It is a good idea to register it in ~/.bash_profile for that purpose before the 1st use: export EDITOR='mate -w' And create a symlink in your ~/bin folder: ln -s /Applications/TextMate.app/Contents/Resources/mate ~/bin/mate *The above info applies to Mac OS X users –  ommunist Nov 17 '12 at 21:24
add comment

3 Answers

up vote 31 down vote accepted

You first need to enable Apache in the Sharing prefpane. Check "Web sharing" and your web server is running.

Note that since Mountain Lion, Web Sharing was removed from the Sharing preference pane, but Apache is still included. Check this answer for controlling Apache in Mountain Lion.

Enable Web Sharing

To activate PHP you'll need to edit /etc/apache2/httpd.conf in Terminal.app. This requires root credentials. nano is a very accessible command-line editor if you are uncomfortable with vim.

sudo nano /etc/apache2/httpd.conf

Find the line (you can press ctrl + W to start searching in nano):

#LoadModule php5_module libexec/apache2/libphp5.so

and uncomment it. Next find the line

#Include /private/etc/apache2/extra/httpd-vhosts.conf

and uncomment that as well to enable virtual hosts support.

Save the file and exit nano by pressing ctrl + X, then confirming the changes by pressing Y(es), then enter.

You can now edit your virtual hosts in the file /etc/apache2/extra/httpd-vhosts.conf

sudo nano /etc/apache2/extra/httpd-vhosts.conf

Important to note is that the first defined host will be the default host for unqualified host names. For resolving additional hostnames apart from localhost I recommend hardcoding them in /etc/hosts.

To install MySQL, download the installer from the MySQL website (64bit installer should be ok). Follow the instructions to install it.

Finally, to configure PHP for MySQL, copy the default php.ini:

sudo cp /etc/php.ini.default /etc/php.ini

Now you can edit /etc/php.ini (again root access required) and replace any reference to /var/mysql/mysql.sock with /tmp/mysql.sock (the default location of the MySQL socket after running the installer). There probably are about 3 references to that path.

Finally, restart Apache for the new configuration to take effect:

sudo apachectl restart

Alternatively you can restart Apache by toggling it off and on again in the Sharing prefpane.

Done.

share|improve this answer
1  
i would advise you to never suggest any sort of terminal text editor, just use textedit.app in the command instead of nano, because terminal text editors are just barbaric. –  XAleXOwnZX Mar 10 '12 at 20:28
11  
Nano is quite user-friendly, IMO, and it's really annoying to try to edit something with root privileges from the GUI. –  NReilingh Mar 10 '12 at 21:22
12  
@XAleXOwnZX: I'm sorry but that's just bad advice. If anything, you'll find it next to impossible to edit these files in TextEdit.app because a lack of privileges, as NReilingh also pointed out. Also, it is not unreasonable to expect some aquaintance with the console from any (aspiring) web developer. –  Gerry Mar 11 '12 at 21:08
    
generally works if u sudo it –  XAleXOwnZX Mar 12 '12 at 13:47
8  
@XAleXOwnZX: With all due respect, that is arguably the worst advice I have ever seen on a Stack Exchange property. I agree that a GUI text editor is probably a better approach for people who are not programmers or who don't have much unix experience, however, TextEdit is the wrong application to advise using simply because it defaults to a variable-width font and rich text. This can cause all sorts of problems (beyond the simple usability nightmare of writing code in variable-width) that will be extremely difficult or impossible for this person to debug. –  lightyrs May 13 '12 at 0:35
show 5 more comments

Just for the record, an alternative to MAMP is WebStart that makes it easy to manage a professional Apache 2 web sever on Mac OS X 10.7 Lion.

share|improve this answer
add comment

You can find a good tutorial here to enable also phpmyadmin and such without using mamp

share|improve this answer
add comment

protected by Community Dec 7 '12 at 3:19

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.