WordPress is a free and open source blogging software and content management system based on PHP and MySQL as the platform. WordPress has a plugin architecture and template system. Alexa Ranking More than 16.7% of the top 1 million websites use WordPress. By August 2011, about 22% of new websites had adopted WordPress. WordPress is currently the most popular blog system on Internet.
In most cases, LAMP or LEMP (ie Apache and Nginx) are used to install WordPress. In this tutorial, we will use Caddy to install WordPress. Caddy is a new web server that has quickly become popular due to its wide range of unique features, such as support for HTTP/2 and automatic TLS encryption.
In this tutorial, you will install and configure WordPress supported by Caddy.
To follow this tutorial, you need:
The Caddy project provides an installation script for installing Caddy server files. To execute, enter:
curl -s https://getcaddy.com | bash
You can view the script by visiting https://getcaddy.com
and downloading files using wget
or curl
.
During the installation process, the script will be used for sudo
to gain administrative rights in order to place the Caddy file in a system-wide directory, so it may prompt you for a password.
The command output is as follows:
Downloading Caddy for linux/amd64...
https://caddyserver.com/download/linux/amd64?plugins=
Extracting...
Putting caddy in/usr/local/bin(may require password)[sudo] password for sammy:
Caddy 0.10.2
Successfully installed
After the script is complete, the Caddy file will be installed on the server and ready to be used. You can use which
to check its location to verify that the Caddy binary is in place.
which caddy
The command output will show that the Caddy binary file /usr/local/bin/caddy
can be found.
To run WordPress, you need a web server, MySQL database and PHP scripting language. So the last requirement is to install PHP.
First, make sure your package is up to date.
sudo yum update
Install the PHP extensions that PHP and WordPress depend on, such as supporting MySQL curl, XML and multi-byte strings.
sudo yum install php php-fpm php-mysql php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc
After the installation is complete, you can verify whether PHP has been installed correctly by checking the version of PHP.
php -v
You will see output similar to this, which shows the version number of PHP.
PHP 5.4.16(cli)(built: Nov 6201600:29:02)Copyright(c)1997-2013 The PHP Group
Zend Engine v2.4.0,Copyright(c)1998-2013 Zend Technologies
Before continuing, we must slightly modify the PHP configuration file to use our non-privileged user to run the caddy server. The default Apache on CentOS is the preferred server.
Use vi
or your favorite text editor to open the PHP-FPM
configuration file.
sudo vi /etc/php-fpm.d/www.conf
Find the fragment of the specified user account.
; 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
Change the two values to caddy as follows:
; 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 close the file. To allow Caddy to communicate with PHP, start the PHP service.
sudo systemctl start php-fpm
Install all WordPress dependencies, next, we will configure the MySQL database for WordPress for use.
WordPress uses a MySQL database to store all its information. In the default MySQL installation, only the root management account is created. This account should not be used because it poses a security risk to the database server. Here, we will create a dedicated MySQL user for WordPress to allow new users to access the database.
First, log in to the MySQL root management account.
mysql -u root -p
During the installation process, you will be prompted to enter the password for the MySQL root account. Create a new database called wordpress, which will be used for the WordPress website. You can use another name, but please make sure to remember it when you make other configurations in the future.
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Next, create a new user who is allowed to access this database. Here, we use the username wordpressuser
to simplify, but you can choose your own name. Please replace password
with a secure password.
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
**Note: **The default password policy requires 12 characters, including at least one uppercase letter, one lowercase letter, one number and one special character. If you forget to follow the policy, the above command will not create a user, but will display an error message.
Refresh permissions to notify the MySQL server of the change.
FLUSH PRIVILEGES;
You can log out of MySQL now.
EXIT;
WordPress has a dedicated database and user accounts, so all system components have been set up. The next step is to install WordPress itself.
Download the latest WordPress to the web root directory and make sure that the web server can access it, and then complete the installation through the GUI (graphical interface) of the WordPress browser. In this step, we only download this version because we need to configure the web server before accessing the GUI (graphical interface).
First, change the current directory to /var/www
, the web root directory where website files are stored.
cd /var/www
Download the latest WordPress version. It is recommended that you use the latest version, because the software is often updated with security patches.
sudo curl -O https://wordpress.org/latest.tar.gz
Extract and decompress the compressed archive just downloaded.
sudo tar zxf latest.tar.gz
This will automatically create a new directory called wordpress
. We delete the old compressed package
sudo rm latest.tar.gz
The last step is to change the permissions of WordPress files and directories so that all files can be written by Caddy. Allow WordPress to automatically update to a newer version.
sudo chown -R caddy:caddy wordpress
**Note: **Prohibiting write access to WordPress files can improve security by making it unavailable to take advantage of some errors that may lead to the disclosure of WordPress core files, but at the same time, it will result in disabling automatic security updates and installing and updating plugins through the WordPress web interface Function.
Next, you need to modify the configuration of the web server to serve your website.
We will modify the Caddyfile
configuration file to tell Caddy where our WordPress installation is located and which domain name should be used to perform it.
Open the configuration file using vi
or your favorite text editor
sudo vi /etc/caddy/Caddyfile
Copy and paste the following configuration into the file. You can delete any sample configuration from the previous tutorial.
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 Caddyfile structure is as follows:
example.com
in the first line is the domain name available for the site. Replace it with your own domain name. The root
directive tells the location of the Caddy website files. In this example, it is /var/www/wordpress
. The gzip
command tells Caddy to use Gzip compression to speed up the site. The fastcgi
directive configures the PHP handler to support files with the php
extensionrewrite
directive to enable URLs (called very permanent links in WordPress). If you use Apache, this configuration is automatically provided by WordPress in the .htaccess
file, but it needs to be configured separately for Caddy.After changing the configuration file accordingly, save the file and exit.
Restart Caddy for the new profile settings to take effect.
sudo systemctl restart caddy
You have now installed and configured Caddy and all the necessary software to host your WordPress website. The last step is to use its GUI (graphical interface) to complete the configuration of WordPress.
WordPress has a GUI (graphical interface) installation wizard to complete its setup, including connecting to the database and setting up your first website.
When you visit a new WordPress instance in your browser for the first time, you will see a list of languages. Choose the language you want to use. On the next screen, it describes the information it needs about the database. Click Let's go!, and the next page will ask for database connection details. Fill out the following form:
When you click "Submit", WordPress will check if the details provided are correct. If you receive an error message, double check that you have entered the database details correctly.
Once WordPress successfully connects to your database, you will see a message stating **All right, sparky! You've made it through this part of the installation. WordPress can now communicate with your database. (**You completed this part Install. WordPress can now communicate with your database. **) **The message at the beginning
Now you can click "Run Installation" to start the installation. Next, WordPress will show you a page asking for your website details such as website title, admin account username, password, and email address. The default is to automatically generate a random password, but if you want, you can choose your own password.
**Note: **For administrative accounts, it is not recommended to use common user names such as Admin because many security vulnerabilities rely on standard user names and passwords. Choose a unique username and strong password for your main account to keep your website safe.
Click After installing WordPress, you will be directed to the WordPress dashboard. You have now completed the WordPress installation, and you are free to use WordPress to customize your website and write posts and pages.
You have learned to install WordPress using the Caddy web server. Caddy will automatically use HTTP/2 and Gzip compression to serve the website faster. You can read more about the unique features and configuration instructions of Caddy's Caddyfile
in the official Caddy documentation.
If you want to use plugins in a new WordPress instance, please note that some plugins rely on the .htaccess
file of the Apache web server. There are not many plugins that rely on .htaccess. However, there are a few that can not be used with Caddy because it does not use .htaccess
. Most plugins that rely on .htaccess are cache plugins (for example, W3 Total Cache), they use .htaccess
to completely bypass PHP for processing. If you encounter this kind of plug-in, please replace it with a similar plug-in. Want to learn more? Please go to Tencent 云+社区 to learn.
Reference: "How to Install WordPress with Caddy on CentOS 7"
Recommended Posts