Home > Article > Backend Development > Can't open php when installing nginx
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:
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)
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:
location / {
# try to serve file directly, fallback to index.php try_files $uri /index.php$is_args$args;
}
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!