WordPress is one of the most popular open-source Content Management Systems (CMS). It is based on PHP and MySQL and works pretty well on almost all Ubuntu distributions. Its development started in 2003 and it has been widely accepted by webmasters since then.
WordPress is great if you want to start a blog, a company website or a portal for your business. There are thousands of free themes that you can install on WordPress to create professional stunning website in minutes.
Unlike in shared hosting where WordPress is set up using script installers like softaculous, it requires manually installation on a VPS server.
In this guide, we are going to show you how to download the latest stable release of WordPress and install it on your Ubuntu 22.04 server to run a fully functional website.
- Ubuntu 22.04 server
- Apache, MySQl and PHP
- A non-root user with sudo privileges
Step 1: Switch to the tmp folder and download the latest version of WordPress
We need to download the latest WordPress release from https://wordpress.org/latest.tar.gz. To do this, type the commands below on a terminal window:
$ cd /tmp $ curl -O https://wordpress.org/latest.tar.gz
Step 2: Unzip the tar archive
$ tar -xzvf latest.tar.gz
Once the unzipping process is completed, a WordPress folder will be created on the path /tmp/wordpress.
Step 3: Move the directory to the root of your website
In order for WordPress to work, we will need to move its directory to the root folder of our website using the command below:
$ sudo mv wordpress /var/www/html/wordpress
Step 4: Change ownership and Set permissions for WordPress directory
In order for Apache to access WordPress, we need to change the ownership of the ownership of the directory to www-data using the command below:
$ sudo chown -R www-data:www-data /var/www/html/wordpress/
Then we need to set the right file permissions using the commands below:
$ sudo chmod -R 755 /var/www/html/wordpress/
Step 5: Open MySQL server and create a database for WordPress
WordPress relies on a MySQL database. So we need to create one using the commands below:
$ sudo mysql -u root -p
Enter your password and press Enter.
Then enter the commands below, remember to replace the database, user and password with your preferred values:
mysql> CREATE DATABASE wordpress_db;
mysql > CREATE USER ‘wordpress_user’@’localhost’ IDENTIFIED BY ‘root123′;
mysql > GRANT ALL ON wordpress_db.* TO ‘wordpress_user’@’localhost’;
mysql > FLUSH PRIVILEGES;
mysql > EXIT;
When you installed WordPress, a default configuration file was created. We need to move the file and set the database configurations using the commands below:
$ sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
Then we need to edit the file using our nano editor using the command below:
$ sudo nano /var/www/html/wordpress/wp-config.php
You will see a screen similar to the image below, enter the correct database name, user and password:
When you are done, press CTR+O and Y to save the changes.
Step 6: Apache Virtual Host configurations
Create an apache Virtual host configuration file and add the following content:
Save all changes using ‘Ctrl+O’ and press ‘Y’. Use the following command to reload and restart the apache web server:
$ sudo a2ensite www.domain.com.conf $ sudo a2enmod ssl rewrite $ sudo systemctl restart apache2
Step 7: Finalize the WordPress Installation
Next, you need to visit the new WordPress site using the public IP address or domain name on your browser to finalize the configuration.
Since we installed our WordPress on a sub-folder, we will have to visit www.example.com/wordpress for our site to work.
A screen similar to the one below will be displayed and we can click continue to finish the installation:
Click on ‘Continue’ to move ahead. In the other screen, the following page will be displayed in your browser. Enter the required details and complete the installation process.
If you get the error, Your PHP installation appears to be missing the MySQL extension which is required by WordPress”. You will need to install all PHP modules required for the smooth functioning of WordPress using the command below:
$ sudo apt-get install php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip php-curl php-xmlrpc
Then, restart Apache using the command below:
$ sudo service apache2 restart
Then, visit your WordPress site one more time to finalize the installation.
That’s it; you have now installed the most popular content management system on your server. You can now select your preferred theme, plugins and start creating posts. Remember to update your WordPress once a new version is released. This will ensure that your site has the latest WordPress version with new features and bug fixes.