Home>Article>Backend Development> What should I do if mac nginx does not parse php?

What should I do if mac nginx does not parse php?

藏色散人
藏色散人 Original
2021-07-23 10:02:02 2536browse

The solution for mac nginx not parsing php: 1. cp a new file with the correct name; 2. Execute the command "php-fpm --fpm-config..."; 3. cp a file named www .conf file; 4. Kill the Solution process.

What should I do if mac nginx does not parse php?

The operating environment of this article: macOS10.15 system, PHP7.1 version, MacBook Air 2019 computer

mac nginx does not parse php what to do?

The pitfalls encountered by mac when deploying php under nginx

I was asked by someone to help them deploy a website, and then I wanted to debug it in the local nginx first. At first, when I opened the page, it showed 403. I had seen this before, and it was a permission issue with nginx. After changing the permissions, I found that when I accessed the PHP page, I downloaded it directly without parsing. I remembered that my computer might not have a PHP environment, so I downloaded PHP. Then still the same problem. In short, because I am not very familiar with PHP (I used software such as xampp before), it took me a while to get it done.

The first thing to understand is that nginx itself cannot handle PHP. It is just a web server. When the front-end requests PHP, nginx needs to send the interface to the PHP interpreter for processing, and then return the result to the front-end. Generally, nginx sends the request to the fastcgi management process for processing. For example, the configuration in nginx:

location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#这里原来不是$document_root,搞得我很蒙,还好网上查到改好了,不然会报file not found include fastcgi_params; }

So to start a fastcgi, php-fpm is used here. It is a php fastcgi manager and is only used for the php language (the old version of php needs to download php-fpm separately. The php-fpm I use has integrated this).

There are a lot of strange questions here.

  • First time running php-fpm

failed: /private/etc/php-fpm.conf file not found,

Solution: But there is a php-fpm.conf.default file in this directory, so cp a new file with the correct name

  • Run php-fpm for the second time

Failed: Cannot find /usr/var/log/php-fpm.log

Solution: There is no such directory at all. I changed it in the conf file but it has no effect. , I have no choice but to execute php-fpm through the following command (I will use this command to execute later)

php-fpm --fpm-config /private/etc/php-fpm.conf --prefix /usr/local/var
  • Run php-fpm for the third time

Failed: No pool defined. at least one pool section must be specified in config file

Solution: Go to the /etc/php-fpm.d/ directory and there is a file www.conf.default, cp a file named www.conf

  • Fourth Run php-fpm for the first time

Failed: The port is occupied

Solution: Kill this process

sudo lsof -i tcp:9000#Find the occupied port Process number of port 9000

kill -9 port#Kill!

  • Run php-fpm for the fifth time

## Success!

##Supplement:

There is a little difference when configuring on nginx. On the mac, php-fpm directly listens to the 9000 port, but on the server, it listens to php7.0. -fpm.sock but socket file, this method may be faster, so you need to change

fastcgi_pass 127.0.0.1:9000;

in the php configuration on nginx to:

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

to successfully run php

Recommended study: "

PHP Video Tutorial"

Continue to add

A very interesting thing, I want to upload a video of 27m, nginx directly reported 413 Request Entity Too Large, but I did not set it...

Add it to the nginx configuration (set-enabled/default)

server { ... client_max_body_size 80m; ... }

Reread the configuration and restart the server

nginx -s reload service nginx restart

Then you have to modify php.ini and modify two configurations in it

upload_max_filesize = 80M post_max_size = 80M

Then turn off the php-fpm process and restart it~

ps: Teacher He is really I haven’t researched it at all...mp4 cannot be uploaded, but this type is not added to the system. I have to find this myself...uncomfortable:(

note: It is now more recommended to use apt under ubuntu. It’s not apt-get…so, it’s time to change!

The above is the detailed content of What should I do if mac nginx does not parse php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn