Installing WordPress with Caddy on CentOS 7 Server


WordPress is the leading CMS (Content Management System). CMS is used to set up blogs and websites simple and fast, and most of the administration is possible with the help of web interface. Mostly, WordPress is installed in LAMP or LEMP stack and it uses Apache or Nginx as a web server. In this article, you will be able to setup up WordPress with Caddy. Caddy is a new type of web server gaining good quality for its attractive features.


Steps to Install WordPress with Caddy on CentOS 7:


1) Installing the PHP:


We need to make sure that the packages are up to date.


sudo yum update


Installation of PHP and the extensions of PHP WordPress relies upon, support for MySQL, XML, curl, and multibyte strings.


sudo yum install php php-fpm php-mysql php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc


Once the installation is complete, you will be able to verify that PHP was installed properly by checking the version of PHP


php -v


You will be able to see the output similar to this, that displays the version number of PHP.


PHP version output

PHP 5.4.16 (cli) (built: Jan  6 2018 (15:02:23)

Copyright (c) 1997-2015 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2015 Zend Technologies


You need to Open the PHP-FPM configuration file with vi or text editor of you choice. Below are the short introduction to vi:


sudo vi /etc/php-fpm.d/www.conf


You need to find the fragment that specifies the user account and group:


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

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user's group

;       will be used.

; RPM: apache Choosed to be able to access some dir as httpd

user = apache

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

group = apachep:


Change both the values to caddy as required:


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

; Unix user/group of processes

; Note: The user is mandatory. If the group is not set, the default user's group

;       will be used.

; RPM: apache Choosed to be able to access some dir as httpd

user = caddy

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

group = caddy


And then, you need to Save and close the file to exit. So Caddy will be able to communicate with PHP and start the PHP service.


sudo systemctl start php-fpm


2) Creating the MySQL Database along with Dedicated User


First, you need to log in to the MySQL root administrative account.


MySQL -u root -p


And then you will be prompted for the password and you need to set for the MySQL root account during the installation.


You need to create a new database called as Wordpress, It will be used on the WordPress website. You will be able to use a different name, but you need to make sure the additional configuration later.


mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;


Next, you need to create a new user which will be allowed to access this database. Here, we use the username as abcd, but you can select your own name. You need to replace the password with a strong and secure password.


mysql> GRANT ALL ON abcd.* TO 'abcdef'@'localhost' IDENTIFIED BY 'password';


Flush privileges on the MySQL server to notify the changes.


mysql> FLUSH PRIVILEGES;


Now you will be able to safely exit MySQL.


mysql> EXIT;


3) Downloading the WordPress


First, you need to make changes in the current directory to /var/www, the web root which is capable of storing the website files.


cd /var/www


You need to download the latest compressed WordPress release. It's necessary to use the latest version as the software is often updated with the security patches.


sudo curl -O https://wordpress.org/latest.tar.gz


You need to extract the compressed archive that you have downloaded.


sudo tar zxf latest.tar.gz


It will automatically create a new directory known as WordPress. Now you can safely remove the downloaded archive, as it is not required anymore.


sudo rm latest.tar.gz


And the final last step is to modify the permissions of WordPress files and directories. So the files are writable by Caddy. It allows WordPress to be automatically updated to the latest versions.


sudo chown -R caddy:caddy wordpress


4) Configuring Caddy to serve the Website of wordpress


You need to open the configuration file with vi or text editor which you require


sudo vi /etc/caddy/Caddyfile


You need to copy and paste the following configuration into your file. You will be able to remove any example configuration from the previous tutorials.


/etc/caddy/Caddyfile

abcd.com {

   tls This email address is being protected from spambots. You need JavaScript enabled to view it.

   root /var/www/wordpress

   gzip

   fastcgi / 000.0.0.0:0000 php

   rewrite {

       if {path} not_match ^\/wp-admin

       to {path} {path}/ /index.php?_url={uri}

   }

}


After making changes in the configuration file, save the file and exit.


You need to Restart the Caddy to put the new configuration file settings into effect.


sudo systemctl restart caddy


5) Configuring the WordPress


While visiting your new WordPress instance in the browser for the first time, you will find numerous of languages. Select the language you need. Next, it will describe the details it requires about the database. And on Click Let's go and the next page will be requesting for database connection details.


And when you click on Submit button, WordPress will check whether the entered details are correct. Once the WordPress is being successfully connected to the database, you will be able to see a message. And now the WordPress will be able to communicate with your database.


Now you need to click on Run the install to start the installation. After some time, WordPress will offer you with the last screen asking for the website information. Later you need to click on Install WordPress and you will be directed to the WordPress dashboard. Finally, you have finished the installation of WordPress.