How to Add WordPress to an Existing Server

You always wanted to run your own website or blog but you can’t program yourself, or you don’t have the time to write your own complex website? 
Then WordPress is the right choice for you! WordPress is free Content Management System (CMS) with which you can create your own websites, blogs and much more.  
According to Wikipedia, WordPress is used by over 40% of all websites. Fun fact: We also rely on WordPress for our blog! 
WordPress can also be extended and customized with an incredible number of plugins and extensions and is also completely customizable. 
To write a complete article about all the features of WordPress would be impossible with this range of functions, which is why we focus on the installation of WordPress in this article. 
Let’s get started!

Requirements

Installing PHP8.2

For WordPress to run at all, PHP is required. The official requirements of WordPress are PHP7.4 or higher. In this guide we install the latest PHP version, namely 8.2.

Adding the PHP Repository

We’ll need to add the PHP8.2 repository in Debian 10.
To do so enter these commands in this order:

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 

Installation of PHP8.2

The actual installation of PHP8.2 is very easy and done with just one command:

apt install php8.2 -y

Adjusting the php.ini

After installing PHP , we need to adjust the php.ini, or the config of PHP. I’m going to use the nano text-editor. Open the file with this command: 

nano /etc/php/8.2/apache2/php.ini 

And don’t forget to change these parameters: 

  • memory_limit = 1024M 
  • upload_max_filesize = 16G  
  • post_max_size = 16G  
  • date.timezone = <YourTimezone>

The Timezone needs to be in this format: Europe/Berlin

You can find your Timezone database name here.

Hint: You can press [CTRL+W] to open a search-field in which you can search for these parameters (e.g., memory_limit). Hit [Enter] to jump to the exact line. With this method, you don’t need to scroll through the whole config to find the values. 

After you’ve changed the parameters, save the file with [CTRL+O] and exit the editor with [CTRL+X]

Installation of Other Required Programs

We’ll need to install additional required programs, e.g., Apache2, PHP, and database software. The installation of PHP8.2 has been done in a previous step already.

Let’s install the other required programs with this command:

apt install apache2 unzip wget curl mariadb-client mariadb-server

Setting up a Database

WordPress will store things like userinfo in a database. Therefore, we need to create one by using MariaDB. 
You have to first log in to the database software with this command: 

mysql –u root –p

Then, you’ll need to enter your root-password. 
With this command you can create the database:

create database wordpress;

Now we will create a database user with this command:

create user 'wordpress'@'localhost' identified by 'PASSWORD';

IMPORTANT: Please set a secure password by replacing PASSWORD in the command above. Make sure to leave the apostrophe in front and behind your password (you could use a password manager like Bitwarden self-hosted on a VPS for even more security). 

Now give the database user access to the WordPress database with this command:

grant all privileges on wordpress.* to ‘wordpress’@’localhost’;

And refresh the database with this command: 

flush privileges;

This creates the database and database user. You can exit the database software with this command:

exit;

Delete the Placeholder Website

Before we proceed with downloading the WordPress files, let’s quickly delete the placeholder website that our web server, Apache2, created. 
This is done with the following command:

cd /var/www/html && rm index.html

Downloading the WordPress Files

Now it’s time to download the actual WordPress files. To do so, use this command:

cd /home && wget https://wordpress.org/latest.zip

Because the downloaded file is a .zip-Archive, we need to unzip it first with this command: 

unzip latest.zip

After unzipping, you can remove the .zip-Archive with this command:

rm latest.zip

Now move the unzipped WordPress files to its correct position with this command: 

cp -R /home/wordpress/* /var/www/html

Adjusting Folder Permissions

In order for Apache2 (the webserver) to access the WordPress files, we’ll need to adjust a few permissions.
This can be done with these three commands:

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

In order to tell Apache2 that there is a WordPress instance running at a specific location, we need to set up a reverse-proxy. 

To do so, we are again using the nano-text editor to create this reverse-proxy. Use this command to create the config:

nano /etc/apache2/sites-available/wordpress.conf

Now paste in the following content:

<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>

IMPORTANT: You need to replace <YourEmail> in the second line with a valid email address. The brackets in front of and behind your email address (“<” and “>”) need to be removed. 

Moreover, you need to replace <Your(sub)Domain> in the fourth line with your acutal (sub)domain (don’t forget to remove the brackets!).  

After changing these two things, save the file with [CTRL+O] and exit the editor with [CTRL+X]

You can now activate your config with the following command:

a2ensite wordpress.conf

Now you’ll need to restart the whole web server with this command in order for the changes to take effect: 

systemctl restart apache2

Installing an SSL Certificate via Certbot

SSL certificates are one of the “must implement” security measures, especially for securing data transfer or login data. In this tutorial, we use Certbot, which lets you generate free Let’s Encrypt certificates that are valid for 90 days.
Use this command to install Certbot:

apt install certbot python3-certbot-apache -y

After installing Certbot, start the program with this command:

certbot --apache

Note that when you start the program for the first time, you’ll need to agree to some license terms & conditions (y’know, the usual “sign your soul away to use the program” terms & conditions). 

You should now see a list of all of your active websites (e.g., mywebsite.com or ilovethistutorial.com). 

In this following step, you’ll need to type in the correct number to select the site you want to install a certificate for, and choose Redirect (Option 2 in the next menu.) 

After this is all complete, you can sit back and marvel at the fruits of your labor: you now have a SSL certificate.

Finish the WordPress Installation in Browser

All the required programs are now installed and all the settings are complete. You can now close the console, as the setup can now be completed in the browser.   

To do this, enter your chosen domain (subdomain if applicable) into the URL bar of your browser. The installation wizard will now be called:

WP installation wizzard
You own Website is only a few steps away!

After you click on “Let’s go!”, you need to enter the data of your previously created database in the following window:

WP Database credentials
Connect your database to WordPress

After you have entered your database connection, click Submit.  

On the next page click on “Run the installation”:

WP start the installation
Finalize the installation

In the following menu you can give your website a title, as well as create an admin access:

WP Create Website and Admin Account
Choose a site title and create an admin account

After you click on “Install WordPress”, it will confirm that the installation was successful. Now click on “Login” to log in to the backend of your WordPress instance:

WP Successfully installed wordpress
Now your WordPress instance is good to go!

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: 

WP Login interface
This is how the login page to your WordPress instance looks like

Congratulations! You have installed a fully functional WordPress instance.  

Have fun personalizing it.

You can check out more tutorials, or spin up another VPS server (they only start from $6.99 USD/mo!) to tinker with and self-host other apps.

Scroll to Top