@mac
To install PHP in nginx, follow these steps:
- Make sure that you have nginx installed on your system. If you don't have it installed, you can install it by running the following command:
- Next, install PHP and the PHP-FPM (FastCGI Process Manager) package by running the following command:
1
|
sudo apt install php-fpm
|
- Once PHP is installed, you need to configure nginx to use it. To do this, open the default nginx configuration file in a text editor:
1
|
sudo nano /etc/nginx/sites-available/default
|
- In the file, you will see a block of configuration settings for the server directive. Within this block, add the following lines:
1
2
3
4
|
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
|
- Save the file and exit the text editor.
- Test the nginx configuration to make sure there are no syntax errors:
- If the configuration test passes, restart the nginx server to apply the changes:
1
|
sudo systemctl restart nginx
|
That's it! PHP is now installed and configured in nginx. You can create PHP files in your web root directory (usually /var/www/html
) and access them through your web browser.