How to Install WordPress with Caddy on Ubuntu 16.04

Caddy is a modern, general-purpose, multi-platform web server which supports Virtual hosting, HTTP/2, IPv6, Markdown, WebSockets, FastCGI, automatic HTTPS via Let’s Encrypt, templates and more. In this tutorial, we will show you how to install Caddy on a Ubuntu 16.04 VPS.

Please ensure that you have an Ubuntu 16.04 server set up, including a sudo non-root user and a firewall, MySQL is installed, and Caddy is installed including a domain name configured to point to your Droplet.

Open your terminal with:

Ctrl+Alt+T

Run the following commands:

Instal PHP

sudo apt-get update

You will be prompted for your password. Take caution when entering as there is no visual feedback.

sudo apt-get install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc

Check the version of PHP which has been installed once the installation finishes:

php -v

You'll see output which displays PHP's version number and all of WordPress' dependencies would've been installed.

Create a MySQL Database and Dedicated User

Log into your MySQL administrative account using the password you set for the MySQL root account during installation:

mysql -u root -p

Create a database called worpress:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Set permissions on the database:

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

Remember to replace password with a strong and secure password.

FLUSH PRIVILEGES;

EXIT;

Download WordPress

Change your directory:
cd /var/www

Download the latest compressed release of WordPress:

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

Extract the compressed archive:

sudo tar zxf latest.tar.gz

A Wordpress directory will be created automatically. Delete the compressed file:

sudo rm latest.tar.gz

Change the permissions of WordPress files and directories so that all files are writable by Caddy:

sudo chown -R www-data:www-data wordpress

Configure Caddy to Serve the WordPress Website

Open the configuration:
sudo nano /etc/caddy/Caddyfile

Copy and paste the following configuration into the file.

example.com {
tls admin@example.com
root /var/www/wordpress
gzip
fastcgi / /run/php/php7.0-fpm.sock php
rewrite {
    if {path} not_match ^\/wp-admin
    to {path} {path}/ /index.php?_url={uri}}}

Replace example.com with your own domain name
After changing the configuration file accordingly, save the file and exit.

Restart Caddy:

sudo systemctl restart caddy

Configure Wordpress

WordPress has a GUI installation wizard to finish its setup, including connecting to the database and setting up your first website.

When you visit your new WordPress instance in your browser for the first time, you'll see a list of languages. Choose the language you would like to use. On the next screen, it describe the information it needs about your database. Click Let's go!, and the next page will ask for database connection details. Fill in this form as follows:

  • Database Name should be wordpress, unless you customized it in Step 2.
  • Username should be wordpressuser, unless you customized it in Step 2.
  • Password should be the password you set for wordpressuser in Step 2.
  • Database Host and Table Prefix should be left to their default values.

When you click Submit, WordPress will check if the provided details are correct. If you receive an error message, double check that you entered your database details correctly.

Once WordPress successfully connects to your database, you'll see a message which begins with:

All right, sparky! You've made it through this part of the installation. WordPress can now communicate with your database.

Now you can click Run the install to begin the installation. After a short time, WordPress will present you with a final screen asking for your website details, such as the website title, the administrator account username, password, and e-mail address. The strong password will be auto-generated for you, but you can choose your own if you'd like.

After clicking Install WordPress, you will be directed to the WordPress dashboard. You have now finished the WordPress installation, and you can use WordPress freely to customize your website and write posts and pages.