Setup LEMP (Nginx, MySQL, multiple PHP) on MacOS. In the end, you’ll have a robust, clean and fast local web development environment on Mac’s M chip or Intel
Verified It’s working on MacOS Soloma
Software needs to install:
Xcode, Homebrew (required)
Multiple PHP version (required)
Xdebug (Optional - But highly recommend)
Nginx & SSL (Required)
MySQL (Optional)
Elasticsearch (Optional - But required for Magento 2)
Mailhog (Optional)
DNSMASQ (Optional)
Setup
Xcode, Homebrew
Before starting you need a few tools installed to take the stress out of the setup process You will be using the terminal a lot of coming up (I like WezTerm)
Multiple PHP Version
Some PHP version deprecated on the default homebrew. Use tab shivammathur/php
By default, all PHP version are using port 9000. We need to change the port for each PHP version to avoid conflict. Path file: {bash} $(brew --prefix)/etc/<php_version>/php-fpm.d/www.conf
If you want to change configure php from path {bash} $(brew --prefix)/etc/<php_version>/php.ini{bash} `
P/S: After you adjust configure PHP, You must restart php-fpm Once you are ready, starting up php-fpm for each version
Check that you have a configuration correctly
Alias multiple PHP Version
Switch between multiple PHP Version
Xdebug
P/s: PHP 7.4 only support xdebug <= 3.1.6. You can check it on xdebug. To install, you must install specifically xdebug version
Note:pecl no valiable: The root was caused by SSL certificates is invalid.. To install, we need to download & install package offline. View on StackOverflow
Setup Xdebug for PHP
Nginx
Reload nginx to apply the new config
Go to http://localhost to see the result (if the port is different 80, it must be http://localhost:port) Check the PHP code can work on nginx
SSL
Install mkcert
Auto redirect HTTPS
MySQL
PHPMyadmin
Go to https://localhost/phpmyadmin Or you can use another DB GUI such as Table Plus, DBeaver, Sequel Ace
Mailhog
Now, you can access MailHog at http://localhost:8025. Send a test email and check MailHog
Next, update each php.ini file with the following, if you have multiple versions of PHP, and then restart php-fpm. Note, test@localhost should be used but will be overridden by any PHP scripts that run
ElasticSearch (Need to install Magento 2)
From Magento Version ≥ 2.4, It has changed MySQL search to Elasticsearch.
Install Elasticsearch & OpenJDK
Symlink OpenJDK so the system Java wrappers can find it. This information is also displayed as a Homebrew “caveat” after installing OpenJDK.
Run & Test Elasticsearch
DNSMASQ
To save yourself the fuss of editing your hosts file constantly you can use dnsmasq
Start or restart “dnsmasq” (Need to sudo)
unable to install elasitcsearch: Change “plist_options :manual => “elasticsearch” to “@plist_manual = “elasticsearch” on /opt/homebrew/Library/Taps/elastic/homebrew-tap/Formula/elasticsearch-full.rb:68
elasticsearch fails to start: add **xpack.ml.enabled: false** to /opt/homebrew/etc/elasticsearch/elasticsearch.yml
Confirm “dnsmasq” is working with a ping TLDs, one at a time