![]() If you dislike the echo command, use an editor to create a file named info.php in the /var/www/html folder with the following content: Test the Nginx, PHP integration This creates the most basic PHP file outside of a “Hello World” example you could create. The easiest way to do so is with a quick echo command: echo "" > /var/www/html/info.php Then add a new PHP file to Nginx’s web hosting directory. You may have to change permissions to the folder with a CHMOD command in order to create a file in it: sudo chmod -R 777 /var/www/html To prove this, create a PHP file in Nginx’s /var/www/html folder and test to ensure the page renders properly on the server. To enable the Nginx PHP fastCGI setup, restart the server: sudo systemctl restart nginx Create a PHP page in NginxĪfter the restart, PHP is fully enabled on Nginx. The following command validates the updated Nginx config file to ensure the edits do not create any syntax errors: sudo nginx -t nginx php config: the configuration file /etc/nginx/nf syntax is ok nginx php-fpm config: configuration file /etc/nginx/nf test is successful ![]() Changes are highlighted in bold: server # End of PHP FPM Nginx config example How to validate an Nginx config file The server section of the Nginx, PHP and PHP-FPM config file will look like this when completed. To configure PHP, Nginx and FTP (fastCGI), you must update the Nginx config file. Uncomment the section to deny all access to Apache.Uncomment the line to enable the fastcgi_pass and the php8.1-fpm.Uncomment the line to include snippets/nf.Uncomment the PHP scripts to FastCGI entry block.Make the following changes to the Nginx config to support PHP and PHP-FPM on the server: This command will open it with Nano: sudo nano /etc/nginx/sites-available/default ![]() The default Nginx file can be opened with any text editor. This allow the PHP FastCGI Process Manager to handle requests that have a. With Nginx and PHP-FPM installed, you must edit the default Nginx config file. - PHP 8.1 FastCGI Process Manager FPM for Ubuntu Loaded: loaded (/lib/systemd/system/) Active: active (php-fpm running) Add PHP support to Nginx.Check if PHP-FPM is runningĪfter the PHP-FPM setup is complete, check to see if it is running: sudo systemctl status php8.1-fpm To avoid this, install either the php-cgi or the php-fpm module for Nginx. PHP requires one of three dependencies to exist on a machine:Ī simple PHP install uses the libapache2-mod-php module by default, which requires installation of the full Apache HTTP server software suite. Why does a basic PHP install require Apache? ![]() The problem with this approach is that unlike PHP-FPM, the PHP package installs the Apache HTTP server and its httpd process, which conflicts with Nginx. In this instance, we have installed version 8.1 of the PHP and PHP-FPM packages.Ī common mistake is to install the PHP, not PHP-FPM package. You can install PHP-FPM support with another apt-get install command: sudo apt-get install php8.1-fpm -y To install PHP for Nginx, use the PHP-FPM library. You can visually verify the Nginx landing page displays on of a web browser.
0 Comments
Leave a Reply. |