Setup PHP, Apache, and MySQL in Mac without MAMP – Part II

In the previous tutorial of this series, we have configured Apache and PHP and thus we are able to run .php files in our local server. As a follow up, we are now going to install and set MySQL up which we will be using for the database.

Let’s get started.

PHP Installer

Fortunately, MySQL comes in a form of .pkg installer that provides an easy step-by-step instruction. Download the package from this page, and make sure you grab the the DMG Archive version, which could be either Mac OS X 10.7 (x86, 64-bit), DMG Archive or Mac OS X 10.7 (x86, 32-bit), DMG Archive if you are running on 32 bit machine.

Launch the DMG package. And you should find three files as shown in the following screenshot.

  1. mysql-5.6.15-OS X10.7-x86_64.pkg, the main package to install MySQL in OS X.
  2. MySQL.prefPane, for adding MySQL panel in the System Preference.
  3. MySQLStartupItem.pkg, to enable MySQL to start at system startup or reboot.

Install all three. Then, after they are all completed, open System Preference, and navigate to the MySQL pane.

Turn MySQL Server on, and tick Automatically Start MySQL Server on Startup.

Connecting PHP to MySQL

At this point, MySQL is running. But, OS X searches a different directory to find MySQL socket, mysql.sock, which causes the Warning: mysql_connect(): [2002] No such file or directory error when trying to connect PHP to MySQL.

To solve this, we will create a symbolic link (symlink) in the directory where OS X expects to find the MySQL socket.

  1. Open Terminal.
  2. Navigate to the var folder with cd /var.
  3. Type mkdir mysql to create a new directory named mysql
  4. Create the symlink of mysql.sock using ln -s /tmp/mysql.sock /mysql/mysql.sock command.

Set MySQL Password

Then we need to create password for root user. In Unix terminology, the root user is the one who has all administrative access. Type the following command in Terminal to set the password:

mysqladmin -u root password new_password

Change the “new_password” with the password of your choice.

Managing MySQL

Now, we need to find a way to manage MySQL. The popular way for doing this would be using a web-based application such as phpMyAdmin. But, I’m not quite fancy with phpMyAdmin User Interface, and the installation process (to me) is rather complicated.

I found a good alternative, a lovable native OS X application named Sequel Pro. Grab the installer here, put it in the Application folder, and launch it.

In this tutorial, we are going to connect to MySQL via the socket file. So, let’s head over to the Socket tab, and enter the following information:

  1. Name: This could be anything. You can name the connection, for example, OS X MySQL.
  2. Username: Enter the MySQL username as root – since we have no other users at this point.
  3. Password: Enter the Password that you have set for the root user above.
  4. Database: We are not going to connect to a particular database. In fact, we haven’t created any databse, yet. So, leave this empty.
  5. Socket: Set the socket path to /var/mysql/mysql.sock.

Click the Connect button.

Once you are connected to the MySQL, you can create, modify, and delete databases as well as creating new MySQL users. In the following example, as shown below, I’ve created a database named wordpress for my WordPress site.


In this tutorial, we have done configuring MySQL. Now, you have a fully functioning local server for developing PHP-based website in Mac. In the next part and last part, we are going to show you how to custmize the localhost. So, stay tuned.