This tutorial will walk you through choosing and downloading the appropriate edition of MAMP, downloading and installing the package, starting its components, and integrating them with the PhpStorm IDE.
As an alternative, you can use the XAMPP cross-platofrm package, which has a similar set of features. Please refer to the Installing and Configuring XAMPP tutorial for more information.
MAMP is the macOS package comprising Apache HTTP server, MySQL database, PHP interpreter, and some libraries. The word "MAMP" is an acronym, where "M" stands for "Macintosh", meaning it's designed for macOS, and the other letters stand for the package components.
MacOS comes with the pre-installed PHP interpreter and Apache server, which can be configured to work well together following the tutorial published by php.net. PhpStorm-related configuration is similar to the one described in this tutorial. Since installing additional packages and configuring the system environment on your own can be tricky, this guide describes how to get everything set up at once easily in a separate environment with complete MAMP package.
MAMP is a reliable and fast way to set up an environment for PHP programming. It provides all the components required for developing, running, debugging, and unit testing of PHP applications. MAMP is a good alternative to installing and configuring a Web server, a PHP engine, a database server, and a debug engine separately. To start developing, you will only need to download and install MAMP, and start the components using the MAMP control panel.
Before starting, the following tools should be available on your system:
From the MAMP web site, we can download and install the MAMP edition which matches the macOS version. The following versions are available:
It's also possible to download additional PHP versions for MAMP PRO.
MAMP is free software distributed under GNU license. MAMP PRO is a paid version which includes additional features. MAMP can be used stand-alone without MAMP PRO.
In this tutorial, we will use the MAMP 4.2 version. The process is the same for the MAMP 3.* version.
From the MAMP downloads page, we can find a list of components included in the package. Click the Download link to download the latest stable package version.
We will be using the pkg version. There is also source code available in zip archive and svn repository.
Once the download of the package is completed, we can run it.
Once the MAMP archive is downloaded, unpack it and run the installer (MAMP_MAMP_PRO_4.2 in our case).
The MAMP installation wizard is pretty straightforward. Click the Continue button to proceed through the installation steps.
After the installation is compete, click the Close button.
After installation, we can use the MAMP Control Panel to perform such actions as starting / stopping servers and changing configurations. The MAMP Control Panel application can be found in the Applications/MAMP folder.
To start the Apache and MySQL servers, click the Start Servers button.
The icons in the top-right corner will become green-colored. Once the servers are started, you can stop them at any time by clicking the Stop Servers button.
The Start Page will open (http://localhost:8888/MAMP/ by default) in the browser. This page contains the information about your environment and provides useful links.
You can configure MAMP by clicking the Preferences... button.
There are several options available:
Having installed MAMP and launched its components, we now need to tell our IDE where these components are stored and how they are configured.
Let's start by registering the PHP executable from MAMP in PhpStorm. Open the Preferences dialog by pressing Cmd+, or choosing PhpStorm | Preferences on the menu. Navigate to Languages & Frameworks | PHP.
With IntelliJ IDEA and PhpStorm, we can have several separate PHP interpreters registered in the IDE, depending on the PHP version or PHP configuration needed for the project. All currently registered installations of PHP interpreters are displayed in the CLI Interpreter drop-down list:
To add the interpreter installed with MAMP, click the Browse button (…) on the right of the list. The CLI Interpreters dialog box opens.
In the left-hand pane, click the Add (+) button on the toolbar.
We can now save these settings and select the newly added PHP interpreter for our project:
Our IntelliJ IDEA or PhpStorm IDE will now use the PHP installation that was bundled with MAMP.
PhpStorm offers a powerful debugger in which breakpoints can be set and variables can be inspected at runtime. For more information on using PhpStorm's debugger, have a look at any of the following articles:
Please note that if you are using the latest MAMP PRO, httpd.conf, php.ini and my.cnf files should be edited through the Template Editor provided by MAMP PRO. Go to File->Edit Template to edit template files. When MAMP PRO starts the Apache and MySQL server it uses these templates to create httpd.conf and php.ini files, erasing the previous ones.
Once you have installed and configured the debugger, you can validate your debugging configuration by performing the steps described in the tutorial.
Interaction between IntelliJ IDEA or PhpStorm with Web, FTP, and other servers is handled by the Remote Hosts Access plugin, which is enabled by default for IntelliJ IDEA and PhpStorm. The IDE accesses servers using the connection settings specified in the registered server access configurations.
To create and manage these configurations, open the Preferences dialog by pressing Cmd+, or choosing PhpStorm | Preferences on the menu.
Navigate to Build, Execution, Deployment | Deployment page.
Click the Add (+) button on the toolbar to add a new server. In the Add Server dialog, we can specify a name for our MAMP server and select the deployment type. For the MAMP Apache server, select the Local or mounted folder type.
After clicking OK, we can specify the path of the Apache's web root (/Applications/MAMP/htdocs) and the URL of the web server, http://localhost:8888. Note that the actual settings depend on how you have configured the MAMP Apache server in the MAMP configuration or Apache configuration files.
Don't forget to mark the server as default so PhpStorm would use it with browser integration and not the built-in web server.
By clicking the Open button, we can open the MAMP htdocs folder in the browser, thus verifying that the provided settings are correct.
IntelliJ IDEA and PhpStorm allow to connect to the MAMP MySQL database server using the Database Tools and SQL plugin, which is installed and enabled by default. Before you start, make sure that the MySQL server is running on the MAMP PRO Control Panel. If you are using MAMP PRO, also make sure that the Allow network access to MySQL check box is selected on the MAMP PRO Control Panel.
Next, from the right-hand side of our IDE, we can open the Database tool window.
In the Database pane, we can create a new connection or Data Source by using the context menu or the toolbar button. We need to specify the JDBC database driver that will be used to connect to our database. For MySQL, we can use the MySQL Connector driver available in the list of drivers. PhpStorm doesn't ship these drivers but we can download the correct JDBC driver from the Internet by clicking the Click here link.
Next, we need to enter the connection details. Alternatively, we can provide the connection string to the MySQL Database in the Database URL field, for example jdbc:mysql://localhost:8889/ or jdbc:mysql://localhost:8889/foodb to connect to the foodb database.
We can also specify the username and password for MySQL. By default, MAMP uses root both as the user name and the password.
When using UTF-8 or unicode characters in the username, password or database name, two additional parameters must be added to the connection string: characterEncoding and useUnicode. An example connection string would be jdbc:mysql://localhost:8889?characterEncoding=utf8&useUnicode=true. It may also be required to select a different JDBC driver from the list, com.mysql.jdbc.NonRegisteringDriver.
Having defined the data source, we can use the Test Connection button to verify the settings and make sure PhpStorm can connect to MySQL.
We can now create tables, run queries, update data and so on. See this blog post for more information.