Share on Social Media

Learn step-by-step instructions to install LAMP server on Rocky Linux 9. Get your web development environment up and running smoothly with this comprehensive guide. #centlinux #linux #apache #mysql

What is LAMP Server?

A LAMP server is a software stack commonly used for web development and hosting. It consists of four key components:

  1. Linux: The operating system (OS) that serves as the foundation for the server. Linux is known for its stability, security, and open-source nature.
  2. Apache: The web server software that processes and delivers web content to users’ browsers. Apache is highly configurable and supports various features like virtual hosting and SSL encryption.
  3. MySQL: A relational database management system (RDBMS) that stores and manages the website’s data. MySQL is widely used for its reliability, scalability, and ease of use.
  4. PHP: A server-side scripting language used for developing dynamic web pages and web applications. PHP is integrated with the web server to generate dynamic content based on user requests.

Together, these components provide a powerful and flexible environment for hosting dynamic websites and web applications on a Linux server.

To understand the nuts and bolts of the most popular web server, we highly recommend that you should attend online training: Apache Web Servershow?id=oLRJ54lcVEg&bids=1060093

Environment Specification:

We are using a minimal Rocky Linux 9 server with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – Rocky Linux release 9.1 (Blue Onyx)
  • Hostname – lamp-01.centlinux.com
  • IP Address – 192.168.88.137/24

Prepare your Rocky Linux Server:

Use a ssh client and login to your Linux server as root user.

Set a hostname and configure Local DNS resolver for your Linux machine.

# hostnamectl set-hostname lamp-01.centlinux.com
# echo "192.168.88.137 lamp-01.centlinux.com lamp-01" >> /etc/hosts

Execute following command to update software packages in your Linux operating system.

# dnf update -y

Sometimes, Linux Kernel or relevant packages may be updated by the above command.

If this happens, then you should reboot your Linux operating system with newly installed Linux Kernel.

# reboot

Check your Linux operating system and Linux Kernel versions.

# cat /etc/rocky-release && uname -r
Rocky Linux release 9.1 (Blue Onyx)
5.14.0-162.18.1.el9_1.x86_64

Install LAMP Server on Rocky Linux:

Here, we are installing Linux LAMP Stack components: Apache, MariaDB and PHP.

All three components are available in standard yum repositories of Rocky Linux 9.

Therefore, you can install all required components of Linux LAMP server by using a single dnf command.

# dnf install -y httpd httpd-tools mariadb-server mariadb php php-cli php-fpm php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Enable and start Apache, PHP and MariaDB services.

# systemctl enable --now httpd php-fpm mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

Set a password for root (database user) and configure your MariaDB server instance as follows.

# mariadb-secure-installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

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

Enter current password for root (enter for none):
OK, successfully used password, moving on...

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

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
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] Y
 ... 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] Y
 ... 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] Y
 - 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] Y
 ... 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!

To verify the installation of MariaDB server, you can login to mysql shell as root user.

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 10.5.16-MariaDB MariaDB Server

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

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> exit
Bye

Verify PHP installation by checking the version of php command.

# php -v
PHP 8.0.27 (cli) (built: Jan  3 2023 16:17:26) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.27, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies

Verify Apache installation by checking the version of httpd command.

# httpd -v
Server version: Apache/2.4.53 (Rocky Linux)
Server built:   Jan 31 2023 00:00:00

You need to create a PHP homepage for your LAMP server. We are using the phpinfo() function, because it generates a long webpage of useful information related to your Linux server and LAMP components.

# echo "<?php phpinfo ();?>" > /var/www/html/index.php

Configure Linux Firewall:

To make your LAMP server accessible from the network, you need to allow the http service in Linux firewall.

# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --reload
success

Access Linux LAMP Server:

After successful configurations, you can access your Linux LAMP server by opening URL http://lamp-01.centlinux.com/ in a web browser.

phpinfo output page
phpinfo output page

Video: LAMP Server Setup on Rocky Linux 9:

YouTube player

Final Thoughts

Embark on your journey to create a robust web development environment by mastering the installation process of a LAMP Server on Linux 9. Empower yourself with the tools and knowledge needed to build dynamic websites and applications seamlessly. Let this guide be your roadmap to harnessing the power of Linux, Apache, MySQL, and PHP for your digital projects. Apache 2 Pocket Reference (PAID LINK) by Andrew Ford is a quick reference book every Apache administrator should have, and we also advise you to keep the same.

Leave a Reply

Your email address will not be published. Required fields are marked *