WordPress is one of the most popular content management system (CMS). It can be used for setting up blogs and websites in a fast and easy way, and almost all of its administration is possible through a web interface.
WordPress is installed with the use a LAMP or LEMP stack such as using either Apache or Nginx as a web server. This guide aims at installing WordPress using Caddy instead. Caddy is one of the modern next-generation web servers written in GO language. It is well known for its wide array of rich and unique features, such as HTTP/2 support and automatic TLS encryption with Let’s Encrypt, which is a leading free certificate provider.
In this tutorial, we shall walk you through how you can install WordPress with Caddy web server on CentOS 7.
Prerequisites
To begin with, we’ll require the following:
- One CentOS 7 server install
- pre- installed instance of caddy web server
Step 1 — Installing PHP
Running a WordPress requires a web server, a MySQL database, and the PHP scripting language. Having a Caddy web server and a MySQL database already installed from the prerequisites, the next thing one is required to do is to set up PHP.
To start with, ensure that the packages are updated
yum update
Installing PHP and the PHP extensions which are crucial for WordPress, like support for MySQL, curl, XML, and multi-byte strings.
yum install php php-fpm php-mysql php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
After suceesful installation confirm that PHP was installed properly byverifying the PHP’s version.
php –v
A similar output will be as shown below
PHP version output PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
Before proceeding , we need to make slight changes to the configuration files for PHP service .
This is because the system uses the unprivileged caddy user to run the server. The default arrangement on CentOS 7 makes an assumption that Apache is the server of preference.
Access the PHP-FPM configuration file with your preferred text editor.
vi /etc/php-fpm.d/www.conf
locate the section that specifies the user account and class.
; 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 = apache
modify both values to caddy as shown below :
/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
Save and exit.
Start the PHP service to allow Caddy web server to communicate with PHP.
systemctl start php-fpm
Next, we are going to create a MySQL database for WordPress installation
Step 2 — Creating a MySQL Database and Dedicated User
WordPress uses a MySQL database to store information. In a default MySQL set up, only a root administrative account is created. Being a security risk, this account shouldn’t be used because of its unlimited privileges to the database server.
In such a case, there is need to create a dedicated MySQL user for WordPress to use and a database that the new user will be permitted to access.
Log in to the MySQL root administrative account.
mysql -u root -p
One is prompted for the password he set for the MySQL root account during the set up.
create a new database called WordPress.
You can use another name which is easy to recall.
CREATE DATABASE WordPress
Now,create a new user that will be allowed to access the database.
In this case use the username wordpress user for simplicity, but one is allowed to choose personal name. Replacing a password with a strong and secure password is also recommended.
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
Flush privileges to alert the MySQL server of the changes.
FLUSH PRIVILEGES;
Now, one can exit MySQL safely
EXIT;
Next, we are going to install WordPress
Step 3 — Downloading WordPress
We are going to download the current release into the web root directory and ensure it’s accessible by the web server, complete with the installation through WordPress’ graphical interface.
First of all, modify the current directory to /var/www, the web root which keeps website files.
cd /var/www
Download the new compressed WordPress release. It’s necessary to use the current release because the software is updated frequently with security patches.
curl -O https://wordpress.org/latest.tar.gz
Extract the “tar.gz” file as shown below
tar -xvf latest.tar.gz
This creates a new a WordPress directory.
The final step involves changing the permissions of WordPress files and directories so that all files are writable by Caddy. This will enable WordPress to be automatically updated to the current versions.
chown -R caddy:caddy wordpress
Next, one is required to change the web server’s configuration to serve the website.
Step 4 — Configuring Caddy to Serve the WordPress Website
In this step, there would be changes on Caddy file configuration file to tell Caddy where our WordPress set up is situated and under which domain name should it be published to the visitors.
Open the configuration file using vi or the most preferred text editor
vi /etc/caddy/Caddyfile
Next, Copy and paste the configuration below into the file.
/etc/caddy/Caddyfile example.com { tls admin@example.com 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} } }
The structuring of Caddy file is as follows:
1. The example.com in the first line is the domain name under which the site will be present. One can use personal domain name instead
2. The admin@example.com after the tls directive informs Caddy the e-mail address it should use to request the Let’s Encrypt certificate. To recover the certificate one will need to Encrypt so as to use this e-mail address in the recovery process.
3. The root directive informs Caddy the location of the website files. In this example, it’s /var/www/wordpress.
4. The gzip directive informs Caddy to use Gzip compression so as the website is fast.
5. The fastcgi directive aligns the PHP handler to offer support to files with a php extension
6. Use of rewrite directive enables pretty URLs (called pretty permalinks in WordPress). This arrangement configuration is automatically offered by WordPress in the .HRAccess file one uses Apache, but requires to be configured for Caddy as separate items.
Save the file and exit after modifying the file configuration.
Refresh Caddy to put the new configuration file settings into action.
systemctl restart caddy
When Caddy begins, it will automatically acquire an SSL certificate from Let’s Encrypt to serve your site securely using TLS encryption. Now one can access Caddy-hosted WordPress website by moving to domain with the use of personal browser. After doing so, one will notice the green lock sign in the address bar meaning the site is being shown over a secure connection.
By doing so, one will have installed and configured Caddy and all necessary software required to host a WordPress website. The final step is to complete WordPress’ configuration with the use of graphical interface.
Step 5 — Configuring WordPress
WordPress consists of a GUI installation wizard to complete its setup, including connecting to the database and setting up the first website.
When one visits the current WordPress instance in the browser for the first time, he will notice list of languages. Select the language would like of own choice .the next screen, it explains the information it requires about on the database. Click and start! The next page will inquire for database connection information. Complete the form as follows:
1. Database Name should be listed as WordPress, unless you customized it in Step 2.
2. The Username is WordPress user, unless you customized it in Step 2.
3. Password should be the password that was set for WordPress user in Step 2.
4. The Database Host and Table Prefix should have their default values.
Clicking Submit, WordPress will confirm if the presented details are correct. If an error message is received, double check that entered your database details inserted correctly.
Immediately WordPress successfully links to the database, one will see a message that starts with All right, sparky! You’ve made it through this part of the installation. WordPress communication with the database is now enabled.
Next, press the install to start the installation. After a short time, WordPress will present a screen requesting for the website details, such as the website title, the administrator account username, password, and e-mail address. One can select a password of own choice although a strong password will be auto-generated for you.
It is advisable to note that a good security practice that is, not to use a common username like admin for the administrative account, as many security uses depend on standard usernames and passwords. Select a unique username and a strong password for your main account to make your site secure.
Direction to the WordPress dashboard will be given after pressing install WordPress. You have now completed the WordPress installation and you good to use WordPress with no restrictions to customize your website and write posts and pages.
Conclusion
In this tutorial, we have shown you how you can install WordPress with Caddy Web server. Feel free to give it a try and give us feedback. Thank you for your time.