MAMP

2018-09-26 — This manual is not maintained anymore.

Skip the free version and pay for MAMP Pro. It’s worth the money to easily setup sites with HTTPS.

Site management

Apache config

Add a unique entry for each site:

File: /Applications/MAMP/conf/apache/httpd.conf

# -----------------------------------------------
# GravDept:
# Custom virtual hosts
# -----------------------------------------------

<VirtualHost *>
    ServerName example.test
    DocumentRoot "/Users/brendan/work/projects/example/www"

    <Directory "/Users/brendan/work/projects/example/www">
        Options FollowSymLinks Indexes Multiviews
        AllowOverride All
    </Directory>
</VirtualHost>

<VirtualHost *>
    ServerName test.test
    DocumentRoot "/Users/brendan/work/projects/test/www"

    <Directory "/Users/brendan/work/projects/test/www">
        Options FollowSymLinks Indexes Multiviews
        AllowOverride All
    </Directory>
</VirtualHost>

Hosts config

Edit your Mac’s hosts file:

sudo nano /etc/hosts
# MAMP
127.0.0.1 example.test
127.0.0.1 test.test

Database management

Import / export

# Import database from file
/Applications/MAMP/Library/bin/mysql -u [DB_USER] -p [DB_NAME] < data.sql

# Export database to file
/Applications/MAMP/Library/bin/mysqldump -u [DB_USER] -p [DB_NAME] > data.sql

# Log into mysql
# Password: root
/Applications/MAMP/Library/bin/mysql -u root -p

# Run queries
create database learningLaravel;
show databases;

Reference

Assign existing user to imported database

In phpMyAdmin:

  1. Click Home icon.
  2. Click User accounts tab.
  3. Click Edit privileges link for the user.
  4. Click Database tab.
  5. Select the database from the multi-select input.
  6. Check all privileges.
  7. Click Go.

Assign global priveliges to a user

Sometimes importing a database requires global priveliges. I’m not sure why, but I don’t worry about it for a local environment.

In phpMyAdmin:

  1. Click Home icon.
  2. Click User accounts tab.
  3. Click Edit privileges link for the user.
  4. The Global tab is selected (default view).
  5. Check all privileges.
  6. Click Go.

Preferences

Ports

Apache port 80
Nginx port 80
MySQL port 3306

PHP

PHP version 5.6.37
PHP cache Off

MAMP only makes the two most recent PHP versions it bundles be selectable. To select an older version, rename the unused PHP versions with an underscore:

  1. Go to /Applications/MAMP/bin/php.
  2. Rename folders for unused PHP versions with an underscore.
  3. Example: change php7.1.12 to _php7.1.12 to disable it.

For broader coverage, keep only the last PHP 7.x and PHP 5.6.x versions active.

Web server

Web server Apache

Configuration

Apache config

# Edit this file:
# /Applications/MAMP/conf/apache/httpd.conf


# -----------------------------------------------
# GravDept:
# Enable GZIP
# -----------------------------------------------

<IfModule mod_deflate.c>
    # Compress HTML, CSS, JavaScript, Text, XML and fonts
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml

    # Remove browser bugs (only needed for really old browsers)
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    Header append Vary User-Agent
</IfModule>


# -----------------------------------------------
# GravDept:
# Custom virtual hosts
# -----------------------------------------------

# Add vhosts here

MySQL config

File: /Applications/MAMP/conf/my.cnf

phpMyAdmin config

Something broke related to the MySQL root user’s password, and this is necessary now:

File: /Applications/MAMP/bin/phpMyAdmin/config.inc.php

// Leave these alone:
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user']      = 'root';

// Make sure this is 'root':
$cfg['Servers'][$i]['password'] = 'root';

// Add this line:
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = false;

Otherwise you won’t be able to access phpMyAdmin.

PHP config

File: /Applications/MAMP/bin/php/php5.5.3/conf/php.ini

memory_limit = 128M

Note: you may need to raise to 256M if Magento returns white pages.

Error logs

/Applications/MAMP/logs/apache_error.log
/Applications/MAMP/logs/mysql_error_log.err
/Applications/MAMP/logs/php_error.log

Troubleshooting

  • Disable OPcache if PHP pages don’t refresh. Reference