WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Snow Leopard, Apache, PHP, MySQL and WordPress! (18 posts)

  1. tady
    Member
    Posted 4 years ago #

    Hi there,

    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:

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

    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 "Europe/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

  2. Dennis Whiteman
    Member
    Posted 4 years ago #

    When you install MySQL on Leopard and earlier versions, it installs the directory in /usr/local/ as you say, something along the lines of...

    /usr/local/mysql-5.0.77-osx10.5-x86

    ...and then it creates a symbolic link to that directory called mysql. When you upgrade to Snow Leopard, it backs up everything in /usr/local and later restores it back to /usr/local/. However, Apple's installer does not recreate the mysql symbolic link during the upgrade process. So, there's no need to rename that directory to mysql, just create a symbolic link to it as the official mysql installer does.

    ln -s /usr/local/mysql-5.0.77-osx10.5-x86 /usr/local/mysql

    Once you create the symbolic link, MySQL will start automatically. At some point you'll want to upgrade and this method will leave your previous installations in place.

    Dennis

  3. macgruder
    Member
    Posted 4 years ago #

    Tady,
    As fastpipe recommends you shouldn't be moving the mysql directory like that. Use a symbolic link - this is how binary installs are usually done. You probably installed the MySQL binary, and when you updated to Snow Leopard Apple removed the symbolic link to prevent it from starting up - as there maybe problems with the 32-bit version on SN.

  4. pneal
    Member
    Posted 4 years ago #

    Tady,

    I can still not get the database to connect. It's working fine for me using other programs to connect to mysql databases but not wordpress. I've tried the settings you suggested, as well as numerous others, but no joy. Any additional advice? I've been looking for a solution for a week now and it's very frustrating. Any advice?

    Thanks

  5. profeddieb
    Member
    Posted 4 years ago #

    pneal
    I have struggle with the exact same problem. It has been very annoying. Anytime I copied the php.ini.default to php.ini and made the change . . . . my timezone setting would be correct - but I could no longer connect to the database.

    I finally solved the issue.

    In the same directory . . . . you should have a previous php.ini (eg: php.ini-5.2-previous). I decided to rename that as php.ini. Then add the line:
    date.timezone=America/Chicago

    Once I did that . . . . all my wordpress install worked - and no longer threw the error.

    Be careful to keep your php.ini.default intact . . . . just in case.

    Hope that helps.

  6. bartpop
    Member
    Posted 4 years ago #

    I had the same issue but finally found that if I changed the DB_HOST in my wp-donfig.php file to "127.0.0.1:3306" that everything started working. None of the other setting worked for the DB_HOST: localhost, localhost:3306, or 127.0.0.1

    Hope that helps someone in the future.

  7. maestric
    Member
    Posted 4 years ago #

    Easy steps to follow for those starting with a clean install of Snow Leopard.

  8. creativereason
    Member
    Posted 4 years ago #

    FYI... I rum MAMP for testing some stuff on my mac and after upgrading to Snow Leopard I've had no issues with my wordpress install on it at all.

    To preempt the questions of why do this when you already get these tools out of the box... I like that MAMP installs phpmyadmin and can be turned off and on, and when I originally installed it, I wasn't as comfortable with bash and linux / unix as I am now.

    I still use both directories (mamp install) and the root apache directories.

  9. oklunden
    Member
    Posted 4 years ago #

    Tady, nice writing!

    Though good practice is that you don't change the permissions for a file just because you want to edit it.

    Instead of your line sudo chmod 777 php.ini, USE sudo vi php.ini. That way you'll leave the permission as they were intended to be.

    good luck!

  10. AdrianaTX
    Member
    Posted 4 years ago #

    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.

    MySQL does not ship with Snow Leopard.

  11. Web Hosting India
    Member
    Posted 4 years ago #

    Thanks @ bartpop

    You have solved my issue

    [Mod note : signature moderated Please read the Forum Rules]

  12. timlanta
    Member
    Posted 4 years ago #

    tady,

    I'm a neophyte when it comes to leaving the comfort of the GUI. I got this message (cp: php.ini: Permission denied) when I tried to make the php.ini file from the default as stated in your tute. I am the administrator by the way, and am using the Terminal.app in the utilities folder to enter the commands.
    Thanks

  13. JeremyVaught
    Member
    Posted 4 years ago #

    @timlanta,
    Not sure why that happens, but it happened to me to. I had to change the settings to have access. So to change the settings on the php.ini file I used,

    sudo chmod 777 php.ini

    Then edit your vile with your text editor. I just use vi, so I typed,

    sudo vi php.ini

    When you are done, make sure you change the settings back so that your php.ini can't be accessed when it shouldn't be.

    sudo chmod 444 php.ini

    I'm not sure of the actual settings, but 444 seemed to do the trick.

  14. timlanta
    Member
    Posted 4 years ago #

    @JeremyVaught,
    Thanks for your reply. I have moved on and simply installed MAMP, which is nice except for the whole "setting up of the virtual hosts thing". I used this http://www.sawmac.com/mamp/virtualhosts/ for reference but something is amiss; when I try to access my virtual host, the browser keeps going to MAMP's htdocs folder. PAIN

  15. aradams
    Member
    Posted 4 years ago #

    Thanks bartpop! Was tearing out my hear trying to get WP installed on Snow Leopard. changed the db_host and it worked.

  16. ondacuantica
    Member
    Posted 4 years ago #

    Just one word: THANKS!

  17. jhettich
    Member
    Posted 4 years ago #

    This was useful ... Thanks to your tips, my installation was successful on the first go!

    I did a plain vanilla installation of MySQL on Snow Leopard, using the 64-bit DMG archive from the MySQL site: mysql-5.1.45-osx10.6-x86_64.dmg.

    I used the version of php that came installed with Snow Leopard, but fixed the TimeZone issue per the instructions above.

    In setting up WordPress, I followed the step-by-step instructions on the WordPress site, using '127.0.0.1:3306' for DB_HOST in the wp_config.php file (again per the recommendation above).

  18. del.sunil
    Member
    Posted 4 years ago #

    i have tried this on website http://www.withss.com/ but can't fix it else what i need to do .

Topic Closed

This topic has been closed to new replies.

About this Topic