Sunday, June 3, 2012

Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard) or 10.7 (Lion)?


What is the easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard)?



I'd prefer to use any bundled versions before resorting to downloading from the PHP or MySQL websites.



I'm comfortable at the command line in Terminal.


Source: Tips4all

12 comments:

  1. Open a good text editor (I'd recommend TextMate, but the free TextWrangler or vi or nano will do too), and open:

    /etc/apache2/httpd.conf


    Find the line:

    "#LoadModule php5_module libexec/apache2/libphp5.so"


    And uncomment it (remove the #).

    Download and install the latest MySQL version from mysql.com. Choose the x86_64 version for Intel (unless your Intel Mac is the original Macbook Pro or Macbook, which are not 64 bit chips. In those cases, use the 32 bit x86 version).

    Install all the MySQL components. Using the pref pane, start MySQL.

    In the Sharing System Pref, turn on (or if it was already on, turn off/on) Web Sharing.

    You should now have Apache/PHP/MySQL running.

    In 10.4 and 10.5 it was necessary to modify the php.ini file to point to the correct location of mysql.sock. There are reports that this is fixed in 10.6, but that doesn't appear to be the case for all of us, given some of the comments below.

    ReplyDelete
  2. To complete your setup or MySQL:

    sudo vim /etc/profile



    Add alias

    alias mysql=/usr/local/mysql/bin/mysql
    alias mysqladmin=/usr/local/mysql/bin/mysqladmin

    Then set your root password

    mysqladmin -u root password 'yourPassword'

    Then you can login with

    mysql -u root -p

    ReplyDelete
  3. I've summarized all the necessary steps (tested with a clean install of Snow Leopard).

    ReplyDelete
  4. I strongly prefer HomeBrew over MacPorts for installing software from source.

    HomeBrew sequesters everything in /usr/local/Cellar so it doesn't spew files all over the place. (Yes, MacPorts keeps everything in /opt/local, but it requires sudo access, and I don't trust MacPorts with root.)

    Installing MySQL is as simple as:

    brew install mysql
    mysql_install_db


    To start mysql, in Terminal type:

    mysqld&


    There's a way to start it upon boot, but I like to start it manually.

    ReplyDelete
  5. It's an invisible folder. Just hit Command + Shift + G (takes you to the Go to Folder menu item) and type /etc/.

    Then it will take you to inside that folder.

    ReplyDelete
  6. This help me a lot:

    http://maestric.com/doc/mac/apache_php_mysql_snow_leopard

    It also works for Mac OS X Lion :D

    .:EDIT:.
    On my case the prefepane only allows to start and stop mysql, but after some issues i've uninstalled him.
    If you need a application to run queries and create DB, you could use: Sequel Pro (it's free) or Navicat

    If you need start and stop mysql in ~/.bash_profile you can add these lines:

    #For MySQL
    alias mysql_start="/Library/StartupItems/MySQLCOM/MySQLCOM start"
    alias mysql_stop="/Library/StartupItems/MySQLCOM/MySQLCOM stop"


    After reloaded the console just call:

    $mysql_start


    or

    $mysql_stop


    agreding the desired action.
    Hope helped you.

    ReplyDelete
  7. I would agree with Benjamin, either install MAMP or MacPorts (http://www.macports.org/). Keeping your PHP install separate is simpler and avoids messing up the core PHP install if you make any mistakes!

    MacPorts is a bit better for installing other software, such as ImageMagick. See a full list of available ports at http://www.macports.org/ports.php

    MAMP just really does PHP, Apache and MySQL so any future PHP modules you want will need to be manually enabled. It is incredibly easy to use though.

    ReplyDelete
  8. I'm not quite sure as I'm not so familiar with Mac OS X, but I think this will work in Snow Leopard too: 10.5: How to enable PHP and MySQL in 10.5 UNIX.

    ReplyDelete
  9. Considering it hasn't been released yet, I'm assuming this is a question for ahead-of-time or you have a developer's build. As Benjamin mentioned, MAMP is the easiest way. However, if you want a native install, the process should be like 10.5. PHP comes installed on OS X by default (not always activated for some), just download the 32-bit version of MySQL, start Apache, and you should be good to go. You may have to tweak Apache for PHP or MySQL, depending on what builds are present. I didn't have to tweak anything to have it working.

    ReplyDelete
  10. Has anyone tried XAMPP? http://www.apachefriends.org/en/xampp-macosx.html

    ReplyDelete
  11. FYI - if anyone experience issues with launching Apache, and getting errors about

    /usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

    it's because of a recent update to Apache in Snow Leopard. The fix is easy, just open /usr/sbin/apachectl and set ULIMIT=""

    http://blog.deversus.com/2010/11/mac-os-1065-apachectl-usrsbinapachectl-line-82-ulimit-open-files-cannot-modify-limit-invalid-argument/

    ReplyDelete