Lighttpd is a fast, secure, and flexible web server, ideal for handling high-traffic websites and running efficiently with minimal resources. When combined with MariaDB and PHP-FPM, it becomes a powerful solution for web hosting. In this guide, we will walk you through how to install Lighttpd with MariaDB and PHP-FPM on Ubuntu 22.04. Hosting this setup on a WindowsVPS ensures enhanced performance and control over your server, providing scalability with a VPS server tailored for web applications.
Step 1: Update Your VPS Server
Before starting the installation, ensure your VPS server is up to date. Run the following commands to update your system:
sudo apt update && sudo apt upgrade -y
Running your web server setup on a WindowsVPS provides dedicated resources, ensuring high performance, scalability, and stability for your web applications.
Step 2: Install Lighttpd
To begin, install Lighttpd using the following command:
sudo apt install lighttpd -y
Once installed, start and enable Lighttpd to run at boot:
sudo systemctl enable lighttpd --now
You can verify that Lighttpd is running by opening your browser and visiting http://your-server-ip
. You should see the default Lighttpd welcome page.
Step 3: Install MariaDB
MariaDB is an open-source database management system that will store your website's data. Install MariaDB by running the following command:
sudo apt install mariadb-server -y
After installation, secure your MariaDB installation with the following command:
sudo mysql_secure_installation
This script will guide you through securing MariaDB, including setting the root password and removing unnecessary test databases.
Step 4: Install PHP-FPM
PHP-FPM (FastCGI Process Manager) is required to process PHP scripts. Install PHP-FPM and the necessary PHP extensions using the following command:
sudo apt install php-fpm php-mysql php-cli php-curl php-mbstring php-xml -y
Once installed, start PHP-FPM and ensure it runs at boot:
sudo systemctl enable php-fpm --now
Step 5: Configure Lighttpd to Use PHP-FPM
Next, configure Lighttpd to use PHP-FPM for processing PHP files. First, enable the FastCGI and FastCGI-PHP modules:
sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php
Edit the Lighttpd configuration file to ensure PHP-FPM is set up correctly:
sudo nano /etc/lighttpd/lighttpd.conf
Look for the following lines and ensure they are correctly configured:
server.modules = (
"mod_fastcgi",
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite"
)
Save the file and restart Lighttpd for the changes to take effect:
sudo systemctl restart lighttpd
Step 6: Test PHP Processing
To verify that PHP is correctly configured, create a phpinfo()
test file. Navigate to the Lighttpd web root directory:
cd /var/www/html
Create a file called info.php
:
sudo nano info.php
Add the following content:
<?php
phpinfo();
?>
Save and exit the file. Now, open your browser and navigate to http://your-server-ip/info.php
. You should see the PHP information page, confirming that PHP-FPM is working correctly with Lighttpd.
Step 7: Configure MariaDB
To start using MariaDB for your applications, log in to the MariaDB shell:
sudo mysql -u root -p
Once logged in, create a new database and user:
CREATE DATABASE mydatabase;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
This creates a new database named mydatabase
and a user myuser
with full access to the database.
Step 8: Optimize Your VPS Server for Lighttpd
To ensure the best performance and scalability for your Lighttpd server, hosting it on a WindowsVPS is highly recommended. A VPS server provides dedicated CPU, memory, and storage resources, allowing you to handle high-traffic websites and serve dynamic content efficiently. Additionally, VPS hosting gives you the flexibility to scale your server as your website grows.
Conclusion
Installing Lighttpd with MariaDB and PHP-FPM on Ubuntu 22.04 is a powerful solution for hosting dynamic websites. By hosting your setup on a WindowsVPS, you can benefit from improved performance, scalability, and control over your server, ensuring that your web applications run smoothly and efficiently.
For more information about VPS hosting and optimizing your web server, visit WindowsVPS today.