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
Table of Contents
What is LAMP Server?
A LAMP server is a software stack commonly used for web development and hosting. It consists of four key components:
- Linux: The operating system (OS) that serves as the foundation for the server. Linux is known for its stability, security, and open-source nature.
- 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.
- 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.
- 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.
Environment Specification
In this guide, we are working with a minimal installation of Rocky Linux 9, which serves as the foundation for our setup. This lightweight server configuration is optimal for flexibility and efficiency, as it includes only the essential packages needed for operation. Below are the specific details of the system we are using:
- 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
Recommended Training: Apache Web Server from Vipin Gupta
Prepare your Rocky Linux Server
Use a ssh client and login to your Linux server as root user.
To ensure proper network identification and functionality, it’s essential to set a hostname and configure a local DNS resolver on your Linux machine. The hostname uniquely identifies your system within a network, while the local DNS resolver allows your machine to efficiently resolve domain names into IP addresses.
Begin by assigning a meaningful and unique hostname that reflects the machine’s purpose or role in your environment. After setting the hostname, configure your system’s DNS resolver to point to the appropriate DNS server or use localhost for local name resolution. These configurations ensure seamless communication and identification within your network and improve system integration with other devices and services.
# 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
New Amazon Fire HD 8 Kids Pro tablet, ages 6-12. Bright 8″ HD screen, includes ad-free content, parental controls, 13-hr battery, slim case for older kids, 32GB, Discovery (2024 release)
$84.99 (as of January 23, 2025 14:29 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Install LAMP Server on Rocky Linux
In this guide, we focus on installing the essential components of the Linux LAMP Stack: Apache (web server), MariaDB (database server), and PHP (scripting language). These three components form the backbone of a robust, dynamic web server environment.
Fortunately, all these packages are readily available in the standard YUM repositories of Rocky Linux 9, ensuring compatibility and ease of installation. To simplify the process, you can install all the necessary LAMP stack components in one step using a single dnf command. This streamlined approach saves time and ensures that the core components of your LAMP server are installed correctly and efficiently.
# 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
To complete your LAMP server setup, you should create a PHP homepage to test and verify the functionality of your server. A practical choice for this purpose is the phpinfo()
function. This function is particularly useful because it generates a comprehensive webpage containing detailed information about your Linux server and the installed LAMP components, including PHP configuration, loaded modules, environment variables, and much more.
By creating and accessing this PHP homepage, you can confirm that your Apache server is correctly processing PHP scripts and that all components of your LAMP stack are working seamlessly. This step is essential for troubleshooting and ensuring your server’s environment is fully operational.
# echo "<?php phpinfo ();?>" > /var/www/html/index.php
The Complete Guide to Windows Subsystem for Linux 2: Bridging Linux and Windows for AI, IoT, and DevOps
$35.97 (as of January 23, 2025 14:29 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)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
Once all the configurations have been completed successfully, you can test and access your Linux LAMP server by navigating to its URL in a web browser. For instance, you can open http://lamp-01.centlinux.com/ (or your server’s hostname or IP address) to verify that the server is operational. This URL should load the custom PHP homepage. This step confirms that your LAMP stack is correctly installed and running, ensuring the integration of Apache, MariaDB, and PHP is functioning as expected.
Video Tutorial
For a step-by-step walkthrough, consider watching a video tutorial on installing a LAMP server on Rocky Linux 9. Video tutorials provide a visual guide, making it easier to follow along with the installation process, especially for beginners. From setting up the Apache server and configuring MySQL to deploying PHP, a detailed video can help clarify complex steps and ensure you don’t miss critical configurations. Whether you’re new to Linux or simply looking for a practical demonstration, a video tutorial can complement this guide effectively.
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.
Struggling with AWS or Linux server issues? I specialize in configuration, troubleshooting, and security to keep your systems performing at their best. Check out my Fiverr profile for details.