I’ve posted this on the Apple Forum too, but considering my end goal was to get my local WordPress site running, I should post it here.
It’s taken me most of the day to work this out, so I thought I should post about it somewhere and here, on the Apple/WordPress forums, are the ideal location.
I’m a web developer and love the fact that my MacBook works out of the box with a Unix webserver and with little effort, I was able to set up PHP and MySQL on it. I was delighted to hear that the new Snow Leopard was shipping with the latest and greatest of both. It wasn’t quite that easy when it came down to running my test sites, one of which I’m working on is a WordPress site. Far from being daunting, the solutions to the problems I had were quite simple. The issues arose from the OS not having much exposure yet and not many people having posted their experiences on the web. It was just time consuming.
I should mention at this point that this does require some tinkering with Terminal, but not so much as to cause damage if you do something wrong.
First off Apache. Thankfully this is as stable as it always has been. All this requires to activate it is to visit System Preferences > Sharing and switch on Web sharing. Bish-bosh, job done.
Next off PHP. If you open a Safari window and run your phpinfo.php file (where ever you have it saved. If you don’t, they’re out there, it’s a tiny piece of code which you can use to find out your current php setup). You’ll find that everything is superb! PHP 5.3! Excellent! Hang on, scroll down to the date and time section. Whoa! What’s this big fat warning here?
That warning my friend, has been the bane of my misery all day. WordPress hates it. HATES IT! It causes no end of grief. So what’s the multi step, multi program solution?
Open your php.ini file and add the line:
(do a Google search for PHP Timezones and you will get the exact settings. It’s not so good that it understands every city in the world. My setting was Europe/Dublin).
That’s all. This will solve your issue of the timezone error everywhere. Stop and start Apache (System Preferences > Sharing, tick off and tick back on Web Sharing) and hey presto, error is gone.
Wait a minute, where the hell is my php.ini file? Unfortunately this is where you have to get your hands dirty. Your php.ini file is a system file which resides in the /etc/ folder. Open a terminal window and type exactly the following:
cp php.ini.default php.ini
This makes the php.ini file from the default. This protects the original so if you ever need to create a new copy or if you make a mistake in the next steps, you can start again.
Next I’m going to tell you how to edit this file. This uses a program called vi (there are GUI editors out there that will save you this heartache, so if anyone knows any, please post in response. I think TextWrangler is one).
First you need to set the php.ini file so you can edit it. Type in exactly as follows:
sudo chmod 777 php.ini
Sudo is the superuser commmand. It may not be needed, but stick it in anyway. If you are asked for a password, put in your normal password (that you would be asked for say if you were installing something you downloaded).
At the next prompt, type in:
This will open the php.ini file. Using the up and down keys, find a blank line in the file. You will notice that alot of the lines start with ‘;’. These are commented lines. Once you find a blank line, press ‘i’ to insert text. Your screen will now say ‘– INSERT –‘ at the bottom in red. Type the following in exactly (you will NOT be able to cut and paste):
; Set PHP Default Timezone
Substitute “Europe/Dublin” with your own timezone. When you are done, press escape. Now type in the following:
The colon is important (not a typo on my part) as this tells vi you are going to run a command. You should now be back at your prompt. Now you need to reset the permissions on the file. Type the following:
sudo chmod 444 php.ini
And that’s it. That’s your PHP setup and finished. If you run your phpinfo.php file now, you should see your timezone under the date and time where you were getting the error before.
Now the MySQL. This is a bit of fun because, even though MySQL ships with the system, it’s not exactly set up correctly! So once again into terminal.
This time go to the local directory:
If you type in:
You’ll get a directory listing. This has the MySQL folder listed as mysql-5.0.77-osx10.5-x86 (or something! I did that from memory!). This IS the MySQL folder but if you, like me, had previously set the MySQL Preference Pane in your System Preferences, then it won’t be able to access this. Type the following command:
sudo cp -R /usr/local/mysql* /usr/local/mysql
This should copy everything into a folder called mysql. It takes a couple of seconds (first time on my machine it was a good 20 seconds) to run so be patient. Now you need to do the following:
sudo chown mysql:mysql /usr/local/mysql
This sets the owner and group of the mysql files to ‘mysql’. If you go back to your MySQL preference pane in System Preferences, you should now be able to start it (something weird about it makes it require to close and reopen the System Preferences window before it can open the MySQL pref pane. This is normal, just click ok).
The bit that got me here, is that I thought that my activation of the MySQL was actually a new install. I tried everything to change the root user and password for MySQL but in fact, if you had it installed on Leopard, prior to upgrading to Snow Leopard, all your users and passwords are the same. If you HAVEN’T installed it before, I recommend you read the Post Installation Customisation (section 2.3) on the manual for MySQL 5.1 on http://www.mysql.com
So that’s about it. All that remains is to test WordPress. I have phpmyadmin installed (I’ve heard CocoaMySQL is very good, like iTunes for db’s so I’m gonna check that out later) and was able to create the new wordpress database. I changed the settings in the wp-configure.php file to match my setup but nothing worked. I changed the host from ‘127.0.0.1’ back to ‘localhost’ (a common complaint of the wordpress setup) but no joy. Then I changed the host back to ‘127.0.0.1’ and added the port :3306 (so the full host is ‘127.0.0.1:3306’) and bingo, the install worked, my database setup and my test site worked.
So that’s it! Many of you out there will say, why didn’t you just use MAMP? I did use MAMP, but I also got the Timezone issues and it took far more tinkering and hacking to make it work. I decided that, as my lovely MacBook now running lovely Snow Leopard had the lovely newest versions of PHP and MySQL installed, I’d rather get them working than use a runaround with MAMP. I’m a happier camper for it.
I hope this helps some of you out there. I don’t personally have a blog yet, but when I do, I’ll post this up there for all to access. I may even add screen shots!!! But seriously, I hope this helps you all out with your installs. It’s so handy to have all this stuff straightaway with Snow Leopard, it’s just a matter of getting it to work.
All the best now,
- The topic ‘Snow Leopard, Apache, PHP, MySQL and WordPress!’ is closed to new replies.