A good alternative to LAMP is LEMP (Linux Nginx MariaDB/MySQL PHP). NGINX is a high-performance web server and reverse proxy; in English it is pronounced engine X.
As we can see, we need to install three programs. We will start with Nginx. This tutorial is for Ubuntu in all its versions; at the end of the article you will find all the commands to install LEMP on Red Hat–based distributions (Fedora, CentOS, etc.).
How to install Nginx
Log in to your server over SSH and run:
# apt-get install nginx
You can check that Nginx is running by executing:
# service nginx status
You should see something like:
● nginx.service – A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Thu xxxx-xx-xx xx:xx:xx CEST; 17s ago
Once nginx is installed, if you browse to your server's IP from a browser you should see the page:
How to install MariaDB
To install MariaDB run:
# apt-get install mariadb-server mariadb-client
You can check that MariaDB is running with:
# service mysql status
You should see something like:
● mysql.service – LSB: Start and stop the mysql database server daemon Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled) Active: active (running) Fri xxxx-xx-xx xx:xx:xx CEST; 17s ago
Now configure MariaDB by running:
# /usr/bin/mysql_secure_installation
- First it will ask for the “root” password for MariaDB. Press Enter because no password is set.
- Then it will ask if you want to set a password for the “root” user. Using a password is recommended.
- Next it will ask if you want to remove the anonymous user. Answer Yes to delete it.
- Next it will ask if you want to disable remote login for the “root” user. Answer Yes to disable remote access for “root”.
- Next it will ask if you want to remove the “test” database. Answer Yes to delete the “test” databases.
- Finally, it will ask if you want to reload the privilege tables. Answer Yes.
How to install PHP
To install PHP run one of these commands:
# apt install php php-cli php-mysql php-fpm
Check the installed PHP version:
# php -v
Then configure Nginx so PHP works. Edit:
# vi /etc/nginx/sites-available/default
After:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}Add the following, but change the sock path to match your installed PHP version (verified earlier):
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php8.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php8.0-fpm:
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
}After editing, restart Nginx:
# service nginx restart
To verify PHP works, create /var/www/html/test.php with:
<?php phpinfo(); ?>
When you open https://server-IP/test.php in a browser you should see something like:
Commands for RHEL-based distributions (CentOS, Fedora, etc.):
Nginx:
# yum install epel-release # yum install nginx # systemctl start nginx.service # systemctl enable nginx.service
MariaDB:
# yum install mariadb-server mariadb # systemctl start mariadb.service # systemctl enable mariadb.service # mysql_secure_installation
PHP:
# yum install php php-mysql php-fpm php-cli # systemctl start php-fpm.service
We hope this tutorial helped 🙂. If you have questions about this or any other issue related to your Clouding servers, write to support@clouding.io. We are here to help with whatever you need.