PHP is not installed or not configured
First, please make sure that your server has PHP installed and configured correctly nginx to make it work properly. To check if PHP has been installed correctly, open a terminal and run the following command:
php -v
This will display the version of PHP currently installed on your server. If the PHP version is not displayed, consider installing PHP.
To ensure that PHP works with nginx, edit the nginx configuration file and add the following line:
location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
Here, we want to specify nginx’s PHP file processing location and other parameters. Please confirm that the code block has been added to your nginx configuration file and that the path to the sock file matches your PHP configuration file.
index.php file not set
If your web application's home page is index.php, but it won't be in nginx Automatically processed, then you need to add index.php in the "index" directive of the nginx configuration file as follows:
index index.php index.html;
Now, when you open the homepage, nginx will automatically find index.php and process it correctly it.
PHP file permissions
Another main reason why nginx cannot parse PHP files is incorrect permissions. Make sure the following:
The permissions of the PHP file are 644
The permissions of the directory where the PHP file is located are 755
Also make sure that the nginx user has ownership of all PHP files, and the ownership of the directory where the PHP files are located is also set to the nginx group. This can be achieved by using the following command:
sudo chown -R nginx:nginx /var/www/html/
Here we assign the ownership of the /var/www/html/ directory to the nginx user and group.
PHP module is not enabled
If your nginx cannot parse the PHP file and does not display any error message, please make sure that the PHP module has been enabled . To enable it, edit nginx's compilation options, add the following line:
--with-http_stub_status_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_auth_request_module \ --with-http_image_filter_module \ --with-http_geoip_module \ --with-http_degradation_module \ --with-http_xslt_module \ --with-http_stub_status_module \ --with-http_spdy_module \ --with-http_auth_request_module \ --with-http_slice_module \ --with-mail \ --with-mail_ssl_module \ --with-ipv6 \ --with-pcre \ --with-stream \ --with-stream_ssl_module \ --with-threads \ --with-debug \ --add-module=/path/to/php-src/sapi/nginx/
Here, we added --add-module=/path/to/php-src/sapi/nginx/ to enable PHP module.
PHP Error Log
If nginx cannot parse the PHP file but does not display any error message, you can look for information in the PHP error log More information about the error. Open the php.ini file and uncomment the following lines to enable PHP error logging
error_log = /var/log/php/error.log log_errors = On
We specify /var/log/php/error.log as the PHP error log and enable the error logging function. Please make sure the folder has been created and has the appropriate permissions.
The above is the detailed content of How to solve nginx not parsing php files. For more information, please follow other related articles on the PHP Chinese website!

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.

NGINX and Apache each have their own advantages, and the choice depends on the specific needs. 1.NGINX is suitable for high concurrency, with simple deployment, and configuration examples include virtual hosts and reverse proxy. 2. Apache is suitable for complex configurations and is equally simple to deploy. Configuration examples include virtual hosts and URL rewrites.

The purpose of NGINXUnit is to simplify the deployment and management of web applications. Its advantages include: 1) Supports multiple programming languages, such as Python, PHP, Go, Java and Node.js; 2) Provides dynamic configuration and automatic reloading functions; 3) manages application lifecycle through a unified API; 4) Adopt an asynchronous I/O model to support high concurrency and load balancing.

NGINX started in 2002 and was developed by IgorSysoev to solve the C10k problem. 1.NGINX is a high-performance web server, an event-driven asynchronous architecture, suitable for high concurrency. 2. Provide advanced functions such as reverse proxy, load balancing and caching to improve system performance and reliability. 3. Optimization techniques include adjusting the number of worker processes, enabling Gzip compression, using HTTP/2 and security configuration.

The main architecture difference between NGINX and Apache is that NGINX adopts event-driven, asynchronous non-blocking model, while Apache uses process or thread model. 1) NGINX efficiently handles high-concurrent connections through event loops and I/O multiplexing mechanisms, suitable for static content and reverse proxy. 2) Apache adopts a multi-process or multi-threaded model, which is highly stable but has high resource consumption, and is suitable for scenarios where rich module expansion is required.

NGINX is suitable for handling high concurrent and static content, while Apache is suitable for complex configurations and dynamic content. 1. NGINX efficiently handles concurrent connections, suitable for high-traffic scenarios, but requires additional configuration when processing dynamic content. 2. Apache provides rich modules and flexible configurations, which are suitable for complex needs, but have poor high concurrency performance.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

NGINXUnit is an open source application server that supports multiple programming languages and provides functions such as dynamic configuration, zero downtime updates and built-in load balancing. 1. Dynamic configuration: You can modify the configuration without restarting. 2. Multilingual support: compatible with Python, Go, Java, PHP, etc. 3. Zero downtime update: Supports application updates that do not interrupt services. 4. Built-in load balancing: Requests can be distributed to multiple application instances.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor
