What is the method for deploying PHP to Nginx?

There are several ways to deploy PHP in nginx.

  1. To set up PHP-FPM, first install PHP-FPM (FastCGI Process Manager), which is a PHP FastCGI manager used to handle PHP scripts. Once installed, configure nginx to use PHP-FPM to process PHP scripts.
  2. Setting up nginx: In the nginx configuration file, add the configuration for handling PHP. This can be done by modifying the server block in nginx and adding a location block to configure how PHP scripts are handled. For example:
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

In the above configuration, all requests ending in .php are redirected to the address and port where the local PHP-FPM process is listening for processing (default is 127.0.0.1:9000).

  1. Restart nginx: After configuring, it is necessary to restart nginx for the changes to take effect.
  2. Test PHP: Create an index.php file in the web root directory of nginx, and write the following content in it:
<?php phpinfo(); ?>

Then, access the URL of the file in the browser. If the PHP information page can be displayed correctly, it means that PHP has been successfully deployed on nginx.

Note: The above is the most basic deployment method, specific configurations may vary depending on the system environment and requirements.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds