How to Install a LAMP Stack on OpenSUSE Leap 42.1

The LAMP Stack is a collection of open source software installed together on the Linux operating system to get your website and web application running on it. LAMP or - Linux, Apache, MySQL, and PHP - provides the foundation to host web applications based on PHP and MySQL (like Wordpress, Joomla, Drupal etc.) run on it.

In this tutorial, I will guide you trough the steps to install the LAMP Stack with OpenSUSE Leap 42.1 as the Linux operating system. We will Install apache2 with MariaDB and PHP on the server. I will include the installation of phpMyAdmin for MySQL administration and secure phpMyAdmin with a .htaccess file.


I will use OpenSUSE leap with IP address: on this server. This is most likely different from your settings, so you have to replace the IP with your own IP wherever it occurs.

  • OpenSUSE Leap 42.1 - server.
  • Root privileges

Login to the openSUSE server and get root privileges with sudo:

ssh [email protected]
sudo su

Step 1 - Configure SuSEfirewall2

SuSEfirewall2 is based on iptables, it will generate the iptables rules from the configuration file "/etc/sysconfig/SuSEfirewall2". It protects your server from network attacks and unwanted packets.

In this step, we will install SuSEfirewall2 and then configure it to allow access to the ssh service and access to apache for web access on port 80.

Install SuSEfirewall2 with zypper command:

zypper in SuSEfirewall2

Edit the configuration file with vim:

vim /etc/sysconfig/SuSEfirewall2

Go to line 321, define your services so everyone can access it, we will define sshd and apache2 for now:


Next, restart SuSEfirewall and restart the sshd services:

/sbin/rcSuSEfirewall2 restart
systemctl restart sshd

if you want to test the configuration, you can use telnet to access the ssh service port from outside of network:

telnet 22

Check SSH Port

Step 2 - Install and Configure Apache

Apache2 is available in the openSUSE repository, so we do not have to add any additional repository. We can continue this guide and install apache2 with the zypper command:

zypper in apache2

Now, go to the document root directory of the web server "/srv/www/htdocs/" and create a new index.html file so you can test that apache2 works:

cd /srv/www/htdocs/
echo "<h1>This is Apache OpenSUSE Leap 42.1</h1>" > index.html

Next, add apache services to start at boot and start apache2 with systemctl:

systemctl enable apache2
systemctl start apache2

Now open your web browser and access the opnsuse server ip address from it:

Apache works on OpenSuSE Leap

Step 3 - Install and Configure MariaDB

MariaDB is a relational database management system forked from the MySQL. MariaDB is developed by the original developer of MySQL (Monty Widenius) and now has released the stable version 10.1. It has the same feature set then MySQL 5.6 and 5.7.

In this step, we will install MariaDB and mariadb-client with zypper and then configure the MariaDB password.

Install mariadb and mariadb-client:

zypper in mariadb mariadb-client

Now start the mariadb service and add the service to run at boot time with systemctl:

systemctl start mysql
systemctl enable mysql

Now configure thMariaDBdb root password with the command below:


Type in your desired password when requested:

Enter current password for root (enter for none): PRESS ENTER
Set root password? [Y/n] Y
Re-enter new password: REPEAT PASSWORD
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Next, test access to the MariaDB server with the password that we configured above.

mysql -u root -p

Test the MriaDB Login.

Step 4 - Install and Configure PHP

PHP is one of most popular server-side scripting languages for web development and can be embedded into HTML pages. In this tutorial, I will guide you trough the installation of PHP 5.5 and configure it to work with the apache web server and the MySQL database.

Install php and the php extensions needed for this tutorial. We have to install the php-mysql extension to allow PHP scripts to connect tMySQLql, and we need php-mcrypt and php-gd for phpMyAdmin. Install them with the zypper command below:

zypper in php5 php5-mysql php5-mcrypt apache2-mod_php5 php5-mbstring php-mcrypt php-gd php-json php-zlib

Enable the php5 module in apache and restart the apache web server:

a2enmod php5
systemctl restart apache2


a2enmod extension = command to enable apache module.

Next, to ensure that php5 and apache are working properly, you can test them by creating a phpinfo file in the document root directory "/srv/www/htdocs/".

Go to the directory and create file info.php.

cd /srv/www/htdocs/
echo "<?php phpinfo(); ?>" > info.php

Now open your browser and type your server ip and the path to the php info file.

PHP info on OpenSuSE

You can see thaPHPhp and apache are working and you can see that the MySQL extension has been loaded.

Step 5 - Install and Configure phpMyAdmin

phpMyAdmin is a famous open source software based on PHP that makes us ease to manage MySQL/MariaDB databases from a web browser. It provides a great UI and is easy to configure on many web servers.

This step will cover the installation of phpMyAdmin and then we will configure it to make it secure by restricting access with a .htaccess file.

phpMyAdmin is available in the openSUSE repository, you can continue to install it with zypper command:

zypper in phpMyAdmin

To get phpMyAdmin working with PHP and apache, we have to enable the php_mbstring extension in the php.ini file. Edit the file with vim:

vim /etc/php5/apache2/php.ini

Go to the line 873 and uncomment the php_mbsting extension to enable it:


Save the file and exit the editor.

Now we will secure phpMyAdmin by restricting access to the phpMyAdmin page with an .htaccess file.

Before creating the .htaccess file in the phpMyAdmin directory, we have to edit the phpMyAdmin virtualhost file in apache directory to allow config overrides from an .htaccess file. Go to the "/etc/apache2/conf.d/" directory and edit the phpMyAdmin.conf file with vim:

cd /etc/apache2/conf.d/
vim phpMyAdmin.conf

in line 3, change "AllowOverride None" to "AllowOverride all":

AllowOverride all

Save and exit.

Next, go to the phpMyAdmin web directory and create a new htaccess file:

cd /srv/www/htdocs/phpMyAdmin/
vim .htaccess

paste the configuration below:

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /etc/phpMyAdmin/.htpasswd
Require valid-user

Save and exit.


AuthType = Type of authentication method used by a user, common method usage is Basic which is implement by mod_auh_basic.

AuthName = Directive auth name.

AuthUserFile = Directory of .htpasswd file on "/etc/phpMyAdmin/.htpasswd"

Require valid-user = Tell the .htaccess to only give access the restricted directory to the user on .htpasswd file.

Next, restart the apache2 service and configure the password and user:

systemctl restart apache2

To allow a user accessing the phpMyAdmin page, we have to define the user in the .htpasswd file. Generate the user with an encrypted password with htpasswd command:

htpasswd -c /etc/phpMyAdmin/.htpasswd megumi

The command will create a new user "megumi" that is allowed to access the phpMyAdmin page. The "-c" option is used to create a new .htpasswd file, so if we want to add another user, we can use htpasswd without -c option:

htpasswd /etc/phpMyAdmin/.htpasswd yuki

The htpasswd command

Now in the web browser, type the phpMyAdmin url and you will be asked for the user and password from the .htpasswd file.

phpmyadmin login secured with htpasswd.

Type in the username and password and press Login so you can log in to the phpMyAdmin.

The phpmyadmin login page.

Now type in the MySQL username and password and login. You can see the phpMyAdmin dashboard.

The phpmyadmin dashboard

Now the LAMP Stack with phpMyAdmin is installed on openSUSE Leap 42.1.


Share this page:

5 Comment(s)