Install LAMP - Apache, PHP, MariaDB and PhpMyAdmin in OpenSUSE


Introduction

The LAMP stack, which stands for Linux, Apache, MySQL/MariaDB, and PHP, is a powerful combination of open-source software widely used for web development and hosting. In this tutorial, we will guide you through the process of installing and configuring the LAMP stack on openSUSE, a popular Linux distribution. We will cover the installation of Apache, PHP, MariaDB, and PhpMyAdmin, providing detailed examples and command outputs to ensure a smooth installation process.

Step 1: Update System Packages

Before we begin, it is essential to update the system packages to ensure that we have the latest software versions and security patches. Open a terminal and execute the following commands −

sudo zypper refresh
sudo zypper update

Step 2: Install Apache

Apache is a widely used web server that serves as the backbone of the LAMP stack. To install Apache, execute the following command −

Example

sudo zypper install apache2

Output

Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  apache2

1 new package to install.
Overall download size: XXX MiB. Already cached: 0 B. After the operation, additional XXX MiB will be used.
Continue? [y/n/...? shows all options] (y):

Retrieving package apache2-2.x.x-x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x

Once the installation is complete, start and enable the Apache service using the following commands −

sudo systemctl start apache2
sudo systemctl enable apache2

Output

$ sudo systemctl start apache2
[sudo] password for user:
Starting apache2.service...

$ sudo systemctl enable apache2
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /usr/lib/systemd/system/apache2.service.

Step 3: Install PHP

PHP is a popular scripting language used for web development. To install PHP and its required dependencies, run the following command −

Example

sudo zypper install php7 php7-mysql apache2-mod_php7

Output

$ sudo zypper install php7 php7-mysql apache2-mod_php7
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 3 NEW packages are going to be installed:
  apache2-mod_php7 php7 php7-mysql

3 new packages to install.
Overall download size: XXX MiB. Already cached: XXX MiB. After the operation, additional XXX MiB will be used.
Continue? [y/n/...? shows all options] (y):

Retrieving package apache2-mod_php7-XXX...
Retrieving package php7-XXX...
Retrieving package php7-mysql-XXX...
Installing package apache2-mod_php7-XXX...
Installing package php7-XXX...
Installing package php7-mysql-XXX...

Checking for file conflicts: [done]
(1/3) Installing: apache2-mod_php7-XXX..................................................................[done]
(2/3) Installing: php7-XXX....................................................................................[done]
(3/3) Installing: php7-mysql-XXX..............................................................................[done]

Additional rpm output:
...
...
...

Installation of packages was successful.

Step 4: Install MariaDB

MariaDB is a drop-in replacement for MySQL and provides a powerful and robust relational database management system. Install MariaDB using the following command −

Example

sudo zypper install mariadb mariadb-client

Output

Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 2 NEW packages are going to be installed:
  mariadb mariadb-client

2 new packages to install.
Overall download size: 150.1 MiB. Already cached: 0 B. After the operation, additional 672.9 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
...
Retrieving package mariadb-10.6.5-2.1.x86_64 (1/2), 140.6 MiB (373.7 MiB unpacked)
Retrieving: mariadb-10.6.5-2.1.x86_64.rpm ..........................................................................................................................[done]
Retrieving package mariadb-client-10.6.5-2.1.x86_64 (2/2), 9.5 MiB (299.3 MiB unpacked)
Retrieving: mariadb-client-10.6.5-2.1.x86_64.rpm ...................................................................................................................[done]
...
Checking for file conflicts: .................................................................................................................................[done]
(1/2) Installing: mariadb-10.6.5-2.1.x86_64 ..............................................................................................................................[done]
(2/2) Installing: mariadb-client-10.6.5-2.1.x86_64 ...................................................................................................................[done]
...
Executing post-install scripts.....................................................................................................................................[done]
Additional rpm output:
  Installing MySQL system tables...
  OK
  Filling help tables...
  OK
  ...

Start and enable the MariaDB service by executing the following commands −

Example

sudo systemctl start mariadb
sudo systemctl enable mariadb

Output

$ sudo systemctl start mariadb
[sudo] password for user:
$ sudo systemctl enable mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

To secure your MariaDB installation, run the security script and follow the prompts −

Example

sudo mysql_secure_installation

Output

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a Unix socket.

MySQL server found running with a Unix socket at /var/run/mysqld/mysqld.sock. Continue with the MySQL secure installation? [Y/n] Y

Please enter the MySQL root password: 
Validating password...

The existing password for the user account root has expired. Please set a new password.

New password:
Re-enter new password:

Estimated strength of the password: 100 
Do you wish to continue with the password provided? [Y/n] Y

Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

All done! MySQL should now be secured.

Step 5: Install PhpMyAdmin

PhpMyAdmin is a web-based interface used to manage MySQL/MariaDB databases. Install PhpMyAdmin by running the following command −

sudo zypper install phpMyAdmin

During the installation process, you will be prompted to choose the webserver. Select "apache2" and press Enter. Then, choose "yes" to configure the database for phpMyAdmin.

Step 6: Configure Apache for PhpMyAdmin

To configure Apache to recognize PhpMyAdmin, open the configuration file in a text editor −

sudo nano /etc/apache2/conf.d/phpMyAdmin.conf

Replace the line Require ip 127.0.0.1 with Require all granted. Save and close the file.

Step 7: Restart Apache

Restart the Apache service for the changes to take effect −

sudo systemctl restart apache2

Step 8: Access PhpMyAdmin

Open a web browser and enter the following URL: http://localhost/phpMyAdmin. You should see the PhpMyAdmin login page. Use your MariaDB root username and password to log in.

Congratulations! You have successfully installed LAMP - Apache, PHP, MariaDB, and PhpMyAdmin on openSUSE. You are now ready to start developing and hosting web applications.

Conclusion

Setting up a LAMP stack on openSUSE is a straightforward process that allows you to harness the power of open-source software for web development. By following the steps outlined in this article, you have acquired a strong foundation to build and deploy your web applications. Enjoy exploring the endless possibilities that the LAMP stack offers!

Updated on: 17-Jul-2023

698 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements