Install WordPress on a VPS

By Alex • 5. April 2023

VPS stands for Virtual Private Server and is the best solution, if you want to host your WordPress website, Mautic, CRM, n8n and every other software for your own business. If you don't have a clue on how to secure your VPS, maybe you should use hosting services like our Mautic Hosting. As soon as you deal with real-life customer data you need to ensure a certain level of security. 

The best hoster for VPS imo is Hetzner. They are very reliable, have great support and are quite cheap as well. Please feel free to use this affiliate Link if you consider using it: https://hartmut.io/hetzner

Update Server

Update Package Index

apt update && apt upgrade -y
apt-get install -y software-properties-common

Install Webserver and Database and PHP

Installiere Apache2 und MariaDB

apt install -y apache2 && apt install -y mariadb-server && apt install -y mariadb-client

Secure your MySQL installation

sudo mysql_secure_installation <<EOF
y
securePassword#1
securePassword#1
y
y
y
y
y
EOF

Install PHP

sudo add-apt-repository ppa:ondrej/php && sudo add-apt-repository ppa:ondrej/apache2

sudo apt install -y php libapache2-mod-php php-common php-gmp php-curl php-intl php-mbstring php-xmlrpc php-mysql php-bcmath php-gd php-xml php-cli php-fpm php-zip php-imap

Change PHP standard settings in php.ini file

sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php/7.4/apache2/php.ini
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 25M/' /etc/php/7.4/apache2/php.ini
sudo sed -i 's/max_execution_time = 30/max_execution_time = 360/' /etc/php/7.4/apache2/php.ini
sudo sed -i 's+;date.timezone =+date.timezone = Asia/Nicosia+' /etc/php/7.4/apache2/php.ini

Enable Apache at server boot

systemctl enable apache2

Restart Apache Web Server

systemctl start apache2

Install Unzip and Certbot

We need Unzip to open .zip archives like the WordPress package from Github. With Certbot we’ll retrieve our Let’s Encrypt SSL certificates, in order to serve our Website via the secure https protocol.

apt install unzip && apt install -y python3-certbot-apache

Install WordPress

First let’s create a MySQL database, a database user and give the user the necessary privileges.

mysql -u root
CREATE DATABASE wordpress;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'test1234';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
exit

Download WordPress and decompress it

wget https://wordpress.org/latest.zip
unzip latest.zip -d /var/www/html/

Delete the install-package

rm latest.zip

Create a VirtualHost File for WordPress

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

Copy and paste this into the wordpress.conf file you just created. Make sure to change the values ServerAdmin (email address) and ServerName (domain name) according to your needs.

<VirtualHost *:80>
ServerAdmin your@emailaddress.com
DocumentRoot /var/www/html/wordpress/
ServerName yourdomain.com
 
<Directory /var/www/html/wordpress/>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
 </Directory>

 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

allow the website to be served via Apache Server.

a2ensite wordpress.conf
a2enmod rewrite

Restart Apache Server.

systemctl restart apache2

Get a Let’s Encrypt SSL certificate via Certbot.

certbot --apache --agree-tos --email yourname@yourdomain.com --redirect --hsts -d yourdomain.com

Give write and read permissions to the www-data user inside the wordpress directory.

chown -R www-data:www-data /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress

That’s it. Now open your website and follow the installer of WordPress.

If you followed this tutorial you should have a working WordPress website on your own VPS.

About the Author

Founder and marketing-automation-nerd.
He helps onlineshops to sell more fully automated.
Using the Lead & Sales Generatorâ„¢ method, he generates qualified leads, wins satisfied customers and scales e-commerce businesses.
He also loves tea, golf, spending time with his family and exceptional business concepts.

Leave a reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}