- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Install Lighttpd with PHP and MariaDB on RockyAlmaLinux
Introduction
RockyAlmaLinux is a robust and secure Linux distribution that serves as a perfect replacement for CentOS. If you're looking to set up a web server environment using Lighttpd, PHP, and MariaDB. This article will guide you through the installation process. We'll provide detailed instructions along with examples and the expected output of each command.
Prerequisites
Before we begin, make sure you have administrative access to your RockyAlmaLinux system and an active internet connection.
Step 1: Update the System
First, let's update the system's package repositories and upgrade the installed packages to their latest versions. Open a terminal and run the following command −
Example
sudo dnf update
Output
$ sudo dnf update Last metadata expiration check: 0:20:47 ago on <date> Dependencies resolved. ================================================================================ Package Arch Version Repo Size ================================================================================ Upgrading: kernel x86_64 5.14.12-300.fc35 updates 10 M kernel-core x86_64 5.14.12-300.fc35 updates 21 M kernel-devel x86_64 5.14.12-300.fc35 updates 17 M kernel-headers x86_64 5.14.12-300.fc35 updates 5.2 M kernel-modules x86_64 5.14.12-300.fc35 updates 32 M kernel-modules-extra x86_64 5.14.12-300.fc35 updates 4.7 M ... Transaction Summary ================================================================================ Upgrade 21 Packages Total download size: 103 M Is this ok [y/N]: y ... Downloading Packages: [SKIPPED] kernel-5.14.12-300.fc35.x86_64.rpm: Already downloaded ... Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: kernel-core-5.14.12-300.fc35.x86_64 1/7 Upgrading : kernel-core-5.14.12-300.fc35.x86_64 1/7 Running scriptlet: kernel-5.14.12-300.fc35.x86_64 2/7 Upgrading : kernel-5.14.12-300.fc35.x86_64 2/7 Running scriptlet: kernel-headers-5.14.12-300.fc35.x86_64 3/7 Upgrading : kernel-headers-5.14.12-300.fc35.x86_64 3/7 Running scriptlet: kernel-modules-5.14.12-300.fc35.x86_64 4/7 Upgrading : kernel-modules-5.14.12-300.fc35.x86_64 4/7 ... Complete!
Step 2: Install Lighttpd
Next, we'll install the Lighttpd web server. Execute the following command in the terminal −
Example
sudo dnf install lighttpd
Output
Last metadata expiration check: 0:15:01 ago on <date> Dependencies resolved. ================================================================================ Package Architecture Version Repo Size ================================================================================ Installing: lighttpd x86_64 1.4.59-1.fc34 updates 439 k Installing dependencies: libattr x86_64 2.4.48-7.fc34 fedora 29 k libev x86_64 4.33-1.fc34 fedora 70 k ... Transaction Summary ================================================================================ Install 6 Packages Total download size: 791 k Installed size: 2.1 M Is this ok [y/N]: y ... Downloading Packages: (1/6): libattr-2.4.48-7.fc34.x86_64.rpm 187 kB/s | 29 kB 00:00 (2/6): libev-4.33-1.fc34.x86_64.rpm 479 kB/s | 70 kB 00:00 ... Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : libev-4.33-1.fc34.x86_64 1/6 Installing : libattr-2.4.48-7.fc34.x86_64 2/6 Running scriptlet: lighttpd-1.4.59-1.fc34.x86_64 3/6 Installing : lighttpd-1.4.59-1.fc34.x86_64 3/6 Running scriptlet: lighttpd-1.4.59-1.fc34.x86_64 3/6 Running scriptlet: lighttpd-1.4.59-1.fc34.x86_64 4/6 Running scriptlet: lighttpd-1.4.59-1.fc34.x86_64 5/6 Running scriptlet: lighttpd-1.4.59-1.fc34.x86_64 6/6 Verifying : libattr-2.4.48-7.fc34.x86_64 1/6 Verifying : libev-4.33-1.fc34.x86_64 2/6 Verifying : lighttpd-1.4.59-1.fc34.x86_64 3/6 Installed products updated. ... Complete!
Step 3: Start and Enable Lighttpd
Once Lighttpd is installed, start the service and enable it to start automatically on system boot. Enter the following commands −
Example
sudo systemctl start lighttpd sudo systemctl enable lighttpd
Output
$ sudo systemctl enable lighttpd Created symlink /etc/systemd/system/multi-user.target.wants/lighttpd.service → /usr/lib/systemd/system/lighttpd.service.
Step 4: Install PHP
Lighttpd requires PHP to process dynamic content. Install PHP and its necessary modules using the following command −
Example
sudo dnf install php php-fpm php-mysqlnd
Output
Last metadata expiration check: 0:15:01 ago on <date> Dependencies resolved. ================================================================================ Package Architecture Version Repo Size ================================================================================ Installing: php x86_64 7.4.26-1.fc35 updates 3.3 M php-fpm x86_64 7.4.26-1.fc35 updates 1.7 M php-mysqlnd x86_64 7.4.26-1.fc35 updates 195 k Installing dependencies: ... Transaction Summary ================================================================================ Install 3 Packages Total download size: 5.7 M Installed size: 23 M Is this ok [y/N]: y ... Downloading Packages: (1/3): php-7.4.26-1.fc35.x86_64.rpm 459 kB/s | 3.3 MB 00:07 (2/3): php-fpm-7.4.26-1.fc35.x86_64.rpm 178 kB/s | 1.7 MB 00:09 (3/3): php-mysqlnd-7.4.26-1.fc35.x86_64.rpm 150 kB/s | 195 kB 00:01 ... Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : php-7.4.26-1.fc35.x86_64 1/3 Installing : php-fpm-7.4.26-1.fc35.x86_64 2/3 Installing : php-mysqlnd-7.4.26-1.fc35.x86_64 3/3 Running scriptlet: php-mysqlnd-7.4.26-1.fc35.x86_64 3/3 Verifying : php-7.4.26-1.fc35.x86_64 1/3 Verifying : php-fpm-7.4.26-1.fc35.x86_64 2/3 Verifying : php-mysqlnd-7.4.26-1.fc35.x86_64 3/3 Installed products updated. ... Complete!
Step 5: Configure PHP for Lighttpd
To integrate PHP with Lighttpd, we need to configure the FastCGI process manager. Open the PHP-FPM configuration file using a text editor −
sudo nano /etc/php-fpm.d/www.conf
Locate the line that starts with listen =, and change it to the following −
listen = /var/run/php-fpm/php-fpm.sock
Save the changes and exit the text editor.
Step 6: Start and Enable PHP-FPM
Start the PHP-FPM service and enable it to launch on system boot by executing the following commands −
sudo systemctl start php-fpm sudo systemctl enable php-fpm
Step 7: Install MariaDB
MariaDB is a popular open-source relational database management system. Install it using the following command −
Example
sudo dnf install mariadb-server
Output
$ sudo dnf install mariadb-server Last metadata expiration check: 0:15:01 ago on <date> Dependencies resolved. ================================================================================ Package Architecture Version Repo Size ================================================================================ Installing: mariadb-server x86_64 10.6.5-1.fc35 updates 19 M Installing dependencies: mariadb-connector-c x86_64 3.1.14-1.fc35 updates 215 k mariadb-server-utils x86_64 10.6.5-1.fc35 updates 736 k perl-DBI x86_64 1.643-1.fc35 updates 803 k ... Transaction Summary ================================================================================ Install 5 Packages Total download size: 23 M Installed size: 116 M Is this ok [y/N]: y ... Downloading Packages: (1/5): mariadb-server-10.6.5-1.fc35.x86_64.rpm 485 kB/s | 19 MB 00:40 (2/5): mariadb-connector-c-3.1.14-1.fc35.x86_64.rpm 149 kB/s | 215 kB 00:01 ... Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : perl-DBI-1.643-1.fc35.x86_64 1/5 Running scriptlet: perl-DBI-1.643-1.fc35.x86_64 1/5 Installing : mariadb-connector-c-3.1.14-1.fc35.x86_64 2/5 Installing : mariadb-server-utils-10.6.5-1.fc35.x86_64 3/5 Installing : mariadb-server-10.6.5-1.fc35.x86_64 4/5 Running scriptlet: mariadb-server-10.6.5-1.fc35.x86_64 4/5 Running scriptlet: mariadb-server-10.6.5-1.fc35.x86_64 5/5 Verifying : mariadb-connector-c-3.1.14-1.fc35.x86_64 1/5 Verifying : mariadb-server-10.6.5-1.fc35.x86_64 2/5 Verifying : mariadb-server-utils-10.6.5-1.fc35.x86_64 3/5 Verifying : perl-DBI-1.643-1.fc35.x86_64 4/5 Installed products updated. ... Complete!
Step 8: Start and Enable MariaDB
Start the MariaDB service and enable it to run at system startup. Enter the following commands −
sudo systemctl start mariadb sudo systemctl enable mariadb
Step 9: Secure MariaDB Installation
It is essential to secure your MariaDB installation by running the following command −
Example
sudo mysql_secure_installation
Output
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 you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. Set 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!
Step 10: Test the Setup
To verify that Lighttpd, PHP, and MariaDB are working correctly, create a PHP file with some code and access it through a web browser.
Create a new file named info.php in the default web directory −
sudo nano /var/www/html/info.php
Add the following lines to the file −
<?php phpinfo(); ?>
Save the file and exit the text editor.
Step 11: Access the PHP Info Page
Open a web browser and enter your server's IP address or hostname followed by /info.php. For example, http://your_server_ip/info.php. You should see a page displaying detailed information about your PHP installation.
Conclusion
Congratulations! You have successfully installed Lighttpd, PHP, and MariaDB on RockyAlmaLinux. This setup provides a powerful foundation for hosting websites and web applications. Feel free to explore the various configuration options and adapt the setup to meet your specific requirements. Happy web serving!