In the current digital age, deploying a web server that is both efficient and straightforward to manage is crucial for developers and system administrators. The Caddy web server, renowned for its simplicity and automatic HTTPS, combined with PHP 8.1, provides a powerful platform for developing and running web applications. This detailed guide will take you through the process of installing Caddy Web Server with PHP 8.1 on Rocky Linux 9, aiming to be easily understandable for newcomers while offering depth for more seasoned users.
Step 1: System Update
Ensuring your system is up-to-date is vital for security and stability. Begin by updating your Rocky Linux system with the following command:
sudo dnf update -y
This command refreshes your system’s package index and updates all your system’s packages to their latest versions.
Step 2: Install Caddy
Caddy is not included in the default Rocky Linux repositories, but installation is straightforward. Execute the following commands to add the official Caddy repository and install Caddy:
sudo dnf install -y 'dnf-command(copr)'
sudo dnf copr enable @caddy/caddy
sudo dnf install caddy -y
These commands enable the Caddy COPR repository and install the latest version of the Caddy web server.
Step 3: Start and Enable Caddy
With Caddy installed, the next step is to start and enable it to ensure it runs on boot:
sudo systemctl enable --now caddy
You can verify that Caddy is running smoothly with:
sudo systemctl status caddy
Look for an active (running) status in the output.
Step 4: Install PHP 8.1
PHP 8.1 introduces several new features and performance improvements. Install PHP 8.1 and the necessary extensions with the following command:
sudo dnf module reset php
sudo dnf module enable php:8.1
sudo dnf install php php-fpm php-cli php-common -y
This series of commands ensures that PHP 8.1 is selected and installs PHP along with common extensions that are typically required for web development.
Step 5: Configure PHP-FPM
PHP-FPM (FastCGI Process Manager) is crucial for handling PHP content. Start by enabling and starting PHP-FPM:
sudo systemctl enable --now php-fpm
Next, configure PHP-FPM to communicate with Caddy. Edit the PHP-FPM pool configuration (typically located at /etc/php-fpm.d/www.conf) to listen on a Unix socket:
Change the line:
;listen = 127.0.0.1:9000
To:
listen = /run/php-fpm/www.sock
Then, restart PHP-FPM to apply the changes:
sudo systemctl restart php-fpm
Step 6: Configure Caddy to Serve PHP Applications
Now, configure Caddy to handle PHP requests by editing its configuration file (/etc/caddy/Caddyfile). Add or modify the file to include the following:
your_domain.com {
root * /var/www/your_site
php_fastcgi unix//run/php-fpm/www.sock
file_server
}
Replace your_domain.com with your domain name and /var/www/your_site with the path to your website’s root directory.
Step 7: Restart Caddy
Apply the configuration changes by restarting Caddy:
sudo systemctl restart caddy
Your Caddy server is now configured to serve PHP applications using PHP 8.1.
Integrating with Shape.host Services
After setting up Caddy with PHP 8.1 on Rocky Linux 9, consider leveraging Shape.host Cloud VPS services to deploy your web applications. Shape.host offers scalable, high-performance Cloud VPS solutions that complement the speed and efficiency of the Caddy web server. With Shape.host, you benefit from robust security features, SSD storage for high-speed data access, and scalable resources to match your application’s growth. Whether hosting a small project or a large-scale application, Shape.host provides the reliability and performance your online presence demands.