Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ajvillegas/05a0bc2bcb782c1db52dc15e9b4a31f6 to your computer and use it in GitHub Desktop.

Select an option

Save ajvillegas/05a0bc2bcb782c1db52dc15e9b4a31f6 to your computer and use it in GitHub Desktop.
Native PHP development / MAMP stack on Apple silicon M1

Tutorial: Installing the MAMP stack (php, apache & mysql) on Apple Silicon ARM (native)

In this tutorial, we'll build the the nescessary packages for ARM via homebrew. After that we'll configure apache2 for using virtual hosts. The native php is ofcourse way faster, see the results of this benchmark below.

Installing homebrew

cd ~
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
sudo mv homebrew /opt/homebrew

This way homebrew will be installed to the /opt/homebrew folder. We can then initiate homebrew by cd to that directory and run brew in the bin folder.

cd /opt/homebrew/bin
./brew update

If not installed already, the system will ask to install the command-line tools for developers for you. Go ahead.

Now add the homebrew/bin directory to your path by editing/creating a .zshrc file in your home directory.

nano ~/.zshrc
export PATH="/opt/homebrew/bin:$PATH"

Build the packages

brew install -s mysql php httpd

This might take some time (30mins) or so. When everything is done it will list some next steps like adding the php module to apache.

Configuration

Make life a bit easier by symlinking the config directories to a rememberable path:

mkdir ~/MAMP
mkdir ~/MAMP/www
ln -s /opt/homebrew/etc/httpd ~/MAMP/httpd
ln -s /opt/homebrew/etc/php/7.4 ~/MAMP/php

Now, let's add some scripts to this directory

nano ~/MAMP/start.sh

start.sh:

#!/bin/zsh

brew services start mysql
brew services start php
brew services start httpd

stop.sh:

#!/bin/zsh

brew services stop mysql
brew services stop php
brew services stop httpd

restart.sh:

#!/bin/zsh

./stop.sh

sleep 4

./start.sh

Make 'em writable:

chmod +x ~/MAMP/start.sh
chmod +x ~/MAMP/stop.sh
chmod +x ~/MAMP/restart.sh

Oke, lets configure apache/httpd for usage with php and enable mod_rewrite along the way:

nano ~/MAMP/httpd/httpd.conf

Uncomment:

# LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

Change the DocumentRoot:

DocumentRoot "/Users/{username}/MAMP/www"
<Directory "/Users/{username}/MAMP/www">

And add the following to the bottom:


LoadModule php7_module /opt/homebrew/opt/php/lib/httpd/modules/libphp7.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Include /opt/homebrew/etc/httpd/vhosts/*.conf

Now create a directory named vhosts

mkdir ~/MAMP/httpd/vhosts

Addding a website / virtual host

mkdir /Users/{username}/MAMP/www/dev.example.com
mkdir /Users/{username}/MAMP/www/dev.example.com/public_html
mkdir /Users/{username}/MAMP/www/dev.example.com/logs
nano ~/MAMP/httpd/vhosts/dev.example.com.conf

Add:

<VirtualHost *:8080>
    DocumentRoot "/Users/{username}/MAMP/www/dev.example.com/public_html"
    ServerName dev.example.com
    ErrorLog "/Users/{username}/MAMP/www/dev.example.com/logs/error.log"
    CustomLog "/Users/{username}/MAMP/www/dev.example.com/logs/custom.log" common
</VirtualHost>

<Directory /Users/{username}/MAMP/www/dev.example.com/public_html>
        Options FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>

Add dev.example.com to your hosts file

echo '127.0.0.1 dev.example.com' | sudo tee -a /etc/hosts

Now restart:

~/MAMP/restart.sh

Vist http://dev.example.com:8080

Hits

TEST NAME SECONDS OP/SEC OP/SEC/MHz MEMORY
01_math 5.389 sec 185.56 kOp/s 0.00 uOps/MHz 2 Mb
02_string_concat 0.000 sec 1.08 TOp/s 0.00 uOps/MHz 2 Mb
03_1_string_number_concat 5.017 sec 996.62 kOp/s 0.00 uOps/MHz 2 Mb
03_2_string_number_format 4.181 sec 1.20 MOp/s 0.00 uOps/MHz 2 Mb
04_string_simple_functions 5.701 sec 228.01 kOp/s 0.00 uOps/MHz 2 Mb
05_string_multibyte 2.603 sec 49.93 kOp/s 0.00 uOps/MHz 2 Mb
06_string_manipulation 14.105 sec 92.17 kOp/s 0.00 uOps/MHz 2 Mb
07_regex 11.417 sec 113.87 kOp/s 0.00 uOps/MHz 2 Mb
08_1_hashing 10.753 sec 120.90 kOp/s 0.00 uOps/MHz 2 Mb
08_2_crypt 60.466 sec 165.38 Op/s 0.00 uOps/MHz 2 Mb
09_json_encode 9.298 sec 139.81 kOp/s 0.00 uOps/MHz 2 Mb
10_json_decode 9.851 sec 131.96 kOp/s 0.00 uOps/MHz 2 Mb
11_serialize 7.082 sec 183.55 kOp/s 0.00 uOps/MHz 2 Mb
12_unserialize 5.484 sec 237.04 kOp/s 0.00 uOps/MHz 2 Mb
13_array_fill 0.000 sec 0.00 uOp/s 0.00 uOps/MHz 2 Mb
14_array_range 0.001 sec 0.00 uOp/s 0.00 uOps/MHz 2 Mb
14_array_unset 0.001 sec 0.00 uOp/s 0.00 uOps/MHz 2 Mb
15_loops 2.746 sec 72.83 MOp/s 0.00 uOps/MHz 2 Mb
16_loop_ifelse 2.200 sec 22.73 MOp/s 0.00 uOps/MHz 2 Mb
17_loop_ternary 4.697 sec 10.64 MOp/s 0.00 uOps/MHz 2 Mb
18_1_loop_defined_access 1.408 sec 14.20 MOp/s 0.00 uOps/MHz 2 Mb
18_2_loop_undefined_access 10.693 sec 1.87 MOp/s 0.00 uOps/MHz 2 Mb
19_type_functions 2.496 sec 1.20 MOp/s 0.00 uOps/MHz 2 Mb
20_type_conversion 2.496 sec 1.20 MOp/s 0.00 uOps/MHz 2 Mb
24_xmlrpc_encode 9.975 sec 20.05 kOp/s 0.00 uOps/MHz 2 Mb
25_xmlrpc_decode 3.592 sec 8.35 kOp/s 0.00 uOps/MHz 2 Mb
Total time: 191.654 sec 1.96 MOp/s 0.00 uOps/MHz
TEST NAME SECONDS OP/SEC OP/SEC/MHz MEMORY
01_math 1.101 sec 908.17 kOp/s 0.00 uOps/MHz 2 Mb
02_string_concat 0.000 sec 3.59 TOp/s 0.00 uOps/MHz 2 Mb
03_1_string_number_concat 1.436 sec 3.48 MOp/s 0.00 uOps/MHz 2 Mb
03_2_string_number_format 1.321 sec 3.79 MOp/s 0.00 uOps/MHz 2 Mb
04_string_simple_functions 1.980 sec 656.67 kOp/s 0.00 uOps/MHz 2 Mb
05_string_multibyte 0.808 sec 160.83 kOp/s 0.00 uOps/MHz 2 Mb
06_string_manipulation 3.738 sec 347.82 kOp/s 0.00 uOps/MHz 2 Mb
07_regex 2.398 sec 542.20 kOp/s 0.00 uOps/MHz 2 Mb
08_1_hashing 2.660 sec 488.77 kOp/s 0.00 uOps/MHz 2 Mb
08_2_crypt 10.045 sec 995.54 Op/s 0.00 uOps/MHz 2 Mb
09_json_encode 1.601 sec 811.83 kOp/s 0.00 uOps/MHz 2 Mb
10_json_decode 2.650 sec 490.66 kOp/s 0.00 uOps/MHz 2 Mb
11_serialize 1.044 sec 1.24 MOp/s 0.00 uOps/MHz 2 Mb
12_unserialize 1.531 sec 849.39 kOp/s 0.00 uOps/MHz 2 Mb
13_array_fill 0.000 sec 0.00 uOp/s 0.00 uOps/MHz 2 Mb
14_array_range 0.000 sec 0.00 uOp/s 0.00 uOps/MHz 2 Mb
14_array_unset 0.000 sec 0.00 uOp/s 0.00 uOps/MHz 2 Mb
15_loops 1.253 sec 159.63 MOp/s 0.00 uOps/MHz 2 Mb
16_loop_ifelse 1.011 sec 49.47 MOp/s 0.00 uOps/MHz 2 Mb
17_loop_ternary 1.432 sec 34.91 MOp/s 0.00 uOps/MHz 2 Mb
18_1_loop_defined_access 0.352 sec 56.76 MOp/s 0.00 uOps/MHz 2 Mb
18_2_loop_undefined_access 3.124 sec 6.40 MOp/s 0.00 uOps/MHz 2 Mb
19_type_functions 0.629 sec 4.77 MOp/s 0.00 uOps/MHz 2 Mb
20_type_conversion 0.628 sec 4.78 MOp/s 0.00 uOps/MHz 2 Mb
24_xmlrpc_encode 1.702 sec 117.54 kOp/s 0.00 uOps/MHz 2 Mb
25_xmlrpc_decode 1.303 sec 23.02 kOp/s 0.00 uOps/MHz 2 Mb
Total time: *43.745 sec 8.58 MOp/s 0.00 uOps/MHz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment