LLMP Stack

How To Install Linux, Lighttpd, MySQL, and PHP (LLMP Stack) on CentOS

Welcome back to the Greenhost.cloud blog! In today’s post, we’ll guide you through the process of setting up a LLMP stack (Linux, Lighttpd, MySQL, and PHP) on a CentOS server. This is a powerful combination for hosting dynamic websites and applications. Let’s get started!

Prerequisites

Before we dive into the installation process, ensure you have the following prerequisites:

  1. A CentOS Server: You can use CentOS 7 or 8.
  2. Root Access: You need to have root or sudo privileges to install software.
  3. Basic Command Line Knowledge: Familiarity with terminal commands will be helpful.

Step 1: Update Your System

First, log into your CentOS server via SSH. Once logged in, update your system to make sure all packages are current. Run the following command:

sudo yum update -y

Step 2: Install Lighttpd

Lighttpd is a lightweight web server that is known for its speed and efficiency. To install it, execute the following commands:

sudo yum install epel-release -y
sudo yum install lighttpd -y

After the installation is complete, start the Lighttpd service and enable it to start on boot:

sudo systemctl start lighttpd
sudo systemctl enable lighttpd

You can verify that Lighttpd is running by accessing your server’s IP address in a web browser. You should see the Lighttpd default page.

Step 3: Install MySQL (MariaDB)

Next, we’ll install MariaDB, which is a drop-in replacement for MySQL. To install it, run:

sudo yum install mariadb-server -y

Start the MariaDB service and enable it to start on boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

To secure your MariaDB installation, run the following command:

sudo mysql_secure_installation

Follow the prompts to set the root password and secure your installation. This is an important step to protect your database server.

Step 4: Install PHP

Now it’s time to install PHP and the necessary extensions. You can do this by running the following command:

sudo yum install php php-mysqlnd php-fpm -y

After installation, you need to configure Lighttpd to work with PHP. Open the Lighttpd configuration file:

sudo nano /etc/lighttpd/lighttpd.conf

Add the following lines to enable PHP:

server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" => (( "socket" => "/tmp/php.socket",
                                "bin-path" => "/usr/bin/php-cgi",
                                "max-procs" => 1,
                                "check-local" => "disable",
                                "bin-environment" => (
                                    "PHP_FCGI_CHILDREN" => "4",
                                    "PHP_FCGI_MAX_REQUESTS" => "1000"
                                ),
                                "processes" => 1
                              )
                          )
                    )

Save and exit the editor (in nano, press CTRL + X, then Y, and Enter).

Next, restart Lighttpd to apply the changes:

sudo systemctl restart lighttpd

Step 5: Test PHP

To test if PHP is working with Lighttpd, create a new PHP file in the web root directory:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now, navigate to http://your_server_ip/info.php in your web browser. If everything is set up correctly, you should see the PHP information page.

Step 6: Clean Up

For security reasons, it’s good practice to remove the info.php file after testing:

sudo rm /var/www/html/info.php

Conclusion

Congratulations! You have successfully installed a LLMP stack (Linux, Lighttpd, MySQL, and PHP) on your CentOS server. This stack is great for hosting dynamic websites and applications efficiently.

Don’t forget to check back for more tutorials and tips on optimizing your hosting environment.

Happy hosting with Greenhost.cloud!