How to install WordPress on Ubuntu 18.04 using the LAMP Stack

WordPress is undoubtedly one of the most popular content management systems (CMS) on the market thanks to its ease of use and flexibility to create all kinds of websites. The software can also be installed on different types of hosting, including a (VPS, for its acronym in English).

To install WordPress on your server, you can use the LAMP stack (Linux, Apache, MySQL and PHP). This method is ideal for when you want to have full control of the WordPress backend, both for testing and advanced use.

Linux is the operating system with the web server, and the database used to process the dynamic content of the website.

This article will cover the details of installing WordPress using the LAMP stack, from installing the Apache server to configuring WordPress through a web browser.

Remember, before installing WordPress on Ubuntu, you must access your VPS using SSH. Look at our if you have problems.

professional tip

always make sure you have the required sudo access, as this method requires a couple of installations and some basic firewall setup.

Step 1. Install and configure the Apache web server

The first step in configuring the LAMP stack is to install and configure the Apache server. First of all, we need to update the list of packages on your system and update the packages to the latest version. Do it using these commands in your SSH client:

sudo apt update -y sudo apt upgrade -y

If you are prompted to enter a password, enter the root password of your VPS and press Enter.

Now it’s time to install the Apache2 web server on your VPS. If you buy a VPS plan from , it comes with Apache2 pre-installed. In this case, if you follow the next step, it doesn’t harm your VPS, but you can skip it.

Run the following command to install Apache2:

sudo apt install apache2

VPS does not come pre-installed. However, if you have installed UFW on your VPS, it can restrict HTTP and HTTPS traffic from Apache. To check the UFW application profiles, enter this command:

sudo ufw app list

This will provide a result like the following:

Available applications:  Apache Apache Full Apache Secure OpenSSH

If you run that command on a default VPS that doesn’t have UFW, it should print the following output:

-bash: ufw: command not found

Step 2. Install PHP

PHP is required for WordPress to communicate with the MySQL database and display dynamic content. You will also need to install additional PHP extensions for WordPress.

Run the following command to install PHP and PHP extensions at the same time:

See also  ERR_NAME_NOT_RESOLVED: 6 Proven Methods to Fix It

sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-xml php-mbstring php-xmlrpc php-zip php-soap php-intl -y

When you request a directory without specifying a filename, priority will be given to index.html and, therefore, this will be the one that will appear. You can change the priority order in the file dir.conf. Use the following command to open it with the Nano text editor:

sudo nano /etc/apache2/mods-enabled/dir.conf

You should see the following:

When loading the website, the files will be displayed from left to right. You have to put all the files in the correct priority order. For example, if you want index.php have higher priority than index.htmljust move index.php to the left of index.html.

When you have changed the file, save it and exit by pressing CTRL+X. then write Y to save the changes and Enter to close it.

Now you have to restart the Apache2 web server for the changes to take place. To do this, run the following command:

sudo systemctl restart apache2

Create a PHP file that will serve as an example in the main directory of the web to check if PHP works. Use this command to go to the directory:

cd /var/www/html

Next, use this command to create an example PHP file and open it with the Nano text editor:

nanosample.php

In the text editor, insert the following code:

Save and exit the file.

Now, access the file by entering http://your-IP-adress/sample.php in your web browser. You should see this PHP information page:

professional tip

You can find your IP address in your hPanel in the VPS section

We recommend deleting the file after checking the installation. PHP information shows PHP installation and server settings, which can help cyber attackers to access your server. Use this command to remove it:

sudo rm /var/www/html/sample.php

Step 3. Configure MySQL and create a database

Once you have the web server up and running, you can install the MySQL database. The following command will help you do it:

apt install mysql-server -y

This command will ask you for a password. Once the installation begins, depending on what you need, you can press Y Y ENTER to complete the installation.

After installing MySQL on your VPS, open the MySQL terminal by typing the following command:

sudo mysql

You can set a password for the root user using the following command:

mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘Password’;

Make sure to enter a strong MySQL root password instead of PASSWORD.

To reflect these changes, use the command flush as it’s shown in the following:

See also  How to manage and list services in Linux

mysql> FLUSH PRIVILEGES;

Use the following command to create a WordPress database:

mysql> CREATE DATABASE WordPressBD DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now, we will create a MySQL user account to operate on the new WordPress database. We will use WordPressDB as the database name and WordPressUser as the username. To create a new user and grant privileges use the following command:

GRANT ALL ON WordPressBD.* TO ‘ WordPressUser ‘@’localhost’ IDENTIFIED BY ‘NewPassword’;

Provide a strong password instead of New Password. To reflect these changes, use the command:

mysql> FLUSH PRIVILEGES;

Once you’re done, exit the MySQL screen by typing this command:

mysql> EXIT;

Step 4. Prepare to install WordPress on Ubuntu

It’s time to prepare for the WordPress installation by creating a WordPress configuration file and a WordPress directory.

Creating a WordPress.conf file

Create a configuration file, for example: WordPress.conf. put it in /etc/apache2/sites-available/. This will be a replica of the default configuration file that already exists in this location. Use the following command:

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

Important! Remember that on Linux all Linux configuration file names and locations are case sensitive on Linux.

Once you run that command, you’ll be taken to the Nano text editor to edit the WordPress.conf file. Activate the .htaccess adding these lines to the VirtualHost block:

<Directory /var/www/wordpress />   AllowOverride All </Directory>

Close and save the file by pressing CTRL+X. Press Y Y Enter when you are asked.

Create a directory for WordPress

Next, create a directory for WordPress at /var/www/. In our example, your full path will be /var/www/wordpress. To do this, use the command mkdir to create the directory:

mkdir /var/www/wordpress

Now activate the mod_rewrite To use the WordPress permalink function by executing the following command in the terminal:

sudo a2enmod rewrite

You will have to restart the Apache web server using the following command:

systemctl restart apache2

The next step is to change the directive ServerName in the File /etc/apache2/apache2.conf. Open the file with this command:

nano /etc/apache2/apache2.conf

You will have to configure the directive ServerName with the IP address or server name by adding the following line to the file /etc/apache2/apache2.conf:

ServerName

Close and save the file.

Now, you have to check if the Apache configuration is correct by running the following command in the terminal:

apachectl configtest

If the setup works fine, it should print the following output:

Syntax OK

Step 5. Configure and install WordPress

Once all the preparations are complete, it’s time to install WordPress. There are two methods: configure WordPress through a web interface or manually edit the file wp-config.php.

See also  How to create a free web page? - Explanatory video

Method 1. Configure WordPress through a browser

First, install the package wget on your VPS. This will be useful for downloading the WordPress files. Run this command at the command line:

sudo apt install wget -y

Next, use the wget command followed by the WordPress download link:

wget https://wordpress.org/latest.zip

Once you’ve downloaded the zip file, install the unzip utility using these commands:

ls sudo apt install unzip -y

You will now need to move the file to the correct directory before unzipping it. Use the command:

mv latest.zip /var/www/html

Next, navigate to the directory and unzip the file using these commands:

cd /var/www/html unzip latest.zip

Then use the following command to move the directory:

mv -f wordpress/* ./

The last step is to remove index.html. Use the following command:

sudo rm -rf index.html

You can use the command ls to check if the file has been deleted index.html. Once done, restart Apache using these commands:

sudo systemctl restart apache2 sudo chown -R www-data:www-data /var/www/

Finish configuring WordPress through a web browser. Open a web browser and type the IP address of the server. The following steps will be similar to a standard WordPress setup.

First, select a language for WordPress and click Continue.

A message will appear Welcome to WordPress with the information you’ll need to complete setup. Click the button Go for it! to continue.

It will then take you to the main settings page. Fill in the following information:

  • Database name – enter the name you set when setting up the WordPress database. In this case, it will be wordpressdb.
  • Username – enter the MySQL username that you have configured before for the database.
  • Password – enter the password you created for the database user.
  • database host – keep the default value here localhost.
  • table prefix – let wp_ in this field.

click on Send to continue.

A new message will appear saying that WordPress can now communicate with your database. click on Run the installation.

Then, you will have to enter more information:

  • site title – write the name of the WordPress website. To optimize your site, we recommend that you enter your domain name.
  • Username – create a new username that you will use to access WordPress.
  • Password – create a…
Loading Facebook Comments ...
Loading Disqus Comments ...