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 lastest 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.

Pardon me for my rusty english. Let me know if my question isn't clear enough or duplicate. I'll improve it right away.

link|improve this question

36% accept rate
feedback

1 Answer

up vote 20 down vote accepted

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

enter image description here

To activate PHP you'll need to edit /etc/apache2/httpd.conf in Terminal.app. This require root access. Nano is a very accessible command-line editor.

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).

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

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

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 php.ini:

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

Now edit 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 location.

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

sudo apachectl restart

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

Done.

link|improve this answer
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 at 20:28
3  
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 at 21:22
2  
@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 at 21:08
generally works if u sudo it – XAleXOwnZX Mar 12 at 13:47
Did you try that out @XAleXOwnZX? – Gerry Mar 12 at 14:40
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

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