How to Install WordPress on Ubuntu 22.04 VPS

How to Install WordPress on Ubuntu 22.04 VPS

If we previously discussed How to Install WordPress on Debian 10, now we will discuss how to install WordPress on an Ubuntu 22.04 VPS.

How to Install WordPress on Ubuntu 22.04 VPS

Before proceeding, it is recommended that your server be a fresh install, meaning no other website applications are installed, which reduces the risk of errors during installation.

Additionally, although this title is specific to Ubuntu 22.04, if you are still using Ubuntu 18.04 or 20.04, you can also try using this method.

For the installation method on Ubuntu 22.04, you can follow these steps

1. SSH/Console Login

The first step is, of course, to log in to SSH or access the server via the Console, which is usually provided by your server provider.

If you forget or do not know how to open the server with SSH, you can open CMD/Terminal on your PC or use an application like PuTTY to open it. Details can be read here: Login SSH VPS Linux

If using SSH or Terminal, you can use this command

ssh username@server_ip -p port_ssh

Make sure to change the username according to your SSH access username, for example root, and change server_IP to your server IP address, for example 192.168.8.8. For port_ssh, you can change it to the port used for SSH access. The default SSH port usually used is port 22, so the result will look like this

2. Install PHP and MySQL

Before installing PHP and the Database, make sure the system is updated

sudo apt update && apt upgrade -y

If you want to use MySQL, you can use this command to install Apache and MySQL

sudo apt install apache2 \                 ghostscript \                 libapache2-mod-php \                 mysql-server \                 php \                 php-bcmath \                 php-curl \                 php-imagick \                 php-intl \                 php-json \                 php-mbstring \                 php-mysql \                 php-xml \                 php-zip \                 -y

If you want to use Apache and MariaDB, you can use this command

sudo apt install apache2 \                 ghostscript \                 libapache2-mod-php \                 mariadb-server \                 php \                 php-bcmath \                 php-curl \                 php-imagick \                 php-intl \                 php-json \                 php-mbstring \                 php-mysql \                 php-xml \                 php-zip \                 -y

Once it is fully installed, when you visit the IP using a browser, you will see the default Apache page like this.

Cara Install WordPress di Ubuntu 22.04 Server - 1

Once it appears, you can check the status of MySQL/MariaDB

sudo systemctl status mysql

If it is installed and running, the result will look like this

Cara Install WordPress di Ubuntu 22.04 Server - 2

3. Create Database

Before creating a database, we certainly need to open MySQL first. To open it, you just need to use this command

sudo mysql -u root

If your MySQL already uses a password because it has been secured (How to Install MySQL on Ubuntu Server Securely), then you can open MySQL with this command

sudo mysql -u root -p

Create a database, for example with the name wpgan_db

CREATE DATABASE wpgan_db;

Create a database user and password to access the database wpgan_db that was created. For example, creating a user wpgan_user with the password wpgan_password_123

CREATE USER wpgan_user@localhost IDENTIFIED BY 'wpgan_password_123';

Grant user access rights to the database

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER    ON wpgan_db.*    TO wpgan_user@localhost;

Now you just need to flush privileges and exit MySQL/MariaDB

FLUSH PRIVILEGES;quit

4. Download WordPress to Server

We will place this file inside the folder /srv/www. Because this folder does not exist by default, we need to create it first using this command

sudo mkdir -p /srv/wwwsudo chown www-data: /srv/www

Download the latest WordPress into /srv/www/

cd /srv/wwwcurl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/wwwls

After it is finished, you will get an output that looks more or less like this

Cara Install WordPress di Ubuntu 22.04 Server - 3

Up to this point, we have downloaded WordPress and the installation location is still in the folder /srv/www/wordpress. If you want to install WordPress in another folder, for example /srv/www/wpgan, then you can copy it with the following command

sudo cp -a /srv/www/wordpress /srv/www/wpgancd /srv/www/wpganls

If it is successfully moved, the result will look like this

Cara Install WordPress di Ubuntu 22.04 Server - 4

5. Virtual Host Configuration

Note: Change wpgan in the code in this Virtual Host configuration section to your own folder name.

Run the following command to create a new virtual host file

sudo nano /etc/apache2/sites-available/wpgan.conf

After the file editor opens, enter the code below to continue the configuration, then save the file by pressing CTRL + X.

<VirtualHost *:80>    AllowOverride     DocumentRoot /srv/www/wpgan    <Directory "/srv/www/wpgan">        Options FollowSymLinks        AllowOverride Limit Options FileInfo        DirectoryIndex index.php        Require all granted    </Directory>    <Directory "/srv/www/wpgan/wp-content">        Options FollowSymLinks        Require all granted    </Directory></VirtualHost>

If adding a specific domain, you can change it to look like this

<VirtualHost *:80>    ServerName namaweb.site    DocumentRoot /srv/www/wpgan    <Directory "/srv/www/wpgan">        Options FollowSymLinks        AllowOverride Limit Options FileInfo        DirectoryIndex index.php        Require all granted    </Directory>    <Directory "/srv/www/wpgan/wp-content">        Options FollowSymLinks        Require all granted    </Directory></VirtualHost>

Now activate the virtual host you created

sudo a2ensite wpgan

Enable URL Rewrite before you reload Apache

sudo a2enmod rewrite

So that when the website is accessed it directly displays WordPress, you can turn off the default configuration or use a Virtual Host that is already integrated with the domain.

sudo a2dissite 000-default

After all the processes are finished, now you can reload Apache so that the previous configuration runs

sudo service apache2 reload

Check whether Apache has been successfully reloaded or not

sudo systemctl status apache2

If you get an error Reload failed for The Apache HTTP Server. but the status is already running, then it can be ignored and you can proceed to the next step

6. Connect WordPress to Database

Note: Change wpgan in the command below to your own folder name.

To start connecting the database to WordPress, you do not have to use the CLI, because you can directly visit your server's public IP address and perform the configuration with the interface.

If you want to perform the configuration using the interface, you can continue the tutorial to this page in the WordPress activation section: Manual WordPress Installation

Cara Install WordPress di Ubuntu 22.04 Server - 5

If you want to continue using the CLI, you can proceed by creating the wp-config.php file first

sudo -u www-data cp /srv/www/wpgan/wp-config-sample.php /srv/www/wpgan/wp-config.php

Fill in the database according to what you created previously into the wp-config file

sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/<nama-folder-instalasi>/wp-config.phpsudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/<nama-folder-instalasi>/wp-config.phpsudo -u www-data sed -i 's/password_here/<your-password>/' /srv/www/<nama-folder-instalasi>/wp-config.php

Because I previously created a database with the database name wpgan_db, username wpgan_user and password wpgan_password_123, the result will look like this

sudo -u www-data sed -i 's/database_name_here/wpgan_db/' /srv/www/wpgan/wp-config.phpsudo -u www-data sed -i 's/username_here/wpgan_user/' /srv/www/wpgan/wp-config.phpsudo -u www-data sed -i 's/password_here/wpgan_password_123/' /srv/www/wpgan/wp-config.php

7. Configure wp-config.php

This method only needs to be done if you complete the configuration using the CLI. If the configuration is done directly from the browser page, then this configuration is not necessary.

Next, after adding the database to WordPress, we need to perform configuration for installation verification or salt that is inside the file wp-config.php

sudo nano /srv/www/wpgan/wp-config.php

Inside the wp-config file, look for the following lines, then delete them by pressing CTRL + K

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

After everything is deleted, you can create a new salt through this page: https://api.wordpress.org/secret-key/1.1/salt/. Copy all the content on the page https://api.wordpress.org/secret-key/1.1/salt/ then paste it where you deleted the salt example in the previous wp-config file, until the result looks like this

Cara Install WordPress di Ubuntu 22.04 Server - 6

If done, save the changes and exit the file editor by pressing CTRL + X.

8. Create WordPress Account

To create a WordPress account, you can directly visit your server's public IP address in a browser, and it will appear like this

Cara Install WordPress di Ubuntu 22.04 Server - 7

If everything is filled in, you can continue by clicking the button Install WordPress, and congratulations! Your WordPress has been successfully installed on the Ubuntu server.

Conclusion

Installing WordPress directly via this CLI is actually not recommended. It is more recommended to install WordPress using a control panel so that if there is an error in your WordPress later, especially an error due to files, you can check the files more easily.

However, even though it is not recommended, there is nothing wrong with using this method because everyone's preferences are certainly different.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...