How to install Nginx and PHP-FPM on Ubuntu? How to install LEMP on ubuntu system? Here’s the article which will help you install Nginx and PHP-FPM or LEMP in less than 2 minutes.
We will be using PHP7.2 FPM version in this post and will see Nginx rules to connect to PHP-FPM through Socket
Let’s start with Nginx installation, Run following commands on Terminal
apt update apt install nginx #it will install latest nginx version
Similarly, Let’s Install PHP7.2-FPM now, Run following commands on Terminal
apt install -y php7.2-fpm
Above commands will install php7.2-cli and some other important PHP extensions as well.
You can check the installation of both by checking status of their services
service nginx status service php7.2-fpm status
Nginx Configuration files reside at /etc/nginx folder
We’ll create our website’s Nginx configuration file there
Notes: In the above configuration file, We have added the “expires” variable in each location block, which will suggest the caching time of that object once served on the browser.
We have also added, Content-type header for files that will be added in headers.
Finally, we have integrated PHP-FPM configuration, so every file with extension .php will be served with that block.
For more variants of NGINX configuration example, visit this article link
Save your changes and now we will create link of this configuration file
cd /etc/nginx/sites-enabled && ln -s /etc/nginx/sites-available/example.servername.com.conf example.servername.com.conf
Now, restart Nginx for this changes to get effect.
service nginx restart
If you want to add any additional package from PHP as an eg. MySQL extension to connect to MySQL database, run following command
apt install php7.2-mysql
Now, restart PHP-FPM after that
service php7.2-fpm restart
Let’s Create phpinfo file to check this setup
cd /usr/share/nginx/html && vi info.php
<?php phpinfo(); ?>
Save this file and Go to Browser and hit your IP/Domain
Note: Code Directory is /usr/share/nginx/html
Read out other blog on NGINX here
Do Reach out in the comment section if you find this content useful.
May 1, 20120
How do I run nginx on ubuntu?
1. update your package manager
2. Install latest Nginx version
apt-get install nginx
3. Check Nginx status using
service nginx status
4. start Nginx service if status is stopped
service nginx start
5. Change Nginx configuration as needed