Home>Article>Backend Development> What should I do if mac nginx does not support php?
mac nginx does not support php because PHP is not configured. The solution is: 1. Use homebrew to install nginx; 2. Set administrator rights for nginx; 3. Execute the command "brew tap josegonzalez/homebrew-php" Just install PHP.
The operating environment of this article: macOS10.15 system, PHP5.6 version, MacBook Air 2019 computer
mac nginx What should I do if php is not supported?
Install Nginx and configure PHP on Mac
Before, I used Apache and PHP to work together
Because PHP is self-taught, many I don’t understand (I haven’t read much about TP, and it’s useless)
I recently wanted to use nginx and php to write something together
Because I have already installed it on my computer, and I encountered some problems during the process , while I still have some impressions, record it now. If you use nginx and php to develop in the future, you can refer to it
1. Use yum to install the software on Linux. If you are on Mac, you will see a homebrew
2. Then we use homebrew to install nginx
The installation is completed with one command:
brew install nginx
Then we configure the permissions
1》Set the administrator for nginx Permissions: If administrator permissions are not set, port 80 cannot be monitored
#这里的目录根据你实际安装的目录来填写,默认是这个目录,不同的只是nginx的版本号而已 sudo chown root:wheel /usr/local/Cellar/nginx/1.10.1/bin/nginx sudo chmod u+s /usr/local/Cellar/nginx/1.10.1/bin/nginx
2》Add launchctl startup control
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
3》Run nginx
sudo nginx #打开 nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx nginx -t #测试配置是否有语法错误
3. Install PHP
Because brew does not have a php package by default, we first execute the following command
brew tap homebrew/dupes brew tap josegonzalez/homebrew-php
There are many versions of php and we can use brew search php to view
on my computer It is php5.6, but I used brew to install it. It will not affect the one that comes with mac, because it will be installed under /usr/local/Cellar
brew install php56
After the installation is completed, in order to make the system To use the version I just installed, you need to configure it
sudo vim ~/.bash_profile #在这个文件最后添加下列语句: export PATH="$(brew --prefix php56)/bin:$PATH" #保存文件后,source下这个文件,使刚刚添加的环境变量生效 source ~/.bash_profile
After completion, you can use php -v in the terminal to view the version, which is the version I just installed
Join launchctl startup control
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist
The path of the php configuration file is as follows
/usr/local/etc/php/5.6/php.ini /usr/local/etc/php/5.6/php-fpm.conf
After I completed this, I went to test it directly using php
But the nginx service was normal, but php just did not display
The reason is that I am too impatient, nginx has not set up PHP yet
nginx configuration file path is as follows
/usr/local/etc/nginx/nginx.conf
After opening it, find the following piece
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}
Uncomment, it still doesn’t work after restarting nginx. I found the reason, it’s because [/scripts$fastcgi_script_name;] this sentence should be [$document_root$fastcgi_script_name;]
Then restart nginx and you can access php
I remember that I encountered some minor problems when I started php-fpm, and the contents of the problems were displayed in the terminal
For example: [/private/etc/php-fpm.conf] This file does not exist. In fact, there is a file with the suffix [.default] in the same directory. We can copy this file and change it to php-fpm.conf.
If executed later, something may appear. The error_log path is wrong. The default is to log under [/usr/var], but the path cannot be found. There are two solutions.
1》It prompts that there is no folder, we will create it
2》Change the php-fpm.conf file we just copied and find a place similar to the following
[global] ; Pid file ; Note: the default prefix is /usr/var ; Default Value: none pid = /usr/local/var/php-fpm/run/php-fpm.pid ; Error log file ; If it's set to "syslog", log is sent to syslogd instead of being written ; in a local file. ; Note: the default prefix is /usr/var ; Default Value: log/php-fpm.log error_log = /usr/local/var/php-fpm/log/php-fpm.log
pid and error_log were both commented before. We can just change them to a convenient location.
If there are no other special problems now, nginx and php can work normally.
We can configure our own access domain name by modifying the nginx.conf and hosts files
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if mac nginx does not support php?. For more information, please follow other related articles on the PHP Chinese website!