After installing MySQL Database, now its time to Install And Configure PHP Processor on DigitalOcean – We now have NGINX and MySQL installed on our server we still don’t have anything that can be used to generate and serve dynamic content. PHP is a powerful scripting language that fulfills this purpose. It’s also the programming language used to code WordPress. And for this reason it’s required that we install. Unlike Apache, NGINX has ability to process PHP natively. In order to process PHP we will need to install a processing manager known as php-fpm.
php-fpm stands for PHP CGI process manager.
We’ll start by installing the php-fpm module in a helper package that allows PHP to communicate with our database. To do this to type in the following command.
[mks_highlight color=”#ddff99″]$ apt install php-fpm php-mysql[/mks_highlight]
And press enter. Type in Y at the prompt and press enter.
Install and Configure PHP Processor
Now the components contain within the LEM stack bundle are now installed. We still need to configure some additional modifications to instruct NGINX to use the PHP processor for Dynamic Content. This is done by modifying the server block configuration files on NGINX server block files are similar to virtual host files in Apache. They instruct the server on how to process many different components.
Also Read: Install And Configure NGINX Web Server On DigitalOcean
For example if you have multiple domains they would be configured in block files. You can also specify what type of file extensions a block can handle. For example PHP, HTML and so on. Since we will only be hosting one domain on this server we can modify the default block configuration file to suit our needs. This file is contained within the site’s available directory in the NGINX folder.
Type the following command:
[mks_highlight color=”#ddff99″]$ nano /etc/nginx/sites-available/example.com[/mks_highlight]
So this is what the file looks like:
[mks_toggle title=”/etc/nginx/sites-available/example.com” state=”open”]
server {
listen 80;
root /var/www/html;
index index.html index.htm index.php index.nginx-debian.html;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
[/mks_toggle]
Configuring Nginx to Use the PHP Processor
So this is what the file looks like here. And to scroll up and down you can use your up and down arrow keys on your keyboard in this file. We can see some of the important items that the block file handles. Add index.php at the first so server can give preference to PHP files.
[mks_toggle title=”/etc/nginx/sites-available/example.com” state=”open”]
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;
}
[/mks_toggle]
So after making the necessary changes you’re going to, go ahead and press Ctrl + X and it’s going to ask you if you want to save the file. After making changes now we need to test configurations changes are OK.
[mks_highlight color=”#ddff99″]$ nginx -t[/mks_highlight] and press Enter.
And the test was successful. So you want to make sure you see that message. If you don’t it’s possible that you made a typo when you were configuring the changes to the file. So you’ll just have to open the file again you know just just make sure that there’s no issues there. And save the file if you have made any changes. Since there’s no errors reported here we can reload our server to make the necessary changes.
[mks_highlight color=”#ddff99″]$ systemctl reload nginx[/mks_highlight] and press Enter.