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

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

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 installation. 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.33 (Linux/SUSE)
Server built:   2020-02-25 09:51:10.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 15.1. 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 15.1 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 configuration file. (If you don’t have the following file, it’s probably your OpenSUSE system doesn’t have SuSEfirewall installed. You can install it with: sudo zypper install SuSEfirewall2.)

sudo nano /etc/sysconfig/SuSEfirewall2

Find the following line.

FW_SERVICES_EXT_TCP=""

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

FW_SERVICES_EXT_TCP="80"

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.2.31-MariaDB, for Linux (x86_64) using  EditLine wrapper

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 15.1. 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: 42 Average: 4.8]

15 Responses to “How to Install Apache, MariaDB, PHP7 (LAMP) on openSUSE Leap 15.1

  • Thanks!

  • Augusto Vera
    6 years ago

    Super!, thanks!

  • EduardoCupertino
    6 years ago

    Great article! If somebody knows how to show errors on PHP7 – make a dev machine on Suse – tell me please.

  • Was having massive issues with php7, started over with your instructions and its working better than ever..on Tumbleweed.

  • Super, Danke

  • Cassio Rodrigues
    4 years ago

    Thank you so much!

  • Thanks a lot for taking your time to writing such a wonderful article.

    Can we add other DB with the same process as MariaDB mentioned above like MongoDB, MySQL

    • Xiao Guoan (Admin)
      4 years ago

      You can add other DBs like MongoDB, PostgreSQL, etc. If you add MySQL, you probably need to remove MariaDB.

  • thanks, this tutorial has enabled me to set up lamp on my opensuse leap system

  • thanks bro

  • Legend

  • amo o sistema Linux ,o melhor deste planeta ,rapidez segurança e modernidade ,.muito obrigado

    I love the Linux system, the best on this planet, speed, security, and modernity, thank you very much.

  • rauwolf
    2 years ago

    It works.
    Thank you very much.

  • Yulian Yumarsana
    6 months ago

    Could you add firewalld in firewall information for newer OpenSUSE version?

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