The goal of this tutorial is to set up a WordPress server. For this, we will install and configure Apache and MariaDB. You can use this tutorial for another tool like GLPI, but you will obviously need to check the official website for the required PHP packages.
Start by updating your system.
apt-get update
apt-get upgrade
Install MariaDB.
apt-get install mariadb-server
We will now secure MariaDB.
mysql_secure_installation
Enter current password for root (enter for none):
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Log in to MariaDB.
mariadb -u root
Then create a new database.
CREATE DATABASE name_of_my_database DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Add a new user for this database and set a password for them.
GRANT ALL ON my_database_name.* TO 'USERNAME'@'localhost' IDENTIFIED BY 'THE_PASSWORD_I_WANT';
Reload the privileges to recognize this new user.
FLUSH PRIVILEGES;
Then exit MariaDB.
EXIT;
Install Apache, php, and the necessary extensions for WordPress.
apt-get install apache2
apt-get install php7.4
apt-get install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php7.4-mysql php-mysql
Enable rewrite for permalinks.
a2enmod rewrite
Restart Apache.
systemctl restart apache2
Create and modify the Apache conf file for your site.
nano /etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot "/var/www/mysite"
<Directory "/var/www/mysite">
Options +FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog /var/log/apache2/error.mysite.com.log
CustomLog /var/log/apache2/access.mysite.com.log combined
</VirtualHost>
Enable “mysite”, which is the name of the newly created conf file.
a2ensite mysite
Delete the default configuration file.
rm /etc/apache2/sites-enabled/000-default.conf
Navigate to the /tmp directory.
cd /tmp
Then download the latest version of WordPress.
wget https://wordpress.org/latest.tar.gz
Extract the archive.
tar -xzvf latest.tar.gz
Create the folder that will host our site; note it should match the name given in the configuration file.
mkdir /var/www/mysite
Remove the default Apache directory “html”.
rm -R /var/www/html
And move all the content of the WordPress folder into your new directory.
mv /tmp/wordpress/* /var/www/mysite
Before setting the permissions, copy the wp-config.php file.
cp /var/www/mysite/wp-config-sample.php /var/www/mysite/wp-config.php
Create the .htaccess file with the content below.
nano /var/www/mysite/.htaccess
# BEGIN WordPress
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Assign the folder and its content of your site to the www-data user and group.
chown -R www-data:www-data /var/www/mysite
Modify the rights of the folders and files of your site.
find /var/www/mysite -type d -exec chmod 750 {} \;
find /var/www/mysite -type f -exec chmod 640 {} \;
To enhance the security of WordPress, we are going to generate new keys.
curl -s https://api.wordpress.org/secret-key/1.1/salt/
Replace the “demo” keys that are in the wp-config.php file with the new keys.
nano /var/www/mysite/wp-config.php
define('AUTH_KEY', 'XXXXXXXXXXXX');
define('SECURE_AUTH_KEY', 'XXXXXXXXXXXX');
define('LOGGED_IN_KEY', 'XXXXXXXXXXXX');
define('NONCE_KEY', 'XXXXXXXXXXXX');
define('AUTH_SALT', 'XXXXXXXXXXXX');
define('SECURE_AUTH_SALT', 'XXXXXXXXXXXX');
define('LOGGED_IN_SALT', 'XXXXXXXXXXXX');
define('NONCE_SALT', 'XXXXXXXXXXXX');
In this same file (wp-config.php), you’ll find the database configuration. Modify the values according to what you set during the creation of the database and user in the MariaDB section.
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'name_of_my_database' );
/** Database username */
define( 'DB_USER', 'USERNAME' );
/** Database password */
define( 'DB_PASSWORD', 'THE_PASSWORD_I_WANT' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
Also add this small line at the end of your wp-config.php file to force WordPress to use PHP for the installation of plugins rather than FTP.
define('FS_METHOD', 'direct');
Restart Apache.
systemctl restart apache2
Everything is now ready! Launch a browser and enter your server’s IP address into the address bar, and you’ll be redirected to the WordPress installation page.