How to Install Apache, MariaDB, PHP7 (LAMP) on openSUSE Leap 42.2

In this tutorial, we’re going to look at how to install Apache, MariaDB, PHP7 (LAMP stack) with phpMyAdmin on openSUSE Leap 42.2.

Step 1: Update Software

Before installing any software, it’s always a good idea to update repository and software packages.

sudo zypper update

Step 2: Install Apache Web Server

Install Apache on openSUSE using the following command.

sudo zypper install apache2

By default, Apache will not automatically start after installed. You can start it with:

sudo systemctl start apache2

And enable auto start at boot time with:

sudo systemctl enable apache2

Check its status:

systemctl status apache2

opensuse apache

We can see from the screenshot that Apache is running and auto start enabled.

Check Apache version:

sudo httpd -v

Output:

Server version: Apache/2.4.23 (Linux/SUSE) 
Server built:   2016-09-13 13:41:45.000000000 +0000

Now create index.html file under the document root.

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

Put the following text into the file.

<html> 
<body> 
  <h1> It works!</h1> 
</body> 
</html>

Save and close the file. Then in your browser’s address bar, type the IP address of openSUSE Leap 42.2. You should see the “It works!” Web page which means Apache Web server is running correctly.

If you are installing LAMP on your local openSUSE Leap 42.2 machine, just type 127.0.0.1 or localhost in the browser address bar.

install apache on opensuse leap 42.2

By default the SuSE firewall prohibit public access to port 80. To allow public access, you need to edit the firewall configurations.

sudo nano /etc/sysconfig/SuSEfirewall2

Find the following line.

FW_CONFIGURATIONS_EXT=""

Change it to the following to allow public access to port 80.

FW_CONFIGURATIONS_EXT="apache2"

Save and close the file. Then restart SuSE firewall.

sudo systemctl restart SuSEfirewall2

Finally, we need to make wwwrun (Apache user) as the owner of Document root.

sudo chown wwwrun /srv/www/htdocs/ -R

Step 3: Install MariaDB

Install MariaDB server and client on openSUSE Leap using the following command.

sudo zypper install mariadb mariadb-client mariadb-tools

By default, MariaDB won’t start automatically after installed. We can start it with:

sudo systemctl start mysql

And enable auto start at boot time with:

sudo systemctl enable mysql

Check its status:

systemctl status mysql

opensuse leap 42.2 mariadb

We can see from the screenshot that MariaDB is running and auto start enabled.

Check MariaDB version:

mysql --version

Output:

mysql  Ver 15.1 Distrib 10.0.28-MariaDB, for Linux (x86_64) using readline 5.1

Now any user on the system can log into MariaDB as root with the following command:

mysql -u root

To restrict access, we need to set a password for the MariaDB root user. Run the following command:

sudo mysql_secure_installation

When it asks you to enter MariaDB root password, press Enter because you have not set the root password yet. Then enter y to set the root password for MariaDB server.

opensuse leap 42.2 mysql_secure_installation

Next you can just press Enter to answer all the remaining questions. This will remove anonymous user, disable remote root login and remove test database. This step is a basic requirement for MariaDB database security.

install mariadb opensuse leap 42.2

Now you can log into MariaDB with the following command

mysql -u root -p

Step 4: Install PHP7

Enter the following command to install PHP7 and PHP7 extensions.

sudo zypper install php7 php7-mysql apache2-mod_php7

Then enable PHP module and restart Apache web server.

sudo a2enmod php7

sudo systemctl restart apache2

Step 5: Test PHP

Create a test.php file in document root.

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

Paste the following PHP code into the file.

<?php phpinfo(); ?>

Save and close the file. Now in the browser address bar, enter server-ip-address/test.php. Replace sever-ip-address with your actual IP. If you follow this tutorial on your local computer, then type 127.0.0.1/test.php or localhost/test.php.

You should see your server’s PHP information. This means PHP processing is fine.

opensuse leap 42.2 php7

For your server’s security, you should delete test.php file now.

Step 6: Install phpMyAdmin (optional)

phpMyAdmin is a web-based MySQL/MariaDB administration tool. If you don’t want to administrate MariaDB from command line, then you can install phpMyAdmin with the command below.

sudo zypper install phpMyAdmin

Zypper package manager will automatically install required PHP7 extensions for you. Once it’s installed, restart Apache to enable these PHP7 extensions.

sudo systemctl restart apache2

Then you can visit phpMyAdmin web interface via

your-server-ip/phpMyAdmin

or

localhost/phpMyAdmin

opensuse leap 42.2 phpmyadmin

And login with MariaDB root password.

opensuse leap phpmyadmin php7

Congrats! You have successfully installed Apache, MariaDB and PHP7 on openSUSE Leap 42.2. Subscribe to our free newsletter to get latest Linux tutorials. You can also follow us on Google+Twitter or like our Facebook page.

Rate this tutorial
[Total: 10 Average: 4.4]