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.

#Installation

#Linux

Debian 11

Before the installation, update and upgrade system

sudo apt update && sudo apt full-upgrade -y
#Caddy:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
#MariaDB
sudo apt install mariadb-server
#PHP

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

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.

#Wordpress
wget https://wordpress.org/latest.zip
unzip latest.zip

#Configuration

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

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.

#MariaDB
sudo mysql_secure_installation

And then, add a new user

sudo mysql

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

FLUSH PRIVILEGES;

exit

Test

mysqladmin -u acytoo -p version

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

Create a demo database:

create database testacytoo;
#wordpress

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 https://api.wordpress.org/secret-key/1.1/salt/

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');

#Test

Restart caddy and visit your website's dashboard, for me, the url is test.acytoo.com/wp-login.php, 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.

#Reference

www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-debian-10

www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mariadb-php-lemp-stack-on-debian-10

www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-nginx-mariadb-and-php-on-debian-10