In this tutorial, we will show you how to install LEMP on Manjaro 20. For those of you who didn’t know, LEMP stands for Linux, Nginx (pronounced as Engine X), MySQL/MariaDB, and PHP or Perl or Python. All components are free and open-source software, and the combination is suitable for building dynamic web pages. The LEMP stack is one of the most popular server configurations in the world.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of LAMP Stack on a Manjaro 20 (Nibia).
Prerequisites
- A server running one of the following operating systems: Manjaro 20.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install LEMP on Manjaro 20 Nibia
Step 1. Before running the tutorial below, make sure that our system is up to date:
sudo pacman -Syu
Step 2. Installing Nginx.
Install Nginx on Manjaro Linux by running the command below:
sudo pacman -S nginx
Once Nginx has been installed, start it and enable it to start on system boot:
sudo systemctl start nginx sudo systemctl enable nginx
To verify Nginx setup, open your browser and browse to the server hostname or IP address and you should see the Nginx default test page as shown below:
http://your-ip-address
Step 3. Install MariaDB.
Run the following command to install MariaDB Server on Manjaro:
sudo pacman -S mariadb
Then, initialize the MariaDB data directory and create system tables as shown below:
sudo mysql_install_db –user=mysql basedir=/usr –datadir=/var/lib/mysql
Next, enable and start it by using the following commands:
sudo systemctl start mariadb sudo systemctl enable mariadb
By default, MariaDB is not hardened. You can secure MySQL using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] Y Enabled successfully! Reloading privilege tables.. ... Success! You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Step 4. Installing PHP.
Run the following command to install PHP:
sudo pacman -S php php-fpm
Once the installation is complete, start and enable php-fpm
to start on boot with the below commands:
sudo systemctl start php-fpm sudo systemctl enable php-fpm
We need to make a few modifications to the Nginx configuration file:
sudo nano /etc/nginx/nginx.conf
Add the following lines:
location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; root /usr/share/nginx/html; include fastcgi.conf; }
Save the file and restart both Nginx and PHP-FPM for the changes to come into effect:
sudo systemctl restart nginx sudo systemctl restart php-fpm
To test the PHP installation, creating an info.php
file in the /usr/share/nginx/html/
path:
sudo nano /usr/share/nginx/html/info.php
Append the following lines and save the file:
<?php phpinfo(); ?>
Step 5. Configure firewall.
To allow external connections to our Manjaro Linux web server, we need to open web ports 80 and 443. But first, let’s install ufw
a firewall:
sudo pacman -S ufw sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw enable
Congratulations! You have successfully installed the LEMP server. Thanks for using this tutorial for installing LEMP (Nginx, MariaDB, and PHP) in Manjaro 20 systems. For additional help or useful information, we recommend you to check the official Nginx, MariaDB, and PHP websites.