Can't open php when installing nginx

WBOY
Release: 2023-05-07 10:17:07
Original
694 people have browsed it

Install nginx and cannot open php

When building a website server, it is a very popular solution to use Nginx as the web server and cooperate with PHP for dynamic processing of the page. However, when installing Nginx and PHP, you sometimes encounter some problems, such as "Cannot open PHP after installing Nginx".

If you have successfully installed Nginx, but encounter problems when opening PHP, it may be due to the following reasons:

  1. PHP is not installed correctly

When installing PHP, you need to ensure that PHP is installed correctly and the Nginx configuration file is set correctly. Confirm that PHP, nginx and related mods have been installed. You can enter the following command in the terminal to check:

sudo apt-get install php7.2-fpm
sudo apt-get install nginx
sudo apt -get install php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php7.2-xml php7.2-xmlrpc php7.2-zip

(Note: the above command It is based on the Ubuntu system, change it according to your own operating system)

  1. There is an error in the configuration file

In the configuration file, there may be a code error that causes Nginx to not work correctly Process PHP files. This problem can be solved by checking whether Nginx's configuration file is correct.

Nginx configuration files are generally located in the /etc/nginx/sites-available/ folder. Open the corresponding file and confirm whether the following settings are correct:

  1. location ~ . php$ { … } steps.
  2. fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; Steps.
  3. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; and fastcgi_param PATH_INFO $fastcgi_path_info; steps.
  4. In the end of the Nginx configuration file, a simple judgment needs to be made: if a request such as *.php cannot be matched, it will be forwarded to the /index.php file.

location / {

        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
Copy after login

}

  1. Permission problem

If nginx and php are still not working properly after installation To use, be sure to check the read, write, and execute permissions of the PHP file first.

sudo chmod -R 755 /path/to/webroot/

(Note: The above command is based on Ubuntu system, change it according to your own operating system)

Summary

When using Nginx and PHP to build a website, it is common to encounter the problem of "cannot open PHP when installing Nginx". This issue can be resolved quickly by confirming that PHP is installed correctly, checking the configuration files for errors, and resolving permission issues. If you encounter other problems, you can post related questions in relevant technical communities such as Stack Overflow to get more help.

The above is the detailed content of Can't open php when installing nginx. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template