This wiki was updated to MediaWiki 1.37. If you notice any issues, please report them to admin[at]

SDB:LAMP setup

Jump to: navigation, search

This page describes how to install LAMP, which stands for Linux Apache MariaDB PHP. For this purpose, you need to set up:
  • a working Apache2 webserver;
  • a configured MariaDB database server;
  • PHP7 (or PHP5) for work with Apache; and finally
  • phpMyAdmin with a configured pmadb database.
The needed time for the whole installation is around 20 minutes but it may depend on the performance of your Internet connection.

This article is updated to reflect the installation in currently supported openSUSE Leap and Tumbleweed. However it does not deviate much from lower versions of openSUSE.

Getting root access

To get root access, open a terminal and enter the following command:

user $ su -

After entering a valid password, the prompt should turn red and end with a #.


Webserver setup and configuration.

Installing Apache2

First of all, make sure you have root access and enter the following command:

zypper in apache2

Starting Apache2

To start the apache server, enter the following command:

systemctl start apache2
If you ever want to restart the apache server, use:
systemctl restart apache2

or if you want to stop it

systemctl stop apache2

To automatically start the apache server after a reboot:

systemctl enable apache2

Testing the installation

To check if you apache server works, use you favorite text editor "as root" and create an index.html file in the /srv/www/htdocs/ folder with the following content:

<html><body><h1>Welcome to my web site!</h1></body></html>

Now point your favorite Web browser to: 'localhost'. You should see a page with Welcome to my web site! as a headline.

If you get an error, then make sure that you are loading the page with "http" and not "https".


Enabling public access to the web server

In this state the web server is only accessible as localhost. If you want to give access to it from a remote host, you have to open port http (=80) in the firewall. There are two firewalls common on SuSE distributions, SuSEfirewall2 and Firewalld which are treated in separate sections below.


To do this, edit the /etc/sysconfig/SuSEfirewall2 file and change the line



A space should separate elements in that line

After editing you have to restart the firewall using:

systemctl restart SuSEfirewall2
Alternatively, you can do this using YaST and selecting Security and Users --> Firewall --> Allowed services and add HTTP server.


As root execute this. Note that this assumes that the zone you have configured is public. Replace public with your zone you have selected.

firewall-cmd --zone=public --add-port=80/tcp --permanent

Once you add the firewall rule reload firewall service.

firewall-cmd --reload


Alternatively, you can use the graphic user interface through YaST

  • Open the YaST Control Center
YaST can be used on the command line as:
  • Select Firewall
  • The Configuration for modification defaults under Runtime. Any changes you make will only affect the current Runtime of the machine
  • Note the Zone that the network is running and ensure that the current zone is selected under the Zones tab.
  • In the Services tab, locate apache2 in the window.
  • If you would like to make this change permanent under the selected Zone, select Options > Runtime to Permanent
  • If no further changes to the firewall are required, close the Configuration window, changes are immediate.

Setting up PHP

Installing PHP7

Make sure you have root access — see above. Install php7 using:

zypper in php7 php7-mysql apache2-mod_php7

Don't forget to enable mod-php by executing:

a2enmod php7

In addition, ensure that in `/etc/apache2/mod_mime-defaults.conf` there is a line

AddType application/x-httpd-php .php

which makes apache treating files with ending `.php` with the correct mime-type, i.e. as php-sources.

Your are done, php7 is now installed.

To be sure, check by executing

php -v

which shall return the version.

Installing PHP5

If instead you want to install PHP5, the steps are the same as above with 'php5' instead of 'php7':

zypper in php5 php5-mysql apache2-mod_php5
a2enmod php5

By need in `/etc/apache2/mod_mime-defaults.conf` add a line

AddType application/x-httpd-php .php
php -v

to check that installation is correct.

Note you need to choose if to install php7 or php5. You cannot have both of them.

Restarting the webserver

Now that you have installed php, you have to restart the apache2 webserver:

systemctl restart apache2

Testing the installation

To verify that php is properly working, create a `index.php` file into the `/srv/www/htdocs/` folder with the following content:


Now, point your browser to 'localhost/index.php'. You should see a page containing a table with all php settings displayed.


Setting up MariaDB

MariaDB is an alternative package for MySQL, so further on the name mysql is used.

For documentation see

Installing MariaDB

Make sure you have root access — see above. We need to install mariadb and mariadb-tools:

zypper in mariadb mariadb-tools
The package mariadb-tools is necessary for administration

Starting the MariaDB server

To start the MariaDB server, execute:

systemctl start mysql
If you want to read the messages issued by the server cat the /var/log/messages.
cat /var/log/messages|less

Ensure that the server will start at every boot:

systemctl enable mysql
If you ever want to restart mysql, execute
systemctl restart mysql

or if you want to stop it

systemctl stop mysql

Configuring the MariaDB/MySql server

To configure the MariaDB server with improved security, please use the script 'mysql_secure_installation provided by openSUSE. Hereafter is the description of the full process.

root # mysql_secure_installation


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 you haven't set the root password yet, the password will be blank, so you should just press enter here.

Enter current password for root (enter for none):

Just press Enter here.

root #
... (output sequel of previous command)

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation.

Set root password? [Y/n] y

Just enter y here.

root #
... (output sequel of previous command)

New password:

Enter the password for root now. (MariaDb seems to reject special characters in passwords. If you use a password generator, restrict it to Alpha-Numeric characters)

root #
... (output sequel of previous command)

Re-enter new password:

Enter the password confirmation.

root #
... (output sequel of previous command)

Password updated successfully!

Reloading privilege tables.. ... Success! 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]

Answer y to remove anonymous users.

root #
... (output sequel of previous command)

... 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]

Answer y now.

root #
... (output sequel of previous command)

... 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]

Answer y.

root #
... (output sequel of previous command)

- 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]

Answer y.

root #
... (output sequel of previous command)

... 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!

For memory in older versions

Replacing <NEW PASSWORD> with the value of the new password your want to define, execute:

root # mysqladmin -u root password '<NEW PASSWORD>'

Enter the present password or press only Enter if it has never been defined.

Logging in to the client

Now you can log in into the server client by executing

root # mysql -u root -p
Enter password:

Then give your password.

root #
... (output sequel of previous command)

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 154 Server version: 10.0.22-MariaDB openSUSE package

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

To go back to the terminal, execute:

MariaDB [(none)]> exit

Installing phpMyAdmin

What is phpMyAdmin?

phpMyAdmin — a.k.a. pma — is a tool to administrate your databases from a Web interface written in php.

Installing phpMyAdmin

To install phpMyAdmin execute:

root # zypper in phpMyAdmin

This also installs a number of needed php modules and restarts the apache2 server.

Defining Admin User for phpMyAdmin

From mysql 5.7 and mariadb 10.4 on, one cannot use 'root' login with default authentication method. One solution is to create a new admin user for the database just for phpMyAdmin. To that end proceed in the following steps.

Login into mariadb

mysql -p -u root

Create user via which uses

> CREATE USER 'pmaUser'@localhost IDENTIFIED BY 'pma';

or more explicit with

> CREATE USER 'pmaUser'@localhost IDENTIFIED WITH mysql_native_password AS PASSWORD('pma');

Grant privileges via

> GRANT ALL PRIVILEGES ON *.* TO 'pmaUser'@localhost;

To check the result type

> SELECT User, password FROM mysql.user;

This yields a table of users with passwords. Note that password of `pmaUser` is encrypted.

Logging into phpMyAdmin

To log in to phpMyAdmin:

Normally you should get an error message complaining about the lack of the Multibytes String extension. That is the object of the next section.

Checking phpMyAdmin

Now point your browser at http://localhost/phpMyAdmin/ or http://ip_address/phpMyAdmin/ and enter the mysql root username and its passord. In newer versions of mariadb or mysql root is no longer possible and one has to user a special user `pmaUser` as described above.


That's all! You can now administer your databases from a Web interface. Logout icon is the small second after `phpMyAdmin` headline.

You can read the documentation on phpMyAdmin on the phpMyAdmin website.

You should have a working LAMP server now!