WordPress is a popular content management system (CMS) that allows users to create websites and blogs without extensive coding knowledge. This guide provides a step-by-step process for setting up a WordPress website on an existing Linux server.
Prerequisites:
- A Linux-based server with root access
- A (sub)domain connected to the server (recommended)
Installing PHP8.2
PHP is required for WordPress to function. Install the latest PHP version, PHP8.2, using the following commands:
apt install sudo nano -y
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 -y
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
apt update && apt upgrade –y
apt install php8.2 -y
Adjusting php.ini
Modify the php.ini file using the nano text editor:
nano /etc/php/8.2/apache2/php.ini
Adjust the following parameters:
memory_limit = 1024M
upload_max_filesize = 16G
post_max_size = 16G
date.timezone = <YourTimezone>
Replace <YourTimezone>
with your actual timezone.
Installing Additional Programs
Install the required programs using the following command:
apt install apache2 unzip wget curl mariadb-client mariadb-server
Setting up a Database
Create a database and database user for WordPress:
mysql –u root –p
create database wordpress;
create user ‘wordpress’@’localhost’ identified by ‘PASSWORD’;
grant all privileges on wordpress.* to ‘wordpress’@’localhost’;
flush privileges;
exit;
Deleting the Placeholder Website
Remove the placeholder website created by Apache2:
cd /var/www/html && rm index.html
Downloading WordPress Files
Download the latest WordPress files using the following command:
cd /home && wget https://wordpress.org/latest.zip
unzip latest.zip
rm latest.zip
cp -R /home/wordpress/* /var/www/html
Adjusting Folder Permissions
Set the correct folder permissions:
chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
Setting up a Reverse-Proxy
Create a reverse-proxy configuration file:
nano /etc/apache2/sites-available/wordpress.conf
Paste the following content into the file:
<VirtualHost *:80>
ServerAdmin <YourEmail>
DocumentRoot /var/www/html/
ServerName <Your(Sub)Domain>
<Directory /var/www/html/>
Options +FollowSymlinks
AllowOverride All
Require all granted
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/html
SetEnv HTTP_HOME /var/www/html
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Replace <YourEmail>
with your email address and <Your(Sub)Domain>
with your actual (sub)domain.
Save the file, activate the configuration, and restart Apache2:
CTRL+O, CTRL+X
a2ensite wordpress.conf
systemctl restart apache2
Installing an SSL Certificate via Certbot
Install Certbot and generate a free Let’s Encrypt SSL certificate:
apt install certbot python3-certbot-apache -y
certbot --apache
Completing WordPress Installation
Open your (sub)domain in the browser. The WordPress installation wizard will appear.
Click “Let’s go!”.
Enter the database connection details.
Click “Submit”.
Click “Run the installation”.
Enter site title and create admin account.
Click “Install WordPress”.
Login to the backend of the WordPress.Tip: To get to the login of your WordPress instance in the future, use the following URL scheme:
https://<your(sub)domain/wp-admin
The login screen will look like this:
Go crazy!
Conclusion
The article provides detailed instructions on how to install WordPress on an existing server. The instructions are written in a clear and easy-to-follow manner, even for those who are not familiar with Linux.