The Lion (Server), The Witch (MySQL) and The Wardrobe (WordPress)

featured-image-size

It’s been vastly covered by everyone, Lion Server doesn’t come with MySQL. It was replaced by PostgreSQL. So what do all of the WordPress users out there do? Well, it’s still possible to get MySQL installed on to your 10.7 Server – here’s how…

Lets start by downloading the latest 64-bit .dmg from the MySQL site. At the time of writing this, the latest version was 5.5.16 for 10.6 (there is no version for 10.7 at the moment, but don’t worry: this works fine).

Install the MySQL package and follow the onscreen instructions.

To make things easier, we are also going to install the ‘MySQLStartupItem’ package and the ‘MySQL’ preference pane file.

After you have added the preference pane, you can click ‘Start MySQL Server’ and also confirm it’s set to automatically start, if that’s what you desire.

Now you need to choose how you want to manage your MySQL databases. We have covered using phpMyAdmin in the past, but for good measure – this time i’m going to use Sequel Pro (of course if you really want, you can use Terminal). Download and install to your Applications folder, and then link it in your Dock for easy access.

Open up Sequel Pro and fill in the connection details. By default, MySQL is accessible by the user ‘root’ with no password.

Whilst we are in, we can add our database we want to use for WordPress. In the top left, select ‘Choose Database…’ and ‘Add Database’

Give the Database a Name and set the Encoding as UTF-8 Unicode (utf8):

Click Add.

We now need to add a new user to use that Database we just created. In the top right, select the ‘Users’ icon. In the window that opens, click the ‘+’ in the bottom left. Give the user a Username and Password:

With the new user selected on the left, click the ‘Schema Privileges’ tab. Select your newly created database from the left (under ‘Schemas’) and select all of the ‘Available Privileges’ and move them in to the ‘Granted Privileges’ column. Click ‘Apply’

You can now close Sequel Pro.

Open up Server.app and select ‘Web’ from the left. Check ‘Enable PHP web applications’ and click the ‘+’ to add a new site. Name it what you wish and set the ‘Store Site Files In’ to location:

/Library/Server/Web/Data/Sites/Default/

Select ‘Done’ and start the Web Service.

Download the latest version of WordPress and put the contents in to the folder mentioned above.

We now need to set the php.ini file to look in the right place for the MySQL Socket. Select the ‘Go’ menu and ‘Go to Folder…’

Type in:

/etc/

Look for the ‘php.ini’ file and open with your favourite text editor (mine is TextWrangler). Look for the line:

mysql.default_socket

Change it from:

/var/mysql/mysql.sock

to:

/tmp/mysql.sock

Save the file and close TextWrangler. Stop and Start the Web Service in Server.app to be on the safe side.

Now head to your web directory you placed your WordPress files in. Rename the file ‘wp-config-sample.php’ to ‘wp-config.php’ and open it in a text editor. Enter the details of the Database and User you created earlier.

Save the file and open Safari. Browse to:

http://localhost/wp-admin/install.php

And you should be presented with the WordPress setup.

Print Friendly

About the Author

I'm an enthusiastic technology lover and work daily in a mixed AD/OD IT environment. Like most, I strive to work on the Apple platform and tolerate the Windows one. I also have a burning passion for music/bass playing and supporting my football club, Arsenal. I use this blog to write useful articles on cool Mac things, and other technology experiences - my trials and tribulations.

  • cesare65

    Congratulations for the article.
    I followed the instructions step by step, but in the end I can not install wordpress, because it can not connect with the database wordpress.
    What’s wrong?
    I change the variable mysql.default_socket, but this file contains the variable pdo_mysql.default_socket. It ‘also need to change this variable?
    The two variables described above are also included in the file:
    - php.ini.default
    - Php.ini.server-default.
    Should I change the variables in these files?

    Which version of server.app use? I use version 10.7.0 (25).
    I hope for your help.

    • Simon

      Hi Cesare65, No, you shouldn’t need to change any of the other variables. I did this article on Server 10.7.2 (1.2.1). Can you try upgrading and then test again?

      • cesare65

        Thank you. Works perfectly.

        • http://www.mactasia.co.uk Simon

          No problem. Happy to help!

          • Shaun Walker

            I have the same “pdo” line in php.ini on 10.7.3 lion server.

          • http://www.mactasia.co.uk/ Simon

            Hi Shaun, you only need to change the line as mentioned in the article, not the “pdo” line.

  • http://photophrenic.com Daniel Yates

    Thank you SO MUCH

    For once someone has made it simple, clear and to the point – I followed each step and hey presto a seemingly complex issue remedied in no time. Many thanks!

    Daniel

    • Simon

      I’m pleased you found it useful Daniel. Thank you for your feedback!

  • LSmith

    Simon – great post. For reference, I’m using server 10.7.2. I followed your steps and everything seemed to install as expected. The issue I’m having is that Safari keeps telling me that the WordPress URL can’t be found. Is there a setting I’ve missed?

    Larry

    • Simon

      Hi Larry, in Server App, under Hardware and the Network tab, check your computer host name. You could try that in Safari instead of “localhost”. Also, have your got your web root set the same as the guide?

      • LSMITH

        Yep, web root folder did the trick. Unfortunately, now WordPress can’t access my database. I checked all of the files on this guide and no luck. I could access it using Sequel Pro, but not phpMyAdmin. I’m using version 5.5.17 – is there a permissions setting that I’m missing?

        Larry

        • Simon

          Hi Larry, yes, sounds like a permissions error. Try setting up a new database in Sequel Pro, set the access privileges, and try running the WordPress set up again.

  • http://www.ravemor.com T_Hollett

    Hi, first of all – thanks for this! I was able to get a localhost setup of wordpress installed on lion server successfully with this. My issue I am hoping someone can shed light on is how to download/install themes to this localhost setup. I did not yet download an FTP program as I thought it was not needed for a localhost setup. However, when I go to the install a theme on the dashboard, it wants a Hostname, FTP username, and FTP password. Do I need to configure an FTP client for this?

    I should point out I am a complete wordpress neophyte and am probably doing something (or not) that is obvious. I’ve spent hours working on this and wondering if I made the wrong decision to go this route. Ultimately, I was simply wanting to use lion server to develop a wordpress site for my business locally, learn wordpress and then upload the completed site at a later date to an online host. Should I have gone a different route with this?

    Thanks for any help.

    • Simon

      Hi, You are quite right – you don’t need FTP for localhost development. You simply need to drop your theme folder in to the the web directory you installed WordPress. So if you followed the guide exactly, that would be:

      /Library/Server/Web/Data/Sites/Default/

      And then inside that:

      /wp-content/themes/

      Make sure the theme you are installing is unzipped, but in a folder. It should then show up under Appearance > Themes in WP Admin.

      I hope this helps.

      • http://www.ravemor.com T_Hollett

        That was fast Simon! Thanks! I did try that with a free theme, but it was still not showing up. I’ll give it another go while being sure I am using the correct path in Finder. But what about the themes from the theme tab in wordpress? Am I missing an obvious way to download those outside of the dashboard to avoid the credentials dialog? (Sorry to go a bit off-topic here.) Thanks again.

  • http://www.ravemor.com T_Hollett

    Please ignore my last comment and my apologies. Apparently I have been beating my head against the wall so much today that I did indeed miss an obvious step. Problem solved for now. Thanks again.

    • Simon

      Pleased you worked it out! Best of luck with it.

  • Grabauski

    One question before I get started trying this: the person I need to set this up for (for now) needs to use WordPress for two different domains. Is that something that I’ll be able to configure from within WordPress itself, or am I going to need to make separate databases and users, etc., each time somebody wants to use WP on a new domain?

    Thanks,

    Eric

    • Simon

      Hi Eric,

      Do these two domains need to access the same site?

      There’s many questions asked about this over at the WordPress site.

  • http://norestfortheobsessed.com Ton

    HI,

    After trial and error and frustration for two weeks and buckets coffee, I could not get to work Mysql, PhpMyadmin with Lion Server 10.7.2.
    At last I found this site, the first and only? one where you don’t need to use the terminal and not worry about privileges…
    I going to use the info here, and will report my result!!
    Great, Great, Happy to found You SIMON.!!

    • Simon

      Pleased to hear you found it of use!

  • Tolida

    I tried to install the software here, but I have a problem with it.
    When in Sequel Pro it is not possible to choose database, popup is not active.
    When I type the Database name myself “wordpress” and click connect I get the message:
    MySQL said: Access denied for user ‘root’@'localhost’ (using password: YES)
    Maybe this has to do with previous attempts to get mySQL running on this server, I tried to clean up myself (there is no uninstaller for MySQL) maybe something is left.
    If this is the reason, do I have to complete reinstall Lion and Lion Server?
    Please Help.

    • Simon

      Hi Tolida, to rule out any problems, I would start from a fresh install. If you still have a problem after that, let me know and I will try to work out what is going wrong for you.

      • http://norestfortheobsessed.com Ton

        Simon,

        Thanks for offering me help.
        I did a clean install of Lion 10.7.2. with server 10.7.2, SAME ERROR….
        Then I tried in Sql Pro only with host and username, nothing else and then I could continue!!
        Everything seems to work now!
        Except for one thing wordpress works only with the files in the folder “Default” I prefer to have it in a folder “wordpress” in “Sites” it works not also when I changed the path to the folder in server.
        Maybe you have a solution for this also?
        Thanks again, Tolida.

      • http://norestfortheobsessed.com Ton

        Simon,

        I have another question if possible?
        Can you direct me to a place where I can find instructions for installing phpMyAdmin? and how to host several site on lion server?
        I found something that Lion server handle this in a non standard way???

        • Simon

          Hi Ton, Sorry for the delay in getting back to you.

          You should be able set the web roots in the Server app? You can create directories for separate sites.

          phpMyAdmin works in a similar way to phpPgAdmin. I have a post on that here.

          Is this any use for the multiple sites question?

  • Michael

    This didn’t work for me, and every single reference to the ‘Error establishing a database connection’ problem just reiterated some form of ‘change mysql.default_socket to /tmp/mysql.sock’. Well… It turns out that the php.ini on my lion server has *SEVERAL* lines where it defines

    mysql.default_socket=/var/mysql/mysql.sock

    You have to get them all. That’s what finally worked for me. I hope this saves someone some time.

    • Simon

      Thank you for sharing your problem and solution, Michael. I’m sure it will help some.

      I’ve personally only experienced php.ini files with the “mysql.default_socket” line in once. Make sure you are changing the line as displayed in the screenshot, under:

      Default socket name for local MySQL connects.
  • Will

    Perfectly detailed instructions Simon… was banging my head on the desk trying to get this to work until I came across your instructions. Keep up the excellent work.

  • Palex

    Hello. Your walkthrough is brilliant — thank you. I managed to get everything up and running with WordPress. However, when I try to publish new content (pages/posts), the link and the file placement are not synced. In other words, when I click on the link to the Page/Post that I’ve just created, I’m told that the file doesn’t exist.

    Any ideas?

    • Simon

      Hi Palex, are you running your blog locally (localhost)? Do you notice if the URL changes when you visit your post? You could try checking the settings in WordPress admin under Settings > General – check the address URL’s are correct.

  • Palex

    Thanks for the reply. I was attempting to run WordPress through the DNS designated by my server. The address is correct in Settings (I’m also using a DNS alias), but for whatever reason, content would post to folders that didn’t exist (like ‘http://dnsalias.net/wordpress/listings/page-name/’). Content would ‘post’, and I was able to edit it through the admin, but I could not ‘visit’ it.

    I’ve since decided to move on to more traditional methods of displaying content for clients, but if you happen to know the solution to this problem, it may help someone else.

  • Spotsbox

    hello i used your guide and everything is setup however my wordpress isn’t showing the website files properly what is the cause of this?

    • http://www.mactasia.co.uk/ Simon

      Hi Spotsbox,

      Thanks for your message (I also got you email). I visited your site and it seems to be working now – so I guess you sussed it? :)

  • Kevo

    Yeah, mate! Cheers! Just installed it and it works ACE! Thank you very much! 

  • Jmc

    Great tute, I’ve had success managing to get mySQL access set up locally, but I’m having no luck with setting it up for remote access, ie accessing the server from laptop remotely, whilst off site.  Do you have any pointers/tips for going about this, It’s a bit of a necessity for me to be able to administer db remotely.  Many thanks in advance.
    Oh and your directions seem to work on 10.7.4 server which is great too.
    J

    • http://www.mactasia.co.uk/ Simon

      Hi Jmc, I’m pleased that you have found the guide useful.

      I don’t have any direct experience with remotely accessing an SQL database hosted on an Apple server, as my daily job enables me to use ARD.

      Have you considered something like phpMyAdmin or phpPgAdmin? I have guides for those on the site too, and i’ve always found them easier to use with web hosting solutions etc.

  • http://twitter.com/ajsadeh Amir Sadeh

    +1 on the thanks. Worked first time beautifully on Mountain Lion Server 2.2.1

  • http://www.facebook.com/sameer.arbee Sameer Arbee

    How do you set it up to actually host a website globally rather than an internal website?

    • http://www.mactasia.co.uk/ Simon

      Hi Sameer,

      That would require you to configure the Web Server options in the Server.app.

      You will also need to use a service like DynDNS unless you have a fixed external IP.

      Maybe I will do an article on this next.

  • LEE WK

    Thank you. I’ve deleted MAMP. Thank you very much.