Installing phpMyAdmin on Mac OS X Lion

This article is part of Django Installation on Mac OS X Lion

Mac OS X by default ships with Apache web server which we will use to install (configure) phpMyAdmin to manage MySQL server installed previously on Mac OS X 10.7 (aka Lion). At the end of this step-by-step tutorial, you should be able to access phpMyAdmin by opening http://localhost/phpMyAdmin in your preferred browser.

In this tutorial we will be using Terminal to move files around and edit/create files using command line.

Installing phpMyAdmin

  1. Start Apache if it’s not already running (You can check by running command “ps -ef | grep httpd” in terminal)
    1.  Open System Preferences and Click Sharing

      Start Apache Mac OS X

      Start Apache Mac OS X

    2. Check Web Sharing Checkbox which should start web server (Apache) on your Mac
    3. Open http://localhost in browser and you should see default page (on mine it just says “It Works” in H1 Tag)

      Mac OS X Web sharing Homepage

      Mac OS X Apache Homepage

  2. By default, PHP module is not activated. Uncomment the line ”LoadModule php5_module libexec/apache2/libphp5.so” in file “/private/etc/apache2/httpd.conf” to enable PHP on Mac OS X Apache web server. Default PHP version is PHP 5.3 (PHP 5.3.6 to be precise)
  3. Download phpMyAdmin (Latest version at the time of writing this is 3.4.3.1) from phpMyAdmin Site. Download page has quite a few options in terms of language and compresssion formats, so download the most relevant language pack and compression format you are comfortable with. (I downloaded phpMyAdmin-3.4.3.1-english.zip, please note your version may be different )
  4. Open Terminal and Extract downloaded package to /usr/local/ by running command  “sudo unzip phpMyAdmin-3.4.3.1-english.zip -d /usr/local/
  5. Rename phpMyAdmin-3.4.3.1-english to phpMyAdmin by using command “sudo mv /usr/local/phpMyAdmin-3.4.3.1-english /usr/local/phpMyAdmin” in Terminal
  6. Switch to phpMyAdmin directory using “cd /usr/local/phpMyAdmin” to create phpMyAdmin config file
  7. By default config.inc.php file does not exist but phpMyAdmin ships with sample config which we can use. Copy config.sample.inc.php to config.inc.php using “sudo cp config.sample.inc.php config.inc.php
  8. Edit config.inc.php using your favorite editor (I prefer vi) and change $cfg['Servers'][$i]['host'] = ‘localhost’; to $cfg['Servers'][$i]['host'] = ’127.0.0.1′;
    *Well it sounds stupid because localhost and 127.0.0.1 are same in networking world but phpMyAdmin won’t let you (At least me) log in without this change and keeps throwing error “#2002 Cannot log in to the MySQL server
    **If your MySQL is running on a different host/port, you can change them in this file
    ***You can also use setup wizard offered by phpMyAdmin to configure phpMyAdmin further
    ****You can also add random blowfish secret to config.inc.php to encrypt your session cookies.
  9. Configure Apache to enable /phpMyAdmin
    1. Create phpMyAdmin apache config file with below text in bold in /etc/apach2/other/ directory using your favorite editor  “sudo vi /etc/apache2/other/phpMyAdmin.confAlias /phpMyAdmin /usr/local/phpMyAdmin
      <Directory /usr/local/phpMyAdmin>
          Options Indexes
          Order allow,deny
          Allow from all
      </Directory>
  10. Restart Apache by typing command sudo apachectl restart in terminal
  11. Open http://localhost/phpMyAdmin in your browser and you should see phpMyAdmin Login Page

    Mac OS X phpMyAdmin Login Screen

    Mac OS X phpMyAdmin Login Screen

*Note Default phpMyAdmin does not allow you to login with empty passwords, you can change this behaviour but it is highly recommended to have password for mysql server accounts.

91 thoughts on “Installing phpMyAdmin on Mac OS X Lion

  1. Pingback: Installing Django on Apple Mac OS X 10.7 aka Lion | A Non-Programmer Approach to Django

  2. With Snow Leopard, Apache worked very well. After installing Lion I can no more start the web sharing. It simply uncheck the option, with no error messages. Any idea why?

  3. @Stefano:
    For some reason commenting out the fastcgi-line in your httpd.conf (/etc/apache2/httpd.conf) does the trick. Don’t ask me why.

  4. All seemed fairly clear until In step 2 you say…

    Uncomment the line ”LoadModule php5_module libexec/apache2/libphp5.so” to enable PHP on Mac OS X Apache web server.

    Where is this?

  5. @Justin, sorry I should have been more clear about that. You need to edit file /private/etc/apache2/httpd.conf

    Post updated as well.

  6. Ciao man!
    Thanks for sharing your experiences!

    There are 2 issues in the post:

    1) at point 9 of your tutorial you still have an apach2 syntax error, and then you need a space and a or

    tag to put in evidence the content of the phpMyAdmin.conf file;

    2) you need to put 127.0.0.1 in the conf.inc.php file since you do not (fully) set the login credentials in the MySQL installation. If you set 'local' and 'localhost' login credentials for it then phpMyAdmin will stop complaining!

    Cheers!

  7. Thanks for this, worked for me. BUT: I changed my password after my first login. And I think I did it wrong (missed a checkbox). Now I can’t login. How to fix this?

  8. Is this the same procedure for Lion Server ?

    I cant seem to get it working unless I put it in /library/server/web/data/sites/default

    and then when I do it wont let me log in to it if I allow it access to the config file ??

    Any ideas ??

    Cheers

  9. Problem solver PEBCAC error !!!

    FYI for lion server just rename the unziped phpmyadmin folder to phpMyAdmin and put it in /library/server/web/data/sites/default . Works like a charm :)

  10. Hi, I installed MyQL as you described above, and intall phpmyadmin in default folder like Dave said for lion server. phpymyadmin required a password to login, but during the MySQl installation, no password was set up. I spend the whole night but still can not login. Please help.

  11. 1) Open up a terminal window
    2) At prompt, type: mysql -u root
    3) At mysql prompt type: update mysql.user SET Password=PASSWORD(‘yourpassword’) WHERE User=’root’;
    4) type: flush privileges;
    5) try logging in again.

  12. Hi!
    This works fine generally, but I get a message saying:
    The mcrypt extension is missing. Please check your PHP configuration, when logging in to PhpMyAdmin.

  13. Excellent explanation!

    All works great with Lion (OS X 10.7). And if somebody want to log without password, the only thing that you have to do is to edit the next instruction in the config.inc.php file:
    $cfg['Servers'][$i]['AllowNoPassword'] = true;

  14. Hi. I have two questions. The first being on step 9, do I create /etc/apache2/other/phpMyAdmin.conf and put:

    Alias /phpMyAdmin /usr/local/phpMyAdmin

    Options Indexes
    Order allow,deny
    Allow from all

    in it? Also when I go to the login page it says it was unable to read my config file. The output from the config errors page is:
    Starting to parse config file…
    Parse error: syntax error, unexpected T_DNUMBER in /usr/local/phpMyAdmin/config.inc.php on line 31

    These are the lines around 31:
    /* Server parameters */
    $cfg['Servers'][$i]['host'] = ’127.0.0.1′;
    $cfg['Servers'][$i]['connect_type'] = ‘tcp’;
    $cfg['Servers'][$i]['compress'] = false;

    Do I have a syntax error?

    By the way thanks for the awesome job you are doing at this blog. Just found it and wanted to say thanks

  15. For some reason my quoting before was removed by WordPress. Here this is what I put in my /etc/apache2/other/phpMyAdmin.conf

    Alias /phpMyAdmin /usr/local/phpMyAdmin

    Options Indexes
    Order allow,deny
    Allow from all

  16. I changed the config.inc.php to read ’127.0.0.1′ instead of ‘localhost’ but am still getting the error message #2002 Cannot log in to the MySQL server

  17. Pingback: Can Community Edition be installed on OS X Lion? - SugarCRM Forums

  18. Jason:

    This error could happen ’cause the MySQL Server Instance is stopped. Check the MySQL Server Status and start it.

  19. When downloading the phpMyAdmin file, Lion seems to automatically unzip the file, which makes using the sudo unzip create an error, as there is no variant of a .zip file to be found. Should I just move the phpMyAdmin to /usr/local ? if so, do I need to use the terminal, and again (sorry) what is appropriate syntax?
    Thanks- mark

  20. Sorry, figured it out. By default, Lion unzips it, and moves the zip file to trash. Just drug the zip file out of the trash and moved on.

  21. If you want to get around the auto-unzip feature of downloaded files do as follows:

    Safari->Preferences->General
    Uncheck “Open Safe Files After Downloading”

    Bit off-topic but it was also an annoyance for me too so thought I’d mention it.

  22. Hello,

    I have been trying to get phpMyAdmin woking in OSX 10.7 as per the instructions found her. I keep getting the follow error when I try to type “http//localhost/phpMyAdmin”:

    Not Found
    The requested URL /phpMyAdmin was not found on this server.

    I have gone thru the instructions several time by still dont see where I am going wrong. When I type http://localhost I do get IT WORKS” so I think Apache is running. I have turned on Sharing and mySql in the control panel, created and/or modified the config files, etc. Any help would be appreciated.

    Thanks
    Frankie

  23. I am having an issue with part 9.

    I am not so sure what this command is doing.

    I entered the command:
    sudo bbedit /etc/apache2/other/phpMyAdmin.conf

    copied the following boldface code into the file:
    “sudo vi /etc/apache2/other/phpMyAdmin.conf“Alias /phpMyAdmin /usr/local/phpMyAdmin

    Options Indexes
    Order allow,deny
    Allow from all

    Then I saved it. I did everything else successfully but upon loading http://localhost/phpMyAdmin, it doesn’t work.

    Please let me know what I am doing wrong / what I should do.

    Thanks

  24. I dug into this 127.0.0.1 vs localhost issue and found out that the reason 127.0.0.1 works and localhost doesn’t is becuase msyql is setup to use the network socket instead of the unix socket.

    “MySQL will try to connect to the unix socket if you tell it to connect to “localhost”. If you tell it to connect to 127.0.0.1 you are forcing it to connect to the network socket. So probably you have MySQL configured to only listen to the network socket and not to the file system socket.”

    More info over at http://serverfault.com/questions/295285/mysql-cannot-connect-via-localhost-only-127-0-0-1

  25. As a number of people have mentioned, Step 9 needs some straightening up for those of us no so Terminal savvy yet. Can you simply clarify (show us) what the file itself should look like rather than including the sudo editor command with the funky quotes that seem to be confusing everyone? Or post a sample file?

    I went through a whole install of Apache/PHP/MySQL and then couldn’t get past this phpMyAdmin portion. When I hit the http://localhost/phpMyAdmin I see the directory index list of files rather than a log in page. This scuttled the end game.

  26. Step 9 is a friggin mess.
    The perfect way to blow the whole tutorial and leave people hanging.
    All it would take is a little bit of explanation as to what is
    actually happening.

  27. For people confused on step 9 the correct way is the following:

    run this in Terminal:
    sudo vi /etc/apache2/other/phpMyAdmin.conf

    add this info inside of file:
    Alias /phpMyAdmin /usr/local/phpMyAdmin

        Options Indexes
        Order allow,deny
        Allow from all

  28. Thanks for this tutorial, as well as the MYSQL install instructions – both were real simple and helpful.

  29. In Step 9 for some, put the file “phpMyAdmin.conf” in /etc/apache2/sites/phpMyAdmin.conf and not in /etc/apache2/other.

    Thank you for this tuto.

  30. I’m having the same problem as @Frankie
    I ran through all these steps and was really excited, until the very last step. What happens if your phpMyAdmin screen doesn’t come up?

  31. OK, if you’re having trouble on the last step, here’s what worked for me.
    First, I’m new to terminal, and all this vim crap can suck it.
    I navigated in Finder to /etc/apache2/other/
    Found the file phpMyAdmin.conf (it had some weird extension to it, so i renamed it to .conf)
    Opened it up in SublimeText 2 and added:

    Alias /phpMyAdmin /usr/local/phpMyAdmin

    Options Indexes
    Order allow,deny
    Allow from all

    then saved and ran the terminal command: sudo apachectl restart

    After that, i could see localhost/phpMyAdmin

    @author: the line spacing on that last bit is confusing. when I copy and pasted it into terminal, vim opened and the first line was: rectory /usr/local/phpMyAdmin>
    Thats where the confusion began, and this tutorial lost its luster.

  32. Hey im using mac os x lion to setup phpmyadmin so it can manage mysql..m told to create a folder call config, next edit the default config.sample.inc.php and remove the .php then go to the setup/script utility enter the mysql user name and password click add server and my empty config folder would now be ready to connect….what a crock? anyone know exactly how to resolve getting phpmyadmin to connect and manage msql data base

  33. I had all of this working a while ago in Leopard, but for some reason when I go to http://localhost/phpMyAdmin, it takes me to a page that has a header that says ‘index of /phpMyAdmin’. It has a link to the parent directory and the port file. Shouldn’t this page take me to the login page. How can I fix this?

  34. Pingback: Setting up Django with MySql – with and without MAMP | Nistha's Blog

  35. Got everything running thanks to this tutorial!

    I also had problems on step 9. For me I needed to put:

    Alias /phpMyAdmin /usr/local/phpMyAdmin

    Options Indexes
    Order allow,deny
    Allow from all

    Without the “directory” part apache was giving me a syntax error on the “Allow from all” line.

  36. I have OS X 10.7.3. When I create the file as indicated above in the /etc/apache2/other directory, Apache stops working, and so System Preferences refuses to allow web sharing. (I do not have a /etc/apache2/sites folder.) phpMyAdmin also does not appear. Then when I remove the file, Apache starts to function again, and web sharing is again possible, but for phpMyAdmin I am back to square 1.

  37. You’ve just made my day with that “switch localhost to 127.0.0.1″ thing. Thanks a lot.

  38. I’m still confused! I set up all the files correctly, I think. But when I went to http://localhost/phpMyAdmin/ there was an error:

    MySQL said:
    #2002 – the server is not responding (or the local MySQL server’s socket is not correctly configured)

    When I checked the Sharing panel, Web Sharing was turned off, and I could not turn it back on.

    Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>