Using Macports is easy to setup a MAMP environment with all the custom PHP extensions you may need.
This is what I did to have a dev environment, running on MacOS Catalina:
Install apache and php
❯ sudo port install php74 php74-xdebug php74-apache2handler php74-mysql php74-sqlite php74-mcrypt php74-mbstring php74-openssl
Activate mod_php
❯ cd /opt/local/lib/apache2/modules❯ sudo /opt/local/bin/apxs -a -e -n php7 mod_php74.so
Activate mod_rewrite
LoadModule rewrite_module lib/apache2/modules/mod_rewrite.so
Set a default php.ini
sudo cp /opt/local/etc/php74/php-development.ini /opt/local/etc/php74/php.ini
Change DirectoryIndex in /opt/local/etc/apache2/httpd.conf from:
DirectoryIndex index.html
To:
DirectoryIndex index.php index.html
Uncomment the vhosts file
Include etc/apache2/extra/httpd-vhosts.confInclude etc/apache2/extra/mod_php74.conf
Create a new vhost in /opt/local/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>ServerName agilistico.testServerAdmin webmaster@xilonen.lanDocumentRoot "/Users/ivan/PhpstormProjects/agilistico.com/public"<Directory "/Users/ivan/PhpstormProjects/agilistico.com/public">Options Indexes FollowSymLinksAllowOverride AllRequire all granted</Directory>ErrorLog "var/log/apache2/agilistico.test-error_log"CustomLog "var/log/apache2/agilistico.test-access_log" common</VirtualHost>
Restart Apache to reflect the config changes
❯ sudo apachectl restart
And finally add the host to /etc/hosts
❯ sudo echo '127.0.0.1 agilistico.test' > /etc/hosts
Now install MySQL (in my case I need 5.7 at the time, but by default network is off so I can install multiple versions)
❯ sudo port install mysql57-server mysql57❯ sudo /opt/local/lib/mysql57/bin/mysqld --initialize --user=_mysql❯ sudo chown -R _mysql:_mysql /opt/local/var/db/mysql57/❯ sudo chown -R _mysql:_mysql /opt/local/var/run/mysql57/❯ sudo chown -R _mysql:_mysql /opt/local/var/log/mysql57/
Add mysql_client path to the shell, in my case I’ve added the following to ~/.zshrc
export PATH=$PATH:/opt/local/lib/mysql57/bin
Create another mysql user, default root has no password:
❯ mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 24Server version: 5.7.29 Source distributionCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql >
Then in mysql console
CREATE USER 'ivan'@'%' IDENTIFIED BY '123456';GRANT ALL PRIVILEGES ON *.* TO 'ivan'@'%'WITH GRANT OPTION;CREATE USER 'ivan'@'localhost' IDENTIFIED BY '123456';GRANT ALL PRIVILEGES ON *.* TO 'ivan'@'localhost'WITH GRANT OPTION;flush privileges;
Make apache and mysql start at boot:
❯ sudo port load mysql57-server❯ sudo port load apache2