Caddy is a modern, open-source web server written in Go that makes serving WordPress on CentOS 7 both fast and secure. Unlike traditional servers, Caddy has native HTTP/2 support, automatic TLS via Let’s Encrypt, and a simple, human-friendly configuration format, so you spend less time wrestling with complex settings and more time building your site.

In this guide, you’ll learn exactly how to set up Caddy as your web server, install and secure a MariaDB database for WordPress, configure PHP-FPM to work with the Caddy user, and deploy a fresh WordPress installation under /var/www/wordpress. By the end, you’ll have a high-performance WordPress stack on CentOS 7 that’s ready for production.Complete with gzip compression, clean URL rewrites, and automated SSL certificates.

Whether you’re a developer seeking better HTTP/2 performance or a site owner tired of manual TLS renewals, following these clear, beginner-friendly steps will have your WordPress site up and running on Caddy in minutes.


Capabilities:

  • Virtual hosting.
  • Native IPv4 and IPv6 support.
  • Serve static files.
  • Graceful restart/reload
  • Reverse proxy.
  • Load balancing with health checks.
  • FastCGI proxy.

Requirments

We are going to need an installed and configured Caddy web server with a “systemd” service, If you don’t have it installed, use the following article:

How to Install Caddy Web server on CentOS 7

If you have all of the prerequisites ready, we can start right away. 

 Install and configure MySQL database

We are going to install MariaDB (an official fork of MySQL database) as our database which is necessary for WordPress:

yum install mariadb-server

After the installation is finished you can go ahead and start the “Secure installation” script for primary configuration:

mysql_secure_installation

Choose a password for “root” user and disallow access for remote login with root user for better security, (you can answer the rest of the questions with “Y”)

Now login with root user to create a database and user for WordPress:

mysql -u root -p create database test; grant all privileges on test.* to 'admin'@'localhost' identified by 'password'; flush privileges; exit

Install and configure PHP and PHP-FPM

In order to install and run WordPress, we need to have PHP installed can integrate with Caddy, Also WordPress is depended on some PHP extensions which we will install it with the command below:

yum install php php-fpm php-mbstring php-gd php-xml php-curl php-mcrypt

As soon as the installation process is complete run the following commands to start the “php-fpm” service and make it run as startup:

systemctl start php-fpm systemctl enable php-fpm

We need to make some changes to PHP-FPM because by default only Apache can use it, So open the following file with your text editor:

nano /etc/php-fpm.d/www.conf

Find the following lines:

user = apache
; RPM: Keep a group allowed to write in log dir.
group = apache

Then change the value of “user” and “group” like below:

user = caddy
; RPM: Keep a group allowed to write in log dir.
group = caddy

Save and exit.

Restart the “php-fpm” service to take effect:

systemctl restart php-fpm

Configuring Caddy to serve WordPress

Open the famous “Caddyfile” configuration with your text editor:

nano /etc/caddy/Caddyfile

If your file is empty it’s great, if it’s not then exit the text editor and run the following command first:

echo "" > /etc/caddy/Caddyfile

Paste the following lines in your Caddyfile then save and exit:

YOUR_DOMAIN_OR_IP_ADDRESS:80 {
    tls admin@YOUR_DOMAIN
    root /var/www/wordpress
    gzip
    fastcgi / 127.0.0.1:9000 php
    rewrite {
        if {path} not_match ^\/wp-admin
        to {path} {path}/ /index.php?_url={uri}
    }
}

Restart your Caddy service to take effect:

systemctl restart caddy

Download and Install WordPress

switch to your web server’s root directory:

cd /var/www

Download the WordPress using “WGET”:

wget https://wordpress.org/latest.tar.gz

Extract the “tar.gz” file with the command below:

tar xvzf latest.tar.gz

After the extraction process is complete execute the following command to set the correct permissions for WordPress files:

chown -R caddy:caddy wordpress/

That’s it, you can go ahead and Install your WordPress using your domain or your public IP address.

¿Le ha resultado útil esta respuesta? 0 Los usuarios encontraron esto útil (0 Votos)