Professional Documents
Culture Documents
8 Mountain Lion
18/02/13 15:56
Install and configure Apache, MySQL, PHP and phpMyAdmin on OSX 10.8 Mountain Lion
Get your Local Web Development Server Purring on all Fours
With the new cat out of the bag, getting the AMP stack running is a little different on OS X Mountain Lion 10.8 than is its predecessor OS X 10.7 Lion, here is the lowdown on getting Apache, MySQL, PHP and phpMyAdmin running on the new Apple operating system. (OSX 10.7 AMP guide is here). If you have upgraded from a previous OS X your hosting environment will be whacked and you need to fix certain configuration files to get that environment back, in particular enabling PHP, and if you used the username/Sites document root folder in your home account you will need to add back in a user configuration file.
Apache/WebSharing
The first difference in the new OS X 10.8 is the dropping of the GUI option in System Preferences > Sharing to turn on Web Sharing, it may be gone but the webserver Apache is definitely under the hood of the OS and ready to go.
Apache is pre-installed in the OS and needs to be enabled via the command line - this needs to be done in Terminal which is found at /Applications/Utilities/Terminal to start it
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion Pgina 1 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
sudo%apachectl%start
to stop it
sudo%apachectl%stop
to restart it
sudo%apachectl%restart
After starting Apache - test to see if the webserver is working in the browser - http://localhost - you should see the "It Works!" text. If you want a GUI point and click web sharing toggle switch in System Preferences, this is one from clickontyler. Some people have had issues with this sys pref so use at your own decision.
Document Root
Document root is the location where the files are shared from the file system and is similar to the traditional names of 'public_html' and 'htdocs', OSX has historically had 2 web roots one at a system level and one at a user level - you can set both up or just run with one, the user level one allows multiple acounts to have their own web root whilst the system one is global for all users. It seems there is less effort from Apple in continuing with the user level one but it still can be set up with a couple of extra tweaks.
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 2 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Interestingly the user document root level is missing the '~/Sites' folder in the User account on a clean installation, you need to make a "Sites" folder at the root level of your account and then it will work. Upgrading from a previous OS X version preserves the Sites folder but removes the ability to web serve from it - this is where you need to add in a 'username.conf' file.
If you dont (very likely), then create one named by the short username of the account with the suffix .conf, it's location and permissions/ownership is best tackled by using the Terminal, the text editor 'nano' would be the best to deal with this. Launch Terminal, (Applications/Utilities), and follow the commands below, first one gets you to the right spot, 2nd one cracks open the text editor on the command line (swap 'username' with your account's shortname, if you don't know your account shortname type 'whoami' the Terminal prompt):
cd%/etc/apache2/users
sudo%nano%username.conf
Then add the content below swapping in your 'username' in the code below:
<Directory%"/Users/username/Sites/"> Options%Indexes%MultiViews AllowOverride%All Order%allow,deny Allow%from%all </Directory>
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
sudo%chmod%644%username.conf
PHP
PHP 5.3.13 is loaded in OSX 10.8 Mountain Lion and needs to be turned on by uncommenting a line in the httpd.conf file.
sudo%nano%/etc/apache2/httpd.conf
Use "control" + "w" to search and search for 'php' this will land you on the right line then uncomment the line (remove the #):
LoadModule%php5_module%libexec/apache2/libphp5.so
Write out and Save using the nano short cut keys at the bottom 'control o' and 'control x' Re-load apache to kick in
sudo%apachectl%restart
To see and test PHP, create a file name it "phpinfo.php" and file it in your document root with the contents below, then view it in a browser.
%<?php%phpinfo();%?>
MySQL
MySQL is again a missing component in OS X 10.8 and needs to be dowloaded from the MySQL site use the Mac OS X ver. 10.7 (x86, 64-bit), DMG Archive version (works fine on 10.8). When downloading you dont have to sign up, look for No thanks, just take me to the downloads! - go straight to the download mirrors and download the software from a mirror which is closest to you. Once downloaded install the 3 components. You may need to adjust the Security and Privacy System Pref to allow installs of 3rd party apps because of the new security feature of Mountain Lion known as the 'Gatekeeper', which keeps unscrupulous installer packages at bay. To get around this without changing the global preferences (better!) right click or command click the .pkg installer to bring up the contextual menu and select open, then you get the warning - then click Open.
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 4 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Install all 3... mysql5.5.xxx.pkg MySQLstartupitem.pkg MySQLPrefPane The first is the MySQL software, the 2nd item allows MySQL to start when the Mac is booted and the third is a System Preference that allows start/stop operation and a preference to enable it to start on boot. You can start the MySQL server from the System Preferences or via the command line
sudo%/usr/local/mysql/support.files/mysql.server%start%
To find the MySQL version from the terminal, type at the prompt:
/usr/local/mysql/bin/mysql%.v
This also puts you in to an interactive dialogue with mySQL, type \q to exit. After installation, in order to use mysql commands without typing the full path to the commands you need to add the mysql directory to your shell path, (optional step) this is done in your .bash_profile file in your home directory, if you dont have that file just create it using vi or nano:
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 5 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
cd%;%nano%.bash_profile
export%PATH="/usr/local/mysql/bin:$PATH"
The first command brings you to your home directory and opens the .bash_profile file or creates a new one if it doesnt exist, then add in the line above which adds the mysql binary path to commands that you can run. Exit the file with type control + x and when prompted save the change by typing y. Last thing to do here is to reload the shell for the above to work straight away.
source%~/.bash_profile
mysql%.v
You will get the version number again, just type \q to exit.
Note that this is not the same as the root or admin password of OSX - this is a unique password to the mysql root user, use one and remember/jot down somewhere what it is.
/usr/local/mysql/bin/mysqladmin%.u%root%password%'yourpasswordhere'
phpMyAdmin
phpMyAdmin is installed pretty much the same way as before. Fix the 2002 socket error first sudo%mkdir%/var/mysql
sudo%ln%.s%/tmp/mysql.sock%/var/mysql/mysql.sock
Download phpMyAdmin, the english.tar.gz package, uncompress and move the folder with its contents into the document root level renaming folder to 'phpmyadmin'. Make the config folder
mkdir%~/Sites/phpmyadmin/config
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 6 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Then the only other configurations are the local mysql user and the password in the Authentication tab. Add in the username root (maybe already populated, add in the password that you set up earlier for the MySQL root user set up, click on save and you are returned to the previous screen.
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 7 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Make sure you click on save, then a config.inc.php is now in the /config directory, move this file to the root level of /phpmyadmin and then remove the now empty /config directory. Now going to http://localhost/~username/phpmyadmin/ will now allow you to interact with your MySQL databases. To upgrade phpmyadmin just download the latest version and copy the older 'config.inc.php' from the existing directory into the new folder and replace - backup the older one just in case. If you need virtual hosts configured I have added a separate guide on how to set these up in the Apache config files. That's it! You now have the native AMP stack running ontop of the tamed Mountain Lion.
Tags: OSX Web Host
apache
mysql
php
182
Like
128
382
Tweet RECOMMENDED CONTENT What's this? Exxon
239 comments
42
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 8 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Leave a message...
Discussion
Community
Share
Ken
7 months ago
Hi, I get the following errors on http://localhost/~username: Forbidden You don't have permission to access /~username/ on this server. I try chmod 0777 for /Users/username/Sites ... but ...Any ideas for this problem ... Thanks so much
20 1
Reply
Share
marc
>
Hey I made it with sudo chgrp -R _www /users/username/sites sudo chmod -R 774 /users/username/sites but i really don't know if its the best way.
4
Reply
Share
buddhi de silva
>
One possible reason is that you might have enabled URL Rewriting for your app/site (uses .htaccess file). Try adding
Options FollowSymLinks
Reply
Share
Jarek
1
>
Steven Vachon
0
>
I can't get this to work either. I've tried all the solutions mentioned.
Reply
monkey
0
>
http://www.coolestguyplanettec...
>
Christopher Mori
Neil, Thanks very much for this guide; it is extremely helpful. I am having trouble getting my web server running from my user directory (no issues from the main localhost web server). I had successfully used my ~/Sites directory prior to Mountain Lion (and Lion for that matter), and have followed the instructions listed above, but still get the "403 Forbidden You don't have permission to access /~[myusername]/ on this server." message. I added the [myusername].conf file to /etc/apache2/users/, and added the content you recommended. The file's permissions are -rwr--r--. When that didn't work, I modified the options line as follows: Options Indexes MultiViews FollowSymLinks based on the recommendation from buddhi. No luck. (As an aside, my Users directory is on a different drive than my system & applications, but there is a symbolic link in place.)
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 9 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
My ~/Sites directory has drwxr-xr-x@ permissions (the xattr is com.apple.FinderInfo). The index.html file has the following ownership & permissions: -rw-r--r-- 1 [myusername] staff 6186 Nov 9 2002 index.html I am not sure where to turn next; any help would be appreciated. I am sorry for the wall of text, but I am a relative novice, and wanted to err on the side of too much info. Thanks again. EDIT: Got it working. I needed to edit my /private/etc/apache2/extra/httpd-userdir.conf file to add a directory entry for my specific Sites path. The generic one wasn't working (I think) due to the symbolic links mentioned above. Thanks again for the great instructions.
1
>
Reply
Share
Henrry
Try chmod 701 for /Users/username/ All directories in the path (/ /Users/ /Users/myusername/ /Users/myusername/Sites/) need to have execute permission
1
Reply
Share
SanchonX
>
I had the same problem, turned out it's because my user directory name had capital letters in it, but inside the username.conf file I typed the folder name as all lowercase. So for example, if your folder in Users is JoeSmith, make sure you've got /Users/JoeSmith/Sites (and not /Users/joesmith/Sites) as the first line.
1 1
Reply
Share
>
I had the same problem because I made a mistake, username is supposed to be replaced by your User name in my case alejandro, and I did it like that except in the file name, so instead of alejandro.conf i named it username.conf, once I realized that and fixed it, it worked, hope this helps a bit
0
Reply
Share
Bob Jonson
0
>
You do not need the first 0, you should do chmod 777 /Users/username/Sites
Reply
Camille
>
Hi ! I had the same, the 755 in the article is wrong, but in the example it is good : -rw-r--r-- 1 root wheel 298 Jun 28 16:47 username.confso you should use : sudo chmod 644 username.conf and ... for the naive eyes reading these solutions, chmod 777 is more a source of problem than a kind of rapid solution.
1
Reply
Share
>
Reply
Share
Michael Otton
7 months ago
Thanks for this great guide. Issue I'm getting is phpMyAdmin - Error in a big red bar. Can anyone help?
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion Pgina 10 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Reply
Share
Nenad Novakovic
5 months ago
I have enabled php and created sites and user config. However I have some problems. I am on Mountain Lion 10.8.2 and I dont know if this is just me or its latest OS problem. localhost works fine localhost/~dvLden works fine as well but if I open one of the projects like localhost/~dvLden/project1 either I recieve an error that I dont have permission to that folder or on some projects, site loads up, but many scripts and images are broken (cannot be loaded) and message is path is incorrect. Any clues what is the problem ? Cause paths are correct.
4
Reply
Share
>
Same probleme here.. if i install the slim framework in the localhost/~username directory i get a htaccess error. if i copy the framework in the localhost directory /Library/WebServer/Documents/everthing works fine.. banging my had since days
0
Reply
Share
Jeremy Armes
3
Reply
Wayne Smerdon
2 months ago
Hi, I'm good until I get to the "mkdir ~/Sites/phpmyadmin/config" line under phpMyAdmin where I get a "No such file or directory" error. I think it is related to not creating a Sites directory under the User Level Root, but why would I be creating a directory there if everything else is installed under the System Level Root? Just a little confused as to where this is being setup. If someone can shed some light on this before I proceed that would be great. Okay, I tried to create the User Level Sites directory and move on but its not working out. I created the Sites directory under my user folder and created the conf file per the instructions but viewing the localhost/~username location renders an "The requested URL /~username/ was not found on this server." error. So, I need a bit of guidance.
2
Reply
Share
recklesscoder
2
Reply
Clayton
7 months ago
Although I found your previous posts regarding Lion quite helpful, I find this one not so helpful. I am using mountain loin and mountain lion server, which allows me to turn on web services, start php, and host multiple sites that are not tied to particular users. How does one install and access phpmyadmin without creating user sites for which I have no use? I have phpmyadmin installed at /Library/Server/Web/Data/Sites/phpmyadmin. How do I access that? localhost/~???????
2
Reply
Share
chris thacker
1
>
by default it needs to go in the path you've listed but inside the .../Default/ directory
Reply
Rizky Syazuli
7 months ago
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 11 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
thx for the tips man.. i'm surprised Apple didn't notify users of this. gave me quite the scare there for a while. it's always like this every upgrade. btw, some other command line tool is also disabled. Git for example. but it's easy to fix, just like MySQL, you simply need to put the path to Git in your .bash_profile or .profile
3 1
Reply
Share
dewe
2
Adam Johnson
1
Superb guide. A lot more straightforward than it appears at first glance and it doesn't take too long to get through.
Reply
Andres
1
Lauri Ranta
7 months ago
Wouldn't you also have to enable the launchd agent with `launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist`? Or is apache started automatically after restarting the OS if you just start it once with `sudo apachectl start`?
0 1
Reply
Share
>
Reply
Cucurucho Cucaracha
>
Sorry, not in my case (MBP13 9,1 & MBP15 8,2 on 10.8 & Mini 1,1 on 10.6.8 & Lapzilla2,1 on 10.7.4). You need to use the LaunchDaemons approach or something of the Unix sort if you want the Apache to survive reboots...
0
Reply
Share
Marijn Depraetere
7 months ago
What a perfect tutorial! I can't believe I've almost spent money on things like MAMP Pro for a simple setup like this. The only hickup I've got was when installing the mysql-server. As I already had one going it gave me the message 'ERROR! The server quit without updating PID file' in terminal when trying to start it. After googeling arround and trying some complicated stuff, i've just went to system preferences, went to the mysql-dialog, unchecked the "Automaticlly start MySQL Server on startup" and rebooted. Then, the old MySQL install wasn't booted, so the new one could start as promissed. Thank you for this simple cut-and-paste install guide.
0 1
Reply
Share
Julian Symes
0
Reply
Descarreaux
5 days ago
Good morning It is a great tutorial. I am a total newbie on terminal and , so far, it works perfectly. I am to download MySQL and, since I don't know the date of the tutorial, I was wondering if I should use the last iteration Mac OS X ver. 10.7 (x86, 64-bit), or as the tutorial recommends the Mac OS X ver. 10.6 (x86, 64-bit). Usually, I am trying to use the last version of a software. Maybe it is a bad habit.
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion Pgina 12 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
Usually, I am trying to use the last version of a software. Maybe it is a bad habit. Thank-you
0
Reply
Share
>
I will update the tutorial - but yes use the 10.7 version
Reply
abw
8 days ago
Thank you so much--this was a life-saver. As a note, I had to uninstall my previous version of mySQL before things would work right. Good instructions to do that here: http://akrabat.com/computing/u...
0
Reply
Share
Harry Adu
0
AWESOME!!
nico
0
tommy
12 days ago
I was working fine and now with the new update accessing the Mysql is different it looks like. Its a permissions thing I think. I get an error of: #1045 - Access denied for user 'username'@'localhost' (using password: YES) Not sure where to change this?
0
Reply
Share
Gopal
16 days ago
Reply
Share
>
Reply
Reply
Ismail Almahdi
0
thank you. every useful information for a new mac user like me...
Reply
Gilbert
a month ago
Hi Coolest Guy, Your tuto is just great and was very helpful for me with ML (10.8.2). But I regret to say that with phpMyAdmin 3.5.5, this step has to be omitted : "Make sure you click on save, then a config.inc.php is now in the /config directory, move this file to the root level of /phpmyadmin and then remove the now empty /config directory."
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion Pgina 13 de 15
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
If one doesn't skip this, it is impossible to go further (login and create any database) ... HTH, G.
0
Reply
Share
a month ago
Hi, thanks for the great tutorial. Everything worked fine until I try to go to /localhost/~username/phpmyadmin/setup which instead of beginning the setup of phpmyadmin display a mere list of the files inside the folder. Any thought on how to fix this? Andrea
0
Reply
Share
Dawid Rogaczewski
a month ago
Thank you!!!!
0
Reply
Share
Krisztina K. Weiss
0
Reply
actionscripted
a month ago
The phpMyAdmin link "phpMyAdmin is installed pretty much the same way as before" points to a dead domain (http://www.coolestguyplanet.ne... and should, it seems, point instead to http://www.coolestguyplanettec...
0
Reply
Share
>
Reply
Anders
a month ago
Everything Worked except I am using wordpress and I get a error when uploading images Unable to create directory wpcontent/uploads/2013/01. Is its parent directory writable by the server?
0
Reply
Share
>
do the Post Mortem stuff at the bottom of this post to fix those things: http://www.coolestguyplanettec...
0
Reply
Share
sfdafia
0
thanks for the guide man! i'm familiar with all of it but too lazy to figure it out myself :)
PaulX
0
Spot on - I followed your tutorial and with now I have it all running with no problems at all. Cheers!
r Comment feed
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Install and configure Apache, MySQL, PHP on OSX 10.8 Mountain Lion
18/02/13 15:56
r Comment feed
http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion
Pgina 15 de 15