A brief tutorial on how to create a new host in MAMP PRO. MAMP automatically gives you both the paid and free version. Use the grey folder and icon for the free version, if you want you can move the Pro version to the trash. When prompted, uncheck the box that asks if you’d like to check for MAMP PRO every time you open it, and click “Launch MAMP” instead of “Launch MAMP PRO.”.
Category: Freebies - Web Dev Tools & Graphic Design Freebies, Advanced Web Design Tutorials & CMS Tutorials
Utilizing a local development environment is crucial for web developers, but it's not well documented. This guide to setting up MAMP will show you how to create your own PHP development server & how to use MAMP efficiently once you're all setup.
This tutorial will walk you through setting up MAMP so you can take advantage of all the perks of having your own local PHP development server. While this workflow is guided towards folks using a Mac, the steps of the process are almost identical on other platforms. Having your own local development environment allows you to quickly plug through building a website or application without needing to consider all implications of having an accessible product online. We'll show you how to get started with the free version of MAMP, but it should be noted that the Pro version is pretty inexpensive and streamlines your workflow quite a bit. With that said, let's get started showing you how to use MAMP so you can get coding and testing websites like a boss!
Setting Up Mamp - Download & Install
The first step to setting up MAMP will be to download the latest version of MAMP (which is available at www.mamp.info). The only other application you'll need will be a simple text editor to manage the code. Text Wrangler, Sublime, TextMate, Jedit, or Coda would all do the job well and you could always just use Terminal if you're really hardcore. Once you've downloaded MAMP, click to install (you know the drill). After you've installed, take a quick look at the app in your
Applications
folder. You'll notice that the app is in a folder structure and for future reference it's important to know that the htdocs
folder is the default home of your local development environment. The index.php
file is what you'll see as soon as you start it up.What Exactly is a Local Development Environment?
What we're basically doing is creating our own 'internet' on your computer. The primary advantage that we're utilizing is the privacy and efficiency that this allows. By having your own 'internet' running (also known as a local server or local development environment), you don't need to worry about clients monitoring your revisions or even worse - breaking some part of a live website. The concept of a local testing server sounds complex, but really it just gives coders exactly what they need - Practice and privacy.
While the Mac version is called MAMP, the same functionality is offered on other platforms as 'WAMP' or 'LAMP'. you may notice a theme in the naming of these apps. In fact, the name tells you exactly what it is - Mac Apache Mysql PHP. Those last three are obviously the important ones here and if you don't know, those are the basic building blocks of a large majority of websites on the internet. Simply - Apache is your testing server, MYSQL is your database, and PHP is the coding language (which is since most major CMS's run on a PHP backbone - Wordpress, Joomla, Drupal, CodeIgnitor etc.). While that's obviously a simplistic explanation of how a PHP development server works, it does cover the functional aspects and brings us to an inherent problem you may be asking yourself.
IMPORTANT: When running the MAMP application, you are broadcasting a network. If you are connected to the internet while you're broadcasting, you're leaving your door WIDE open to hacker types.
Securing Your PHP Development Server
All MAMP applications come setup with the same username and password (hint: They're both 'root'). While you ideally would never have your Wifi turned on while you're running MAMP, it's best to assume that might accidentally happen. As you can probably imagine, 'broadcasting' your network to the public with a default user and password that would be any dev's first guess would be a bad idea. So the final step in our tutorial is addressing that problem.
Go ahead and turn off your wifi and start MAMP. Then go to your
/Applications/Utilities
folder and open up Terminal. If you're not familiar with Terminal, don't be scared - just take your time and make sure you input this one part correctly. You're basically inputting where your app is located on your computer, then setting your new password in that last chunk. From your root, you'll need to type..Once you hit enter, you'll be prompted for the current password (which is 'root'). As long as you don't get an error, you've successfully reset your root users password. The next file you'll need to edit is 'config.inc.php' that can be located at /MAMP/bin/phpmyadmin/config.inc.php. Open that file with your trusty text editor and look for the line that reads
$cfg['Servers'][$i]['password'] = 'root';
. It should be near the 86th line down. Change that 'root' to your new password and save.The last few files that you'll need to update are located in /MAMP/bin/. The file names are checkMysql.sh, quickCheckMysqlUpgrade.sh, repairMysql.sh, stopMysql.sh, and upgradeMysql.sh and it should look awfully similar to the image that's attached to the right. These files (as you can probably gather) handle the stopping, starting, etc. of MAMP and that's why they're important to edit. If you don't get around to fixing these, you can have a network running that you're not even aware of.. Which obviously isn't good (ps. I've also heard of some setups that require you do the same change to 'bin/mamp/index'). Now each of these files will have a line that reads
-u root -p root
. This is simply a block stating 'Ok, this is the user and this is the password'. When replacing the 'root' password here, you do need to do one thing slightly different. When you replace the password, remove the space between '-p' and your new password (it should read -pNEWPASSWORD). Once you've edited these files, you have properly reset your root password and you're officially done setting up MAMP. Now, let's crank it up!How to Use MAMP - Start it Up!!
You should have everything running now, so let's cover how to use MAMP itself. First - keep in mind that you still want to turn your network connection off when you're running MAMP. Resetting the password will allow you to remove your 'low-hanging-fruit' status, but you still don't want to broadcast publicly. In order to keep your URLs clean, you'll want to remove the ':8888' from your URL. To do that just open up MAMP preferences and click 'Set to default Apache and Mysql ports'(see picture). This allows you to tailor your URL structure like you would on a live website. You'll also notice that you can change your document root under the 'Apache' tab (otherwise it defaults to /MAMP/htdocs as we mentioned earlier.
Every setup is a little unique and if you'd like a video walk-through, check out the step by step process courtesy of Jono Young (@chsweb) posted below. Once everything is setup properly, you'll have a functional php development server for you to practice all your coding awesomeness on.. HTML, Wordpress, Drupal, Joomla, whatever you want. Now pat yourself on the back and getting working on that web project.
If you have any tips on setting up MAMP, please drop them to us on your favorite social network. If you found this tutorial helpful, please feel free to share some love with the buttons below. As always - Thanks for stopping by.
Video
Enable Javascript for Videos
Written By: Matthew Haeck - Lead designer and resident full stack web developer at Haeck Design, Matthew spends a majority of his time creating beautiful logos, websites, print design, & staying up to date on all the tricks of the web development trade. (About Matthew Haeck)
- Content distribution is an overlooked aspect of blogging, so we created this quick guide to mastering RSS. By identifying leading RSS feed formats, top RSS submission sites, and a few of the best RSS reader apps, we can make your audience even larger.
- Apple Security Tutorial - Secure Your Mac from HackersIn the old platform debates, Apple security was always featured as a primary selling point. The truth is technology has caught up to the giant and frankly - a lot of people are simply not using all the existing Mac OS X security tricks of the trade.
- Do you have Facebook fanpage envy? Get over it with this simple 7 step tutorial to build your own custom Facebook fanpage.
- Using Dropbox for web development is an easy way to share files across multiple local servers. This tutorial shows you how to setup a Dropbox database sync so you can trigger your MySQL database sync in the push of a button.
- Optimizing SEO can be a complicated task. Free site ranking utilities provide experienced web developers and newcomers alike, a helpful way to track progress and identify potential shortfalls.
Compile your own PHP version from source and install it on MAMP PRO on macOS. It's possible -- despite what MAMP's developers want you to believe.
I wanted to test my software against PHP 7.3 on macOS instead of just my Linux machines and / or Docker containers. According to MAMP's support 'You cannot compile your own entire versions of PHP in MAMP PRO'. This is of course a ridiculous lie; they do it themselves so surely I can! This article walks you step by step to my process of adding PHP 7.3.0 to MAMP 5.2 on this lazy Saturday afternoon.
Caveats
'It's possible' does not mean 'it's easy'. This procedure is not for the faint of heart, if you don't have experience building stuff from source (and troubleshoot cryptic compile error message) or if you're in a mad dash to deliver software. You will stumble. You will fall. You will curse at your computer. You will be frustrated. You will be searching online cryptic error messages only to find a million pages from five years ago which do not apply. YOU WILL SUFFER. Is it worth it? Hell yeah. That's how you get to learn stuff. If you want quick results just wait a few months for MAMP PRO to include a new version of PHP. It will save you time, money and frustration (and keep you blissfully unaware of the gruesome process of compiling software from scratch). Proceed at your own risk and peril.
Appsolute, the makers of MAMP, make it unnecessarily complicated – read: impossible – to compile your own Apache modules by not shipping the build headers for Apache. Therefore we are only building PHP CLI and CGI/FastCGI, not as an Apache module. This is not a big deal, though. The recommended way to run PHP 5.3 and later is through FastCGI. Just select the 'Individual PHP version for every host (CGI mode)' option. FastCGI is also the only way PHP works on NginX.
Likewise, they do not ship build headers for anything except PHP itself – definitely not for any of the build dependencies. We are going to use Homebrew to install the required PHP build dependencies. The actual caveat is that you can't just pluck the compiled PHP from your computer and install it on your mate's. Not unless you also install the dependencies outlined below with Homebrew.
I compiled most PHP modules but I left some out because I don't use them and don't have the time to troubleshoot their build dependencies. This should not be an issue for most people.
Finally, you will need to edit your PHP version's php.ini template file and manually enable additional PHP extensions. Unlike MAMP, I try to build most of the extensions as 'shared', i.e. you have to load them through php.ini. I sometimes need to disable stuff to see if my code fails gracefully.
Prerequisites
I have two Macs at my disposal. One Mac Mini which was upgraded from macOS Sierra to High Sierra to Mojave; and a MacBook Pro which was freshly installed with Mojave. I used the former to come up with the instructions and the second, 'virgin' machine to verify that everything works. If you get compilation errors check what you have installed in Homebrew and where you have linked it to. This is the source of all problems and please don't ask me to help you; just like you, I search the error message I am getting and plow through the results until I find something which seems like a promising solution. OK. Let's get started, then!
Before you begin your quest to a custom PHP version in MAMP you need a sane build environment with all the PHP dependencies installed.
First, install XCode from the App Store. This is Apple's all-in-one development package which includes system headers and the all important build toolchain (C compiler, automake, autoconf and so on and so forth).
Now open XCode and accept the license. It will take a while. This is the part where XCode installs the software and header files we need to build PHP. If you forget to do that you will get compilation errors when building PHP. After it's done installing you can quit XCode. We don't need the actual application running.
Apple has made it unnecessarily complicated to build software from the command line by tucking away all of the libraries and headers in a non-standard folder. For macOS Mojave you need to run this from a Terminal
This puts everything into the standard folders, e.g. /usr/include. Please check that you have the /usr/include folder after running this command. If you don't, PHP compilation WILL fail and you'll spend two hours trying to figure out what the heck is going on. Been there. Obviously, if you do not have Mojave you need to replace the 10.14 in the command above with your macOS version number.
Next up, install Homebrew. If you're not absolutely new to macOS you already know about it. For everyone else, Homebrew is the de facto package manager for macOS. It allows us to install and upgrade libraries and tools in a simple and sensible manner. Follow the instructions on the link above to install Homebrew. At the time of this writing (December 2018) you need to open Terminal and enter:
Synfig text animation. Now we will have to install the dependencies for building PHP and a bunch of its extensions. Open a Terminal and enter the following:
Please note that I have only tried compiling PHP 7.1, 7.2 and 7.3. If you are compiling an older or newer version of PHP you may have to add more build dependencies.
MAMP's directory structure
Let's pause for a second and understand what we are doing. MAMP stores its files in several different places. These locations are not documented but they are not that hard to reverse engineer.
Every PHP version is stored in /Applications/MAMP/bin/php/phpX.Y.Z where X.Y.Z is your PHP version. Major caveat, X, Y and Z must all be integers without anything else. This means you cannot install alphas, betas or RC versions unless you lie. For example, if you were to install PHP 7.3.0RC6 you'd be installing it as php7.3.0. Anyway. This folder contains a mostly standard PHP installation folder layout. The exceptions are two directories.
The /Applications/MAMP/bin/php/phpX.Y.Z/conf folder contains the pear.conf file (which we don't use), the default php.ini file (which is not used) and the default php.ini.temp MAMP-specific template file (which is NOT used). This folder must exist but its contents are not used during MAMP's regular operation, they are only used when MAMP is installing a new PHP version.
The /Applications/MAMP/bin/php/phpX.Y.Z/modules folder is where MAMP expects to find the PHP Apache module file (libphp7.so). Major caveat! If the file does not exist MAMP will not show this PHP version in its interface. But we can't build that file. So.. are we screwed? Well, no. We can just create a zero byte file and MAMP will work happily.
There's another important location: /Users/your_user/Library/Application Support/appsolute/MAMP PRO/templates/phpX.Y.Z.ini.temp. This is the MAMP-specific php.ini template file you edit through MAMP's File, Edit Template, PHP (php.ini) submenu. This file is parsed when MAMP is starting the servers, creating the real php.ini file in /Library/Application Support/appsolute/MAMP PRO/conf/phpX.Y.Z.ini. Note that the REAL file is in /Library, NOT /Users/your_user/Library.
Remember the location of the real, generated php.ini file when you want to call PHP from the command line. If you do not specify this configuration file with the -c switch then the default /Applications/MAMP/bin/php/phpX.Y.Z/conf/php.ini file will be used instead which is NOT the one you configure through MAMP PRO's interface! That is, call PHP CLI as:
Compile your own PHP version
Go ahead and download the PHP version you want from the official PHP site. I downloaded and extracted PHP 7.3.0 inside ~/php, a subfolder I created for this reason.
You can blindly use the following code in Terminal changing just the first line. Replace 7.3.0 with your PHP version.
Tip: The make commands have a -j 8 switch. This means 'run up to 8 tasks in parallel'. That's because I have a Mac Mini with a 4-core Intel Core i7 processor with Hyperthreading. This means each core can run two threads at the same time, thus 4 cores x 2 threads per core = 8 threads simultaneously. If you have a dual-core processor, as in with most MacBook Pro and Air machines, set this to -j 4. Note that this utilises your processor optimally, reduces the compilation time but will make your Mac run hot.
At this point you need to stop MAMP's servers, quit MAMP PRO completely and then start it again. Now go to the PHP tab. Here's your new PHP version!
Before you get all too excited you should go to File, Edit Template, PHP (php.ini) and select your PHP version. You need to edit the extension=.. lines. You can find the extensions you have compiled under the /Applications/MAMP/bin/php/php7.3.0/lib/php/20180731 folder. Remember that 7.3.0 and 20180731 in that path depend on which PHP version you have compiled. You are interested only in the .so files.
Mamp Pro Alternative
My section of extension loads looks like this:
Mamp Pro Tutorials
Note that all of the extensions controlled by MAMP are actually not built since they are either not part of the PHP distribution (they are installed through PECL) or I didn't bother building them. You will see how to build them in the next section.
Compiling additional PHP extensions
You can do that by typing the following in Terminal (change the first line to reflect your PHP version):
Mamp Download
Now on the same Terminal session you can install PHP extensions using
pecl install
. For example:or
For some extensions you need to pass an explicit version number. For example, for the all important XDebug debugging extension you need to run:
Some extensions may need prerequisites to be installed. For example:
At the time of this writing not all PHP extensions are compatible with PHP 7.3. I was unable to compile memcached, apc, apcu and ssh2. That's what you get for trying the bleeding edge. This is also my response to the people asking 'why are you not using PHP 7.3 in production yet?'. It's simply not ready if you rely on certain extensions. That's why there's an overlap of actively maintained releases, to give time to developers to adapt their extensions and PHP software developers to test before migrating to an infrastructure of unknown compatibility status. That's the whole point of self-compiling the very latest PHP version: get our software ready.