Linux Caddy Mariadb PHP Wordpress LCMP

Configure LCMP stack

LCMP refers to Linux-Caddy-MariaDB-PHP

Where M can also be Mysql

Been using caddy + hugo for 2 years. Though there are developed cmi(content management system) like netlifycms for hugo, it's inconvenient to post new contents, so I decided to give wordpress a try. I already tried nginx and apache before, and found them pretty difficult to configure. So I will stick with caddy as backend.

There aren't many blogs about how to configure caddy with wordpress, but it is simple as wordpress came with a directory, set caddy to work with php and configure the right home directory, we are good to go.

Ok, let's get started.



Debian 11

Before the installation, update and upgrade system

sudo apt update && sudo apt full-upgrade -y
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf '' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf '' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
sudo apt install mariadb-server

php: default version 7.4 on Debian 11 when this article was posted

install php with the most popular php extensions

sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip php-mysql php-fpm

After the installation, restart php-fpm service so the running php can leverage the new installed extensions.

sudo systemctl restart php7.4-fpm.service

You might have a different php version, change the number 7.4 accordingly.



#Caddy {
	root * /home/acytoo/wp_download/wordpress
	log {
		output file /var/log/caddy/
	encode gzip
	php_fastcgi unix//run/php/php7.4-fpm.sock

Adjusting the firewall if you are using ufw

sudo ufw allow 80
sudo ufw allow 443

Make sure there's no other software listening on 80 and/or 443, resolve port conflicts.

sudo mysql_secure_installation

And then, add a new user

sudo mysql

GRANT ALL ON *.* TO 'acytoo'@'localhost' IDENTIFIED BY 'ootyca' WITH GRANT OPTION;




mysqladmin -u acytoo -p version

'acytoo' is the account name and 'ootyca' is the password. Be sure to use your own credential.

Now start mysql command line with user acytoo:

mysql -u acytoo -p

Create a demo database:

create database testacytoo;

Change the working directory to wordpress, and copy the configuration file from template.

cp wp-config-sample.php wp-config.php

Use the tool provided by wordpress to generate a secret key, or you can come up with a good phrase:

curl -s

Copy the output into configuration:

Edit the configuration file

nano  wp-config.php

replace the DEFINEs with the value you get above, or put your unique phrase

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

Then, change the information about database.

define('DB_NAME', 'testacytoo');
define('DB_USER', 'acytoo');
define('DB_PASSWORD', 'ootyca');

If you want to write to the same server where you run wordpress, add the following line in the configuration file.

define('FS_METHOD', 'direct');


Restart caddy and visit your website's dashboard, for me, the url is, you should see the installation page of wordpress now.

If you didn't see the installation page or it shows you the website had already been installed, wipe every thing in your test database and remove wordpress directory, unzip and reconfigure again, it's because hackers had done this for you right after you restart web server. There are so many hackers scan the whole internet, and do bad things.