LEMP: Difference between revisions

Created page with "==Update Software Packages== sudo apt update sudo apt upgrade ==Install Nginx Web Server== sudo apt install nginx After it’s installed, we can enable Nginx to auto-start at boot time by running the following command. sudo systemctl enable nginx Then start Nginx with this command: sudo systemctl start nginx Now check out its status. sudo systemctl status nginx Check Nginx version. nginx -v If you are using UFW firewall, then run this command to open TCP po..."
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Update Software Packages==
==Update Software Packages==
sudo apt update


sudo apt upgrade
<syntaxhighlight lang="bash">
sudo apt update
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
sudo apt upgrade
</syntaxhighlight>


==Install Nginx Web Server==
==Install Nginx Web Server==
sudo apt install nginx
 
<syntaxhighlight lang="bash">
sudo apt install nginx
</syntaxhighlight>


After it’s installed, we can enable Nginx to auto-start at boot time by running the following command.
After it’s installed, we can enable Nginx to auto-start at boot time by running the following command.
sudo systemctl enable nginx
 
<syntaxhighlight lang="bash">
sudo systemctl enable nginx
</syntaxhighlight>


Then start Nginx with this command:
Then start Nginx with this command:
sudo systemctl start nginx
 
<syntaxhighlight lang="bash">
sudo systemctl start nginx
</syntaxhighlight>


Now check out its status.
Now check out its status.
sudo systemctl status nginx
 
<syntaxhighlight lang="bash">
sudo systemctl status nginx
</syntaxhighlight>


Check Nginx version.
Check Nginx version.
nginx -v
 
<syntaxhighlight lang="bash">
nginx -v
</syntaxhighlight>


If you are using UFW firewall, then run this command to open TCP port 80.
If you are using UFW firewall, then run this command to open TCP port 80.
sudo ufw allow http
 
<syntaxhighlight lang="bash">
sudo ufw allow http
</syntaxhighlight>


Finally, we need to make www-data (Nginx user) as the owner of web directory. By default, it’s owned by the root user.
Finally, we need to make www-data (Nginx user) as the owner of web directory. By default, it’s owned by the root user.
sudo chown www-data:www-data /usr/share/nginx/html -R
 
<syntaxhighlight lang="bash">
sudo chown www-data:www-data /usr/share/nginx/html -R
</syntaxhighlight>


==Install MariaDB Database Server==
==Install MariaDB Database Server==
sudo apt install mariadb-server mariadb-client
 
<syntaxhighlight lang="bash">
sudo apt install mariadb-server mariadb-client
</syntaxhighlight>


After it’s installed, MariaDB server should be automatically stared. Use systemctl to check its status.
After it’s installed, MariaDB server should be automatically stared. Use systemctl to check its status.
systemctl status mariadb
 
<syntaxhighlight lang="bash">
systemctl status mariadb
</syntaxhighlight>


If it’s not running, start it with this command:
If it’s not running, start it with this command:
sudo systemctl start mariadb
 
<syntaxhighlight lang="bash">
sudo systemctl start mariadb
</syntaxhighlight>


To enable MariaDB to automatically start at boot time, run
To enable MariaDB to automatically start at boot time, run
sudo systemctl enable mariadb
 
<syntaxhighlight lang="bash">
sudo systemctl enable mariadb
</syntaxhighlight>


Now run the post installation security script.
Now run the post installation security script.
sudo mysql_secure_installation
 
<syntaxhighlight lang="bash">
sudo mysql_secure_installation
</syntaxhighlight>


So you can run the following command to login without providing MariaDB root password.
So you can run the following command to login without providing MariaDB root password.
sudo mariadb -u root
 
<syntaxhighlight lang="bash">
sudo mariadb -u root
</syntaxhighlight>


To exit, run
To exit, run
exit;
 
<syntaxhighlight lang="bash">
exit;
</syntaxhighlight>


Check MariaDB server version information.
Check MariaDB server version information.
mariadb --version
 
<syntaxhighlight lang="bash">
mariadb --version
</syntaxhighlight>


==Install PHP7.4==
==Install PHP7.4==
sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl
<syntaxhighlight lang="bash">
sudo apt install php7.4 php7.4-fpm php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-xml php7.4-gd php7.4-curl
</syntaxhighlight>


Installing these PHP extensions ensures that your CMS runs smoothly. Now start php7.4-fpm.
Installing these PHP extensions ensures that your CMS runs smoothly. Now start php7.4-fpm.
sudo systemctl start php7.4-fpm
 
<syntaxhighlight lang="bash">
sudo systemctl start php7.4-fpm
</syntaxhighlight>


Enable auto-start at boot time.
Enable auto-start at boot time.
sudo systemctl enable php7.4-fpm
 
<syntaxhighlight lang="bash">
sudo systemctl enable php7.4-fpm
</syntaxhighlight>


Check status:
Check status:
systemctl status php7.4-fpm
 
<syntaxhighlight lang="bash">
systemctl status php7.4-fpm
</syntaxhighlight>


==Create an Nginx Server Block==
==Create an Nginx Server Block==
An Nginx server block is like a virtual host in Apache. We will not use the default server block because it’s inadequate to run PHP code and if we modify it, it becomes a mess. So remove the default symlink in sites-enabled directory by running the following command. (It’s still available as <code>/etc/nginx/sites-available/default</code>.)
An Nginx server block is like a virtual host in Apache. We will not use the default server block because it’s inadequate to run PHP code and if we modify it, it becomes a mess. So remove the default symlink in sites-enabled directory by running the following command. (It’s still available as <code>/etc/nginx/sites-available/default</code>.)
sudo rm /etc/nginx/sites-enabled/default
 
<syntaxhighlight lang="bash">
sudo rm /etc/nginx/sites-enabled/default
</syntaxhighlight>


Then use a command-line text editor like Nano to create a brand new server block file under /etc/nginx/conf.d/ directory.  
Then use a command-line text editor like Nano to create a brand new server block file under /etc/nginx/conf.d/ directory.  
sudo nano /etc/nginx/conf.d/default.conf
 
<syntaxhighlight lang="bash">
sudo nano /etc/nginx/conf.d/default.conf
</syntaxhighlight>


Paste the following text into the file. The following snippet will make Nginx listen on IPv4 port 80 and IPv6 port 80 with a catch-all server name.
Paste the following text into the file. The following snippet will make Nginx listen on IPv4 port 80 and IPv6 port 80 with a catch-all server name.


server {
<syntaxhighlight lang="bash">
server {
   listen 80;
   listen 80;
   listen [::]:80;
   listen [::]:80;
Line 102: Line 170:
   }
   }
  }
  }
</syntaxhighlight>


Save and close the file. (To save a file in Nano text editor, press Ctrl+O, then press Enter to confirm. To exit, press Ctrl+X.)
Save and close the file. (To save a file in Nano text editor, press Ctrl+O, then press Enter to confirm. To exit, press Ctrl+X.)


Then test Nginx configurations.
Then test Nginx configurations.
sudo nginx -t
 
<syntaxhighlight lang="bash">
sudo nginx -t
</syntaxhighlight>


If the test is successful, reload Nginx.
If the test is successful, reload Nginx.
sudo systemctl reload nginx
 
<syntaxhighlight lang="bash">
sudo systemctl reload nginx
</syntaxhighlight>


==Source==
==Source==
*[https://www.linuxbabe.com/ubuntu/install-lemp-stack-ubuntu-20-04-server-desktop linuxbabe.com]
*[https://www.linuxbabe.com/ubuntu/install-lemp-stack-ubuntu-20-04-server-desktop linuxbabe.com]
*[https://github.com/erfantkerfan/LEMP-server github.com]


[[Category:Server]]
[[Category:Server]]
[[Category:Web Server]]
[[Category:Web Server]]
[[Category:Nginx]]