Install LEMP stack (Nginx, MariaDB, PHP) on OpenSUSE Leap 42.1

In this tutorial, we are going to learn how to install the LEMP stack (Nginx, MariaDB and PHP) on OpenSUSE Leap 42.1. You will find this process a little bit different from installing LEMP stack on Debian,, Fedora or CentOS. In pariticular, we must set SuSE firewall to allow Internet user to access port 80. So without further ado, let’s get started.

Step1: Install Nginx Web Server

Nginx [engine x] is a HTTP server and IMAP/POP3 proxy server written by Igor Sysoev. It has been running on many heavily loaded Russian sites for many years.

Run the following command to install Nginx on OpenSUSE Leap 42.1

sudo zypper install nginx

Then start Nginx process and set it to auto-start when system boots up.

sudo systemctl start nginx

sudo systemctl enable nginx

Now create a index.html file in the /srv/www/htdocs/ web root.

sudo nano /srv/www/htdocs/index.html

Copy and paste the following HTML code to this file.

<!doctype html>
<html>
<body>
Welcome to Nginx on OpenSUSE!
</body>
</html>

Save and close the file. Now in your Web browser, type the IP address your OpenSUSE Leap 42.1 machine. If you are this is your local machine, then you will see the following.

Install LEMP stack on OpenSUSE Leap 42.1

If you are install Nginx on a remote server, then you need to configure SuSE firewall to allow public access to port 80 because by default it only allows local access to port 80. Open the firewall configuration file.

sudo nano /etc/sysconfig/SuSEfirewall2

Find the following line. (It’s the 253th line.)

FW_SERVICES_EXT_TCP=""

Add 80 in between the quotation marks.

FW_SERVICES_EXT_TCP="80"

FW is short for firewall and EXT stands for external zone (Internet). This directive means the firewall allows external zone to access TCP port 80 which is the port Nginx listens on. Save and close the file. Then restart SuSE firewall.

sudo systemctl restart SuSEfirewall2

Now you should be able to access your remote Web server.

Step2: Configure the Default Server Block

The default server block in /etc/nginx/nginx.conf file is enough for a static HTML site. However we are going to install PHP so we need to change some configuration of the default server.

Here is my configuration.

server {
listen       80;
server_name  localhost;
#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;
location / {
root   /srv/www/htdocs/;
index  index.php index.html index.htm;
}
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /srv/www/htdocs/;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# 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;
        }

The only thing you need to change is to uncomment the location block related to PHP and change /scripts to $document_root. Save and close the file. Then run Nginx configuration test.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If test is successful, reload Nginx.

sudo systemctl reload nginx

Step3: Install MariaDB

MariaDB is a backward compatible, drop-in replacement branch of the MySQL Database Server. It includes all major open source storage engines, including the Maria storage engine.

Install MariaDB with this command:

sudo zypper install mariadb mariadb-client

Then start MariaDB service and enable auto-start when system boots up.

sudo systemctl start mysql

sudo systemctl enable mysql

Now run the the mysql_secure_installation script to set a password for MariaDB root user, remove anonymous user, disable remote root login and remove test database.

 sudo mysql_secure_installation

Install LEMP stack on OpenSUSE Leap 42.1

Step4: Install PHP5

PHP is a server-side, cross-platform HTML embedded scripting language. Run the following command to install PHP5 on OpenSUSE Leap.

sudo zypper install php5-fpm

Next, rename /etc/php5/fpm/php-fpm.conf.default to /etc/php5/fpm/php-fpm.conf.

sudo mv /etc/php5/fpm/php-fpm.conf.default /etc/php5/fpm/php-fpm.conf

Now edit php-fpm configuration file.

sudo nano /etc/php5/fpm/php-fpm.conf

Change the user and group values from nobody to nginx:

user = nginx
group = nginx

Also find the following line in this file.

;error_log = log/php-fpm.log

and change it to this:

error_log = /var/log/php-fpm.log

Save and close the file. Now copy the php.ini file to /etc/php5/fpm/ directory.

sudo cp /etc/php5/cli/php.ini /etc/php5/fpm/

Then edit this file.

sudo nano /etc/php5/fpm/php.ini

Find the following line:

;cgi.fix_pathinfo=1

and change it to this:

cgi.fix_pathinfo=0

Save and close the file. Now start php-fpm service and enable auto-start when system boots up.

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

The Final Step: Test PHP

Create a php file under the web root directory.

sudo nano /srv/www/htdocs/test.php

Copy and paste the following text into the file.

<?php
phpinfo();
?>

Save the file and then reload Nginx.

sudo systemctl reload nginx

In your Web browser, navigate to your-server-ip/test.php. You will see all the PHP information of your server.

Install LEMP stack on OpenSUSE Leap 42.1

Congrats! You have successfully installed the LEMP stack on OpenSUSE Leap 42.1. For security reasons, it’s best to delete the test.php file from your server so others can not peek at it.

Rate this tutorial
[Total: 0 Average: 0]

2 Responses to “Install LEMP stack (Nginx, MariaDB, PHP) on OpenSUSE Leap 42.1

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here