Benches macOS

15

Snow Leopard, PHP, MySQL, Apache and Word…

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Hi there,

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 forum, is 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:

date.timezone=Country/City

(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 **** 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:

cd /etc/

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:

vi php.ini

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

date.timezone=Europe/Dublin

Substitute "Europ/Dublin" with your own timezone. When you are done, press escape. Now type in the following:

:wq!

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:

cd /usr/local/

If you type in:

ls -al

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,

T

15 replies

Sign in or join Beachball Help to reply.

  1. 0

    MonkeyT

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    A lot of your timezone troubles comes from PHP5.3 tweaks. Read up on the DateTime Object for full details. Lists of timezones can be found here:

    http://www.php.net/manual/en/timezones.php

  2. 0

    semifamous

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hmmmm... I did a clean drive install of Snow Leopard because I used to do it once a year with Windows and hadn't done it in 3 with my MBP.

    First, my httpd.conf file had the line enabling PHP commented out, so when I went to see my simple file with phpinfo(), I saw the source. Saw your post, thought it was the timezone, fixed that (which will probably make wordpress happy when I get it running), and it still didn't work. Looked at the httpd.conf file, found that PHP was disabled by default, fixed that line, restarted the server, and my phpinfo() worked like a charm.

    Also if you want to edit config files, I use TextWrangler's "open hidden files" option.

    But... I have no /usr/local directory at all. Doesn't exist on my machine. Checked the options in the base install and MySQL isn't offered as an option. Checked the optional installs and MySQL isn't there. Even letting spotlight search for hidden files, the only files with MySQL in their name were from php scripts in my web folders.

    There's some stuff about installing/compiling from source.

    http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/

    Dunno if I want to go down that road quite yet.

  3. 0

    Allan Eckert

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi semifamous;

    But OS X is
    NOT Windows. There is absolute no reason to do an Erase & Install with OS X periodically as there is with Windows. I have run OS X for years now and have yet to do an Erase & Install.

    Allan

    User uploaded file

  4. 0

    MonkeyT

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Because of open source licensing conflicts introduced a few years ago, MySQL is rarely included in base installs of any OS any more. The good news is that if you go to MySQL.com 's downloads, you can get an installer for OS X in Package form - no compiling needed. Pick the newest version whose processor matches your machine (I doubt they have one labeled 10.6 yet) Others have reported that the installer runs perfectly and Snow Leopard's PHP recognizes it out of the box, unlike some earlier Apple installs which needed you to either change the address for Mysql's sock file or building a symlink.

  5. 0

    semifamous

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    First, a wipe and install is a good way to get rid of clutter in general. Even Macs can pick up clutter. It's a good way to force yourself to reorganize and clean house, and to fix things you might have screwed up over the years.

    Second, I tried the 32-bit install of MySQL 5.1.37. I could get it to work with a socket connection via a GUI MySQL interface and phpMyAdmin, but I could not get it to connect to Localhost.

    I'd read someone saying the 5.4 beta worked great on their 10.6 system, so I got the 64-bit 5.4 beta and still had problems with the localhost connectivity, particularly in getting the Wordpress install to run. I got it working on localhost with a TCP connection method for phpMyAdmin and the GUI, but both of those had you specify the port.

    So, for the Wordpress installer, I decided to try specifying the host as 127.0.0.1:3306 and it worked. My MAMP environment with Wordpress works just fine now.

  6. 0

    Allan Eckert

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hi semifamous;

    While it true as you say that, "Even Macs can pick up clutter." At least it isn't hidden away from you so that they only way to clean up is to repave the disk and start over. There are tool such as OmniDiskSweeper which can help you to clean up without having to do an Erase & Install.

    Allan

    User uploaded file

  7. 0

    MonkeyT

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    In the past, I have seen mysql's os x installer be cranky about responding to localhost. It has always worked for me when I specified 127.0.0.1 instead. It's also felt a little faster with direct addressing.

  8. 0

    capaho

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    But OS X is NOT Windows. There is absolute no reason to do an Erase & Install with OS X periodically as there is with Windows. I have run OS X for years now and have yet to do an Erase & Install.

    There should never be a reason to erase and install OS X to fix a problem unless the user trashed system files that Disk Repair can't restore or in the event that the system is compromised by a Trojan or other malicious file.

    Windows and OS X are fundamentally different operating systems. OS X (and Linux) are modular systems, whereas Windows is a monolithic design with a horrendous system registry file that gradually degrades performance as it slowly gets mucked up over time. As a result, Windows users who switch to Macs bring a lot of bad (and unnecessary) habits with them.

  9. 0

    Allan Eckert

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I thought that was what I said?

    Allan

  10. 0

    semifamous

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Yes, but I was going from Tiger to Snow Leopard, so either way I was going to introduce conflicts and break things. I figured a wipe and a clean install was going to be better than upgrading a three-year-old Tiger install that was already acting a little hinky.

    While I did the wipe and install with the same Windows OS every 12-18 months, I only did wipe and install on OSX when I was jumping up two notches in OS versions to a version that is already getting press for bricking systems on upgrade.

  11. 0

    capaho

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I thought that was what I said?

    I was merely providing a more detailed explanation in support of your statement.

  12. 0

    capaho

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Yes, but I was going from Tiger to Snow Leopard, so either way I was going to introduce conflicts and break things.

    There's nothing wrong with doing a clean install, and it is the best way to make sure you don't have any upgrade glitches, but it's rarely necessary in the case of OS X. However, if you don't mind the extra work, it doesn't hurt anything to take a cautious approach.

  13. 0

    Chris Jones22

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    hello. can we get back to the subject about Snow Leopard and the MySQL & PHP Problem.

    I had a similar problem with MySQL & PHP when I migrated our database from the older version (2008) iMac to the newer (2009) iMac. This happened when Mac decided that their base model should be scrapped. It also happened when I moved all the files from serving iMac to a portable MacBook.

    To fix that, I copied all the conf. files over to the awaiting machine in distress

    I've just upgraded the (was) working iMac and not its not working.

    I've tried all the changes in php.ini.default file which include,

    Changing all occurrences of /var/mysql/mysql.sock to /var/mysql.sock

    which didn't do much as it still lists this directory "/var/mysql/mysql.sock" in the "configure command" box (3rd box down. php info page).

    I also changed the ;date.timezone because your right, it does give a warning. but even after changing it, it still gives the warning.

    Times like this I wished I'd BACKED IT UP!

  14. 0

    Chris Jones22

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks guys. I found the answer myself...

    For anyone or future ref

    YOU MUST REINSTALL mySQL after upgrading to Snow Leopard and remove any previous versions as well as previous startup from the preference panel. install 86_64 10.5...I find the others did not work for me.

    Download MySQL version Mac OS X 10.5 (x86_64) located at
    http://dev.mysql.com/downloads/mysql/5.4.html#macosx-dmg

    Install startup Item (follow instructions)

    Then install the beta version (follow instructions)

    If you want the start up in the Preference Panel...install mySQL.prefpane I find that SQL does not run from the terminal unless you start mySQL in the preference panel.

    Terminal mysql access: /usr/local/mysql/bin/mysql -u root -p

    password not needed for first installed mysql

    Create root password:

    quit out of mysql

    type: mysqladmin -u root password 'newpassword'

    I'm hoping you've all backed up your databases because it will need to be recreated.

    Good luck!!

  15. 0

    Shmajent

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    "Safari can’t open the page “
    http://+[etcetera].local+//login.php” because the server unexpectedly dropped the connection."

    I'm about to pull my hair out. That's the message I get when trying to get MySQL and PHP to play nice. At one point when messing around I was able to get the mysql_connect() function to return false, which suggests a bad connection. Now the thing won't even spit out anything involving MySQL.

    Fresh install of MySQL, no previous version installed. I have already tried modifying sockets to point to /tmp/mysql.sock, and so forth...

    Yes, I am running Snow Leopard at work, where I'm trying to get this to work.