Install LEMP – Nginx, PHP, MariaDB and PhpMyAdmin in OpenSUSE

LEMP or Linux, Engine-x, MySQL and PHP stack is a software bundle composed of open source software installed on the Linux operating system for running PHP based web applications powered by the Nginx HTTP server and MySQL/MariaDB database management system.

Read Also: Install LAMP – Apache, PHP, MariaDB and PhpMyAdmin in OpenSUSE

This tutorial will guide you on how to install a LEMP stack with Nginx, MariaDB, PHP, PHP-FPM and PhpMyAdmin on OpenSuse server/desktop editions.

Installing Nginx HTTP Server

Nginx is a fast and reliable HTTP and proxy server which can handle higher load of HTTP requests. It uses an asynchronous event-driven approach to handling requests, and its modular event-driven architecture can provide more predictable performance under high loads.

To install Nginx on OpenSuse, run the following command.

$ sudo zypper install nginx
Install Nginx on OpenSuse
Install Nginx on OpenSuse

Once the Nginx installed, you can start the service for now, then enable it to auto-start at boot time and verify the status of Nginx by running the following commands.

$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo systemctl status nginx
Start, Enable and Verify Nginx
Start, Enable and Verify Nginx

Read Also: 10 Most Used Nginx Commands Every Linux User Must Know

At this point, the Nginx web server should be up and running, you can also verify the status using the netstat command as shown.

$ sudo netstat -tlpn | grep nginx
Check Nginx Port Listening
Check Nginx Port Listening

Now, we need to test if the Nginx installation is working fine. Unlike on other Linux distributions, under openSUSE, Nginx doesn’t have a standard index.html document in the web root folder. We need to create a new index.html file under the root web directory "/srv/www/htdocs" as show.

$ echo "<h1>Nginx is running fine on openSUSE Leap</h1>" | sudo tee /srv/www/htdocs/index.html
Create Nginx Index File
Create Nginx Index File

If you have firewalld installed, you need to open port 80 and 443 to allow web traffic on firewall.

$ sudo firewall-cmd --permanent --add-port=80/tcp
$ sudo firewall-cmd --permanent --add-port=443/tcp
$ sudo firewall-cmd --reload
Open Nginx Port on OpenSuse
Open Nginx Port on OpenSuse

Next, open a web browser and navigate to the address http://localhost and verify the Nginx page.

Check Nginx Page
Check Nginx Page

Installing MariaDB Database Server

MariaDB is a free and open source fork of the MySQL relational database management system. It’s developed by the original developers of MySQL and intended to stay open source. MariaDB is fast, scalable and robust, with a rich ecosystem of storage engines, plugins and many other tools make it very versatile for a wide variety of use cases.

To install MariaDB on OpenSuse, run the following command.

$ sudo zypper install mariadb mariadb-client 
Install MariaDB in OpenSuse
Install MariaDB in OpenSuse

Next, start the MariaDB service for now, then enable it to auto-start at boot time and check its status.

$ sudo systemctl start mariadb 
$ sudo systemctl enable mariadb 
$ sudo systemctl status mariadb 
Start MariaDB Service in OpenSuse
Start MariaDB Service in OpenSuse

The next critical step under this section is to secure the MariaDB server installation. Therefore run the security script which ships with the MariaDB package, as shown.

Note: Running MariaDB security script and all its parts is highly recommended for all MariaDB servers in production.

$ sudo mysql_secure_installation 

After running the script, read the description at each step carefully. You should set a root user password, remove anonymous users, disable remote root access, remove the test database and access to it and finally reload privileges table.

Secure MariaDB Installation in OpenSuse
Secure MariaDB Installation in OpenSuse

Installing and Configuring PHP and PHP-FPM

PHP-FPM (short for PHP FastCGI Process Manager) is an alternative FastCGI daemon for PHP with some additional features and designed to handle high loads. It maintains pools (workers that can respond to PHP requests) to accomplish this. Importantly, it is faster than traditional CGI-based methods, such as SUPHP, for multi-user PHP environments.

To install PHP and PHP-FPM along with needed modules run the following command.

$ sudo zypper install php php-mysql php-fpm php-gd php-mbstring
Install PHP and PHP-FPM in OpenSuse
Install PHP and PHP-FPM in OpenSuse

Before we proceed to start the PHP-FPM service, we need to create the required configuration files from the default files provided during the installation, and configure the service ready for operations.

$ sudo cp /etc/php7/fpm/php-fpm.conf.default  /etc/php7/fpm/php-fpm.conf 
$ sudo cp /etc/php7/fpm/php-fpm.d/www.conf.default /etc/php7/fpm/php-fpm.d/www.conf

Then open the main php-fpm.conf configuration file for editing.

$ sudo vim /etc/php7/fpm/php-fpm.conf 

Uncomment the following line at the line number 24 as shown.

error_log = log/php-fpm.log

Save and close the file.

Configure PHP FPM
Configure PHP FPM

Next, we need to define the correct settings for the configured pools in the www.conf configuration file.

$ sudo vim /etc/php7/fpm/php-fpm.d/www.conf

First, configure the Unix owner and group owner of processes to the Nginx user and group. Do this by changing the values of the user and group parameters from nobody to nginx.

user = nginx
group = nginx

Now save the changes to the file and exit it.

Set Nginx User and Group
Set Nginx User and Group

Additionally, there is one more important configuration to perform, which secures PHP-FPM in the /etc/php/cli/php.ini file.

$ sudo vim /etc/php7/cli/php.ini

Search for the line ;cgi.fix_pathinfo=1 and change it to.

cgi.fix_pathinfo=0
Configure PHP-FPM CGI
Configure PHP-FPM CGI

Save the changes in the file and exit.

Next, start the PHP-FPM service for now, then enable it to auto-start at boot time and check its status.

$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm
$ sudo systemctl status php-fpm
Start PHP-FPM Service
Start PHP-FPM Service

Configuring Nginx to Work with PHP-FPM

At this point, we need to configure Nginx to work with PHP-FPM in the default Nginx configuration file.

$ sudo vim /etc/nginx/nginx.conf

Then look for the following section, and add the index.php in the list of expected index files.

location / { 
           root   /srv/www/htdocs/; 
           index  index.php index.html index.htm ; 
       }

Configure Nginx for PHP-FPM
Configure Nginx for PHP-FPM

Also find the following section (which should be commented out) and uncomment it. This section is used to pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000.

location ~ \.php$ { 
       root           /srv/www/htdocs/; 
       fastcgi_pass   127.0.0.1:9000; 
       fastcgi_index  index.php; 
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
       include        fastcgi_params; 
       }
Configure PHP for FastCGI
Configure PHP for FastCGI

Save the changes in the file and exit.

Testing Nginx and PHP-FPM

The next step is to test if Nginx is working well in conjunction with PHP-FPM by creating a new PHP test file under the DocumentRoot directory as shown.

$ echo "<?php phpinfo(); ?>" | sudo tee /srv/www/htdocs/info.php

Now we need to check if the Nginx configuration is correct as follows, before we proceed to restart the service.

$ sudo nginx -t
Check Nginx Configuration for Errors
Check Nginx Configuration for Errors

If the Nginx configuration syntax is ok, go ahead and restart the Nginx and PHP-FPM services for the recent changes to take efffect.

$ sudo systemctl restart nginx php-fpm

Now open a web browser and navigate to the address http://localhost/info.php to verify the PHP configuration as shown in the following screenshot.

Verify PHP Info
Verify PHP Info

Installing and Configuring PhpMyAdmin

phpMyAdmin is a free, simple easy-to-use and popular tool written in PHP, built for administering MySQL server over the Web. It spports a wide range of operations on MySQL and MariaDB.

To install phpMyAdmin on OpenSuse, run the following command.

$ sudo zypper install phpMyAdmin
Install PhpMyAdmin in OpenSuse
Install PhpMyAdmin in OpenSuse

Once the installation is complete, create a new vhost configuration file for accessing phpMyAdmin as shown.

$ sudo vim /etc/nginx/vhosts.d/phpmyadmin.conf

Add these following configuration to file.

server { 
   listen 80; 

   server_name localhost/phpMyAdmin; 

  root /srv/www/htdocs/phpMyAdmin; 

   location / { 
       try_files $uri /index.php?$args; 
   } 

   location ~ \.php$ { 
       try_files $uri =404; 
       fastcgi_pass 127.0.0.1:9000; 
       fastcgi_index index.php; 
       include fastcgi_params; 
   } 
} 

Save the changes and close the file. Then restart the Nginx service with the following command.

$ sudo systemctl restart nginx

Now go to your web browser and type the address http://localhost/phpMyAdmin. A phpMyAdmin login page should display as shown in the following screenshot. Enter your database root user login credentials and click Go.

PhpMyAdmin Dashboard
PhpMyAdmin Dashboard

That’s all! In this tutorial, we’ve explained you how install a LEMP stack with Nginx, MariaDB, PHP, PHP-FPM and PhpMyAdmin on OpenSuse server/desktop editions. If you’re facing any issues during setup, do ask your questions via a comment form below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

6 thoughts on “Install LEMP – Nginx, PHP, MariaDB and PhpMyAdmin in OpenSUSE”

  1. Looks great. But for an eCommerce store like me who is also tech-savvy, tends to save his hand from getting dirty in coding stuff like that. I could either hire in devops team or outsource my server management.

    Reply

Leave a Reply to Arthur Mickeal Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.