4 Steps to Install WordPress on Debian and Ubuntu Server

Debian and Ubuntu are both of the most popular Linux distributions. Those are used in various cloud platforms and also in local machines. Today in this article, I will explain the steps of installing WordPress on these machines.

These machines could be Virtual Machines or Local machines such as computers. In this tutorial, we will use Debian 10 for WordPress installation; as I have mentioned in the title, you can also use Ubuntu 16.04 or Ubuntu 18.04.

So, let’s get started!

Install WordPress on the Debian/Ubuntu Server

I will explain the simple four steps for the installation of WordPress on Debian 10. You can also use the same command lines for Ubuntu 20.04 distro. Debian and Ubuntu are very similar in the case of their command line.

Installing WordPress CMS, some required programs are needed to Install before WordPress.

👉 LAMP Stack or LEMP Stack (optional)

Step – 1. Install Apache Server With the Latest PHP

WordPress is a web application, and of course, you need to have a running web server on your system (virtual machine or local computer). WordPress is also compatible with other servers like Nginx and LiteSpeed.

In the meantime, WordPress also can be installed in a Cluster Container like Docker or Kubernetes.

In this tutorial, we are going to use the Apache webserver so, open Terminal or SSH session and type:

sudo apt-get update

Check PHP version or Installed in the system or not.

php -v

If PHP is not found shows, then we are going to install the PHP.

So first, we need to add the newest PHP repository key and repository list, for this process follow these commands:

sudo apt -y install lsb-release apt-transport-https ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
adding the newest PHP repository key, and repository list

Now, add the repository list.

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Adding PHP repository list

Now Install the Latest PHP 7.4 version by using the following commands:

sudo apt update
sudo apt install php7.4
Installing Latest php version 7.4.9

Now check the PHP version; if installed, then it will look like as below in the image.

php -v
checking the PHP version

Now install Apache and the latest PHP modules.

sudo apt install apache2 php7.4 libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-soap php7.4-gd php7.4-xml php7.4-intl php7.4-mysql php7.4-cli php7.4-ldap php7.4-zip php7.4-curl
installing Apace and latest PHP modules.

Now enable PHP fpm for the Apache server.

sudo a2enmod proxy_fcgi setenvif
enabling PHP fpm for the Apache server

Then restart the Apache server using the following command:

sudo systemctl restart apache2

After the successful installation of the Apache server and PHP, we need to test the programs it is installed or not.

sudo nano /var/www/html/test.php

Now copy these PHP lines and paste them into your terminal (as shown in the image below):

<?php
phpinfo();
?>

Now hit CTRL+X enter “Y” and hit the Enter key to save the file.

adding php info code in new test.php file

After saving the file, you need to open your IP address in this format https://your-ip-address/test.php.

showing PHP version in browser tab

If your browser window looks like that and shows the PHP version and other details, that means your installation is successful.

You can also use the command to check that, is your Apache server is working or not.

sudo service apache2 status
Apache Server Status checking on terminal

Step – 2. Installation of Database

WordPress requires a database in the backend for managing all the data in structural table format. In this case, MySQL or MariaDB is one of the best choices for the WordPress database.

To install the database, you need to run the following commands:

sudo apt install default-mysql-server
Installation of MySQL or MariaDB Database

After the successful installation of the Database, we need to secure it by password, for this step run the following command.

sudo mysql_secure_installation

This process will prompt five questions, and you need to enter “Y” for the answers. In the first question, enter “Y” and set a new password for the database.

Securing WordPress Database with password

Now, that we have secured our Database, now need to create a new database with a new user for WordPress. So, run the following commands.

sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'wordpress_pss123';
GRANT ALL PRIVILEGES on wordpress.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
create a new database with a new user for WordPress

Now check the database list for confirmation, use the following commands:

mysql -u root -p

*enter your password

SHOW DATABASES;
checking the databases list

Database creation is successful; next is the installation of WordPress.

Step – 3. Install WordPress on the Debian or Ubuntu Server

Now in this step, I am going to Install WordPress CMS on our system. For this process, we need to use wget syntax for downloading the WordPress compressed file. So, run these commands for installing WordPress.

First, change the directory to.

cd

Now run the following command for WordPress.

wget -c https://wordpress.org/latest.tar.gz
Install WordPress on Debian 10 or Ubuntu 18.04

When the download has been completed, we need to decompress the WordPress Source files and move them to the /var/www/html/ directory. Next, we need to set write permission to the directory.

tar -xvzf latest.tar.gz

sudo mv wordpress/ /var/www/html/

Here we have used mv (move command), perhaps you can use the rsync command for just copying the files.

sudo chown -R www-data:www-data /var/www/html/wordpress/
sudo chmod 755 -R /var/www/html/wordpress/
WordPress Source files and move to the /var/www/html/ directory

Now, create a new virtualhost for WordPress, so whenever you type just your naked domain (exmaple.com; without www or http) it will open correctly with the right protocol in any browser.

Use the following command to create a new virtualhost for WordPress.

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

And add the following lines:

<VirtualHost *:80>
    ServerAdmin [email protected]
      DocumentRoot /var/www/html/wordpress
    ServerName example.com
    ServerAlias www.example.com
     <Directory /var/www/html/wordpress>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
    </Directory>
     ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

Note:- replace “example.com” with your actual domain name. Save to this file hit CTR+X enter Y and Enter.

When your new Virtualhost file creation is done, we need to rewrite the Apache module and then reload or restart the Apache server. So, for this process, we need to follow these commands.

sudo ln -s /etc/apache2/sites-available/wordpress.conf /etc/apache2/sites-enabled/wordpress.conf
sudo a2enmod rewrite

sudo systemctl restart apache2
rewrite the Apache module and then reload or restart the Apache server

Now our server-side installations have been completed. Now, we need to configure WordPress.

Step – 4. WordPress Configuration With Database

Now, you need to open your domain name in the new browser tab as “example.com.” When you open your domain name, as shown in the picture, you will also be prompted to select your language.

 select your wordpress language

After selecting the language, you will be prompted to configure your database with your WordPress CMS.

 configure your database with your WordPress CMS

Now fill in all the credentials of the database, which we have created in the second step.

filling all the credentials of the database

After filling in the credentials of the database, WordPress will prompt you to run WordPress installations, so click on “Run the installation.”

Run the WordPress installation

Then configure WordPress Admin credentials and Website Name.

configure WordPress Admin credentials and Website Name

Now login to your WordPress Dashboard.

login to your WordPress Dashboard

Okay, guys, that’s it for today’s tutorial.

Summary

In the next tutorial, we will learn the step-by-step installation of phpMyAdmin. So stay tuned and if you have any questions and problems related to WordPress installation, Ask me in the comment box.


Pronay Sarkar

Hello!
I am Pronay Sarkar, I love to write about tech and stuff. I am a college graduate from the University of Delhi.

6 thoughts on “4 Steps to Install WordPress on Debian and Ubuntu Server”

  1. Thank you so much for this tutorial!
    After rebuilt three times…I finally did it!
    (Always stuck at “installing php7.4” part…)
    This might be the best guide I’ve ever see!

    Reply
  2. Thank you for the step by step.
    I have a issu in the step 3 end, step 4 start.
    When i go on my domain name on the browser, i have the apache defaut page and not the wordpress page.
    Do you lnow where i miss something ? 🙂

    Reply
    • If you specify what kind of issue facing then, It would very to explain. But at the end of 3rd step, you have seen some code and commands that’s you have to execute. However, I have updated the code (Virtual Host file), and If you also update the file accordingly, then I think it will not open the default apache page. You should also execute the two commands those are mentioned in the article for enabling the virtual host file.

      If you set up 3rd step perfectly then 4th step would be easier for you, for that just you have to open your domain name on the browser, then it will open the WordPress configuration page, instead of default apache page.

      Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.