Install nginx

Install Nginx on BREW

brew install nginx
Copy the code

View nginx installation details

brew info nginx
Copy the code

Start the nginx

Brew services start nginx restart nginx // brew services stop Nginx is stoppedCopy the code

At this point, you can access 127.0.0.1:8080 in your browser.

Install PHP, php-fpm

MAC comes with PHP and PHP-FPM, so use it directly.

Start the PHP – FPM

php-fpm
Copy the code

PHP – FPM: PHP – FPM: FPM: PHP – FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM: FPM

Nginx is associated with PHP and php-FPM

Modify/usr/local/etc/nginx/nginx. Conf, add PHP related configuration. You can also customize the root directory (optional).

Location ~ \.php${fastcgi_pass 127.0.0.1:9999; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }Copy the code

In the root directory, create a new index.php file

<! DOCTYPE html> <html> <body> <? php echo "Hello php!!! xxxx"; ? > </body> </html>Copy the code

Four, the test environment is ok

Restart php-fpm, nginx

php-fpm
brew services stop nginx
brew services start nginx
Copy the code

Go to 127.0.0.1:8080/index.php and if the page displays normally, the environment is ok.

5, Mac native PHP start phP-FPM problem resolved

If you run php-fpm on a terminal, the following error is reported:

ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
ERROR: failed to load configuration file '/private/etc/php-fpm.conf'
ERROR: FPM initialization failed
Copy the code

The configuration file cannot be opened. CD /private/etc shows that the php-fpm.conf file does not exist, but the php-fpm.conf.default file does. This file is the default configuration, so we can copy it, rename it php-fpm.conf, and change the configuration as needed.

cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
Copy the code

Error: php-fpm

ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
ERROR: failed to post process the configuration
ERROR: FPM initialization failed
Copy the code

Error message displayed, cannot open error log file. — /usr/local/var/log — /usr/local/var/log — /usr/local/var/log

/usr/local/var/log/php-fpm.log = /usr/local/var/log/php-fpm.log = /usr/local/var/log/php-fpm.log = /usr/local/var/log/php-fpm.

Error: php-fpm

NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
Copy the code

Sudo php-fpm:

ERROR: Unable to bind listening socket for address '127.0.0.1:9000': address already in use (48) ERROR: Unable to bind listening socket for address '127.0.0.1:9000': address already in use (48) FPM initialization failedCopy the code

Edit www.conf and change listen to 127.0.0.1:9999.

sudo vim /private/etc/php-fpm.d/www.conf
Copy the code

Finally:

Sudo PHP -fpm -dCopy the code

Six, reference

Juejin. Cn/post / 684490… www.jianshu.com/p/6232743f8… Thinkerou.com/post/nginx-…

Blog.csdn.net/weixin_3642… Blog.csdn.net/zrainload/a…