macOS Update: While these instructions still work, there are new posts for recent versions of macOS, the latest being Install Apache, PHP, and MySQL on macOS Mojave.
Run the MySQL installer. Complete additional MySQL configuration. Configure MySQL with a root password. Reboot your computer to restart MySQL. Download the Specify installer package for Mac OS from the Specify Software. Oct 29, 2017 Questions: I’m trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52. Everything goes well and I am also successful with the mysqlinstalldb.
PHP Update: Mac OS X Yosemite comes pre-installed with PHP version 5.5 which has reached its end of life. After you complete this post, you should upgrade PHP on Mac OS X.
I recently upgraded to Mac OS X Yosemite. It seems Mac OS X Yosemite makes my original post on installing Apache, PHP, and MySQL on Mac OS X obsolete. Specifically, Yosemite includes Apache 2.4. This post is a complete update for installing Apache, PHP, and MySQL on Mac OS X Yosemite.
A reminder that Mac OS X runs atop UNIX. So most UNIX software installs easily on Mac OS X. Furthermore, Apache and PHP come packaged with Mac OS X. To create a local web server, all you need to do is enable them and install MySQL.
I am aware of the web server software available for Mac OS X, notably MAMP. These get you started quickly. But they forego the learning experience and, as most developers report, can become difficult to manage.
Getting Started
First, open the Terminal app and switch to the root
user to avoid permission issues while running these commands.
Enable Apache on Mac OS X
Verify It works! by accessing http://localhost
Enable PHP for Apache
First, make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.
Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.
Uncomment the following line (remove #
):
Restart Apache:
You can verify PHP is enabled by creating a phpinfo()
page in your DocumentRoot
.
The default DocumentRoot
for Mac OS X Yosemite is /Library/WebServer/Documents
. You can verify this from your Apache configuration.
Now create the phpinfo()
page in your DocumentRoot
:
Verify PHP by accessing http://localhost/phpinfo.php
Install MySQL on Mac OS X
Note: If you are upgrading MySQL you should skip this section and instead read this.
- Download the MySQL DMG for Mac OS X
- Install MySQL
The README suggests creating aliases for mysql
and mysqladmin
. However there are other commands that are helpful such as mysqldump
. Instead, I updated my path to include /usr/local/mysql/bin
.
Note: You will need to open a new Terminal window or run the command above for your path to update.
I also run mysql_secure_installation
. While this isn't necessary, it's good practice.
Connect PHP and MySQL
You need to ensure PHP and MySQL can communicate with one another. There are several options to do so. I do the following:
Additional Configuration (optional)
The default configuration for Apache 2.4 on Mac OS X seemed pretty lean. For example, common modules like mod_rewrite
were disabled. You may consider enabling this now to avoid forgetting they are disabled in the future.
I edited my Apache Configuration:
I uncommented the following lines (remove #
):
Note: Previous version of Mac OS X ran Apache 2.2. If you upgraded OS X and previously configured Apache, you may want to read more about upgrading to to Apache 2.4 from Apache 2.2.
Mac Windows Download
If you develop multiple projects and would like each to have a unique url, you can configure Apache VirtualHosts for Mac OS X.
If you would like to install PHPMyAdmin, return to my original post on installing Apache, PHP, and MySQL on Mac OS X.
Find this interesting? Let's continue the conversation on Twitter.
How to install MySQL server on Mac OS X
Mac OS X has a great design and a lot of tasks are really easy to do. Unfortunately if you want to have MySQL server installed on your Mac this is not always as simple as everything else.
But wait do I need MySQL server?
In many cases you do not. If this is going to be the only computer on which you will have your sales information, you are planning to have only a few operations every day, or you will connect to other computers using IncoCloud, then no, you can use SQLite and keep things simple.
But if you have more than one computer in the office/shop/restaurant connected together – one or more front office computers or tablets and one or more back office computers all in a single location, for example, or you expect many operations made every day, then you need MySQL server to handle the big load.
Important!IncoPOS – our Point of Sale system for macOS can now download, install and configure MySQL server for you. This happens from the built-in wizard when IncoPOS is started for the first time. You can download IncoPOS from here.
The first step is to download MySQL server. Go to the MySQL web site and select the version that matches your version of Mac OS. Select the DMG archive version. After the DMG file finishes downloading click on it to open. Then open the installer inside and follow the installation steps.Warning! Because Oracle has changed the MySQL installer and the default parameters of the MySQL server in newer versions the following steps may no longer work. These steps were tested with MySQL server version 5.5.48 for Mac OS 10.9 (which should work on newer versions too). Please download and install version 5.5.48 to make sure that all the steps will work correctly. If for some reason the installer is no longer available on the MySQL web site you can download it from here.
After the installation has finished, open the System Preferences and you should see the MySQL icon. Click on it to open the MySQL server preferences. Now press the Start MySQL server button so MySQL would actually start working. Make sure to leave the checkboxMysql Download Mac
“Automatically Start MySQL Server on Startup” so you won’t have to do that again.Now comes the tricky part. By default MySQL server installs without password and does not restrict access to the information on it. This is not a great idea for us because your information is sensitive and we don’t want the whole world to be able to access it.
For the next part you need to open the Terminal app.
- To open the Terminal app click on the magnifying glass icon on the top right on your mac. This will open Spotlight.
- Type terminal in the search field.
- When the Terminal app appears in the list, select it by pressing Enter.
In the Terminal screen, type these commands and press Enter after each one of them:
cd /usr/local/mysql
This will change the current directory to the one where MySQL server is installed
sudo bin/mysql_secure_installation
This command will ask for your computer password. While typing it no characters will be displayed which is normal so don’t worry. Press Enter when finished. This will start a script which will ask you several questions and then reconfigure MySQL.
Set root password? [Y/n]
Select Y and press Enter. After that enter a password for MySQL and press Enter. Re-enter the password and press Enter again. This will be the password that IncoPOS will need when connecting to MySQL server.
Remove anonymous users? [Y/n]Select Y and press Enter. You don’t need anyone but you or someone you told your password to touch your data.
Disallow root login remotely? [Y/n]
Mysql For Mac
Here you have to decide. If you have more than one computer that will be using this data then answer n. If this information will be accessed only from this computer then select Y. In all cases this can later be changed by using the same commands.
Remove test database and access to it? [Y/n]
Select Y and press Enter. You don’t need that test database so it is safe to remove it.
Mac Download Game
Reload privilege tables now? [Y/n]
Select Y and press Enter. This will make the changes you did effective now.
This is it! Now you have MySQL installed and secured on your Mac.