Home Backend Development PHP Problem What should I do if mac nginx does not parse php?

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

Jul 23, 2021 am 10:02 AM
nginx php

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:

1

2

3

4

5

6

7

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;

}

Copy after login

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)

1

php-fpm --fpm-config /private/etc/php-fpm.conf  --prefix /usr/local/var

Copy after login
  • Run php-fpm for the third time

1

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

Copy after login

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

1

fastcgi_pass 127.0.0.1:9000;

Copy after login

in the php configuration on nginx to:

1

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

Copy after login

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)

1

2

3

4

5

server {

    ...

    client_max_body_size 80m;

    ...

}

Copy after login

Reread the configuration and restart the server

1

2

nginx -s reload

service nginx restart

Copy after login

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

1

2

upload_max_filesize = 80M

post_max_size = 80M

Copy after login
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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1244
24
PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

See all articles