On October 8, 2019, Apple officially released the next generation of macOS, version Catalina (11.15).

MacOS Catalina comes preloaded with common scripting languages such as Ruby (2.6.3), PHP (7.3.9), Perl (5.18.4), Python (2.7.16), and Apache (2.4.41) Web server.

Note that ZSH has replaced bash as the default shell in new versions of the operating system. For those who need to customize ZSH, check out minority’s “Oh My ZSH” guide to getting macOS Catalina’s Shell on your Mac ahead of time. This article will not be repeated.

Here is how TO install my MNMP (Macos-nginx-mysql-php).

This tutorial uses three things instead:

  • ITerm2 is used instead of the system’s own command-line terminal
  • Nginx is used instead of Apache
  • Use self-installed PHP7.4 instead of the system’s own PHP7.3.9

Install iTerm2

ITerm2 is recommended to replace the default command line terminal. After the download is decompressed, drag iTerm2 directly into the “Applications” directory.

Install PhpStorm

JetBrains PhpStorm is recommended as an integration development tool.

Install Xcode

Xcode is apple’s developer suite of tools and libraries. Install the latest version of Xcode (9.0) through the AppStore. We generally don’t use Xcode to develop back-end projects. This step is necessary, however, because Xcode comes with the installation of necessary software such as Git.

Install Command Line Tools for Xcode

This step will help you install many common Unix-based tools. The Xcode command-line tool includes the GCC compiler as part of Xcode. Run the following command on the CLI to install:

Xcode -select --install xcode Command Line ToolsCopy the code

When Xcode and Xcode Command Line Tools are installed, you need to start Xcode, click Agree to accept the license agreement, and then close Xcode. This step is also necessary, otherwise Xcode contains a set of development tools will not be available.

Install Homebrew

Homebrew is the indispensable suite manager for macOS, used to install, upgrade, and uninstall commonly used software. Run the following command on the CLI to install:

The/usr/bin/ruby - e "$(curl - fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # system used to own ruby installation HomebrewCopy the code

The git remote repository of Homebrew can be changed to the open source software image of University of Science and Technology of China.

The brew - CD "$(repo)" git remote set - origin url https://mirrors.ustc.edu.cn/brew.git # replace brew. Git: cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # replace homebrew - core. Git: Echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' > > ~ /. ZSHRC # replace Homebrew Bottles source: source ~/.zshrcCopy the code

Installing PHP 7.4

Install PHP7.4.* instead of PHP7.3:

brew install php
Copy the code

Start PHP service:

brew services start php
Copy the code

Replace phP-fpm with PHP:

echo 'export PATH="/usr/local/opt/php/sbin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Copy the code

View version information:

php -v
php-fpm -v
Copy the code

MySQL installation

MySQL 8.0 is recommended as the database server:

brew install mysql
Copy the code

Of course, you can also install PostgreSQL or MariaDB.

MySQL > install MySQL

brew services start mysql
Copy the code

Enter MySQL server:

mysql -u root -p
Copy the code

Set the root password and security level.

mysql_secure_installation
Copy the code

Just follow the step-by-step instructions.

Install Redis

Install redis server:

brew install redis
Copy the code

When the installation is complete, start Redis:

brew services start redis
Copy the code

Using the Redis client:

redis-cli
Copy the code

Install nginx

Here we choose Nginx instead of Apache as our Web server:

brew install nginx
Copy the code

Start nginx service:

brew services start nginx
Copy the code

View installed Brew Services:

brew services list
Copy the code

Configure the nginx.conf file

Run the following command to view the location of the nginx.conf file:

nginx -h
Copy the code

Output:

Nginx version: nginx/1.17.3 Usage: nginx [-? HvVtTq] [-S signal] [-c filename] [-p prefix] [-g directives] Options: -? ,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: Stop, quit, reopen, reload the -p prefix: set the prefix path (default: / usr/local/Cellar/nginx / 1.17.3 _1 /) - c filename: set configuration file (default: /usr/local/etc/nginx/nginx.conf) -g directives : set global directives out of configuration fileCopy the code

Open the configuration file:

vi /usr/local/etc/nginx/nginx.conf
Copy the code

At the end of the file you can see:

include servers/*;
Copy the code

It contains all the files from the Servers directory in the same directory, so we can create configuration information for the development project in the Servers file:

cd /usr/local/etc/nginx/servers/
vi test.conf
Copy the code

Write the following configuration information to the test.conf file:

server { listen 8099; server_name localhost; root /home/www/php-project; rewrite . /index.php; location / { index index.php index.html index.htm; autoindex on; } #proxy the php scripts to php-fpm location ~ \.php$ { include /usr/local/etc/nginx/fastcgi.conf; fastcgi_intercept_errors on; Fastcgi_pass 127.0.0.1:9000; }}Copy the code

In the /home/www/php-project directory above, we create an index. PHP file:

vim /home/www/php-project/index.php
Copy the code

Write content:

<? php phpinfo();Copy the code

Restart the nginx:

brew services restart nginx
Copy the code

Open a browser and visit http://localhost:8099 for information about PHP configuration.

Install the Composer

Composer is a PHP tool for managing dependency relationships. You can declare dependent external libraries in your own projects, and Composer will install these dependent libraries for you.

Install and replace images:

curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer composer config -g Repo. Packagist composer https://mirrors.aliyun.com/composer/ # instead the domestic source of ali cloudCopy the code

Install PHP extensions

For example, the phP-Redis extension can be installed by downloading the source package or pecl install:

Wget https://pecl.php.net/get/redis-5.1.0.tgz # download the source code package tar - ZXVF redis - 5.1.0. TGZ # extract CD redis - 5.1.0 phpize # # into the directory /configure # configure # configure # make # install # configure # configure # configureCopy the code

After installing the extension, we need to modify the php.ini file and restart the PHP service as a final step:

Vi/usr/local/etc/PHP / 7.4 / PHP ini additional extension = # redis. So the brew services restart PHP # restart PHP service PHP -m | grep redis # Check whether the installation is successfulCopy the code

Or install using PECL:

pecl install redis
Copy the code

For details, see phpredis Install

Buy me a cup of coffee 🙂