Knowledge Base
MilesWeb / WordPress FAQ

How to Install WordPress on Ubuntu 18.04 Using LAMP Stack?

Approx. read time : 6 min

WordPress is obviously one of the most popular Content Management Systems (CMS) available in the market. There are multiple ways in which you can install WordPress – one of them is using LAMP. This method allows you to host your very own WordPress website on a VPS. In this tutorial, you will learn about installing WordPress on Ubuntu 18.04.

Many of them use this method as it offers full control of WordPress backend for experimentation and advanced uses.

Also, users mostly keep LAMP stack for their WordPress development environment.

LAMP refers to Linux, Apache, MySQL, and PHP. Linux operating system comes with Apache web server and MySQL Database that uses PHP to process dynamic website content.

In this tutorial, you will learn to install WordPress on Ubuntu 18.04 using LAMP stack.

Note: Make sure that you have the required sudo access as this method calls for a couple of installations and a basic firewall configuration.

Also, note that before you install WordPress on Ubuntu, you need to access your VPS using SSH.

Install and Configure Apache 2

LAMP uses the popular and widely used, Apache web server 2. Ubuntu’s package manager helps to install Apache as shown below:

These commands need you to provide passwords. On the command prompt, press Y and hit ENTER to continue the installation.

By default, the UFW firewall is available in all the Ubuntu installations. The UFW firewall allows traffic via HTTP as well as HTTPS. If you aren’t using UFW, skip this step. Use the below command to check the UFW application profiles:

This will provide the below output:

Execute the below command to allow HTTP and HTTPS traffic for Apache Full profile:

To confirm if this has worked, check this profile information by using:

In order to verify if Apache was installed correctly, you will need the public IP address. Use the below command to get it:

You will be provided with 2-3 IPs using this command. If you want to try all of this, use http://your_public_IPAddress on a browser. The default Ubuntu Apache page will get displayed with this.

Install MySQL

After the web server starts running, you can install the MySQL database. This can be done using the below command:

This command will ask for a password. After starting the installation, based on your preference you can press Y and ENTER to complete the installation. To open MySQL terminal use the below command:

Set a password for the root user using the command below:

To verify these changes, use Flush command as shown below:

To come back from the MySQL prompt, type exit. With this the MySQL installation gets completed.

For displaying dynamic content, you need PHP which can be installed by using:

Use the below command to install additional PHP extensions for WordPress:

The index.html gets displayed as a default setting, when you request for a directory. If you want to show index.php instead of index.html, open the dir.conf file using the vi editor as below:

It will appear as below:

Swap the positions of index.html and index.php and save the file.

To make the changes visible, restart the Apache server using:

For PHP testing, you can create a sample PHP file sample.php and add the below lines of code:

Add this file to the Web Root of Apache which is located at – /var/www/html/

After saving this, try to access this page by using http://Your_Public_IP/Sample.php.

MySQL Setup for WordPress

Login into MySQL as a root user. For this, use the command below:

You will be prompted to type the password for root that is set up earlier. After logging in, it is possible to create a separate database for WordPress.

Below is a new DB created called WordPressDB:

Now, create a separate user for WordPress with the name WordPressUser. For creating a new user and granting privileges, use the command below:

Give a strong password in place of NewPasswordToBeSet. To verify these changes, use the command:

After it gets completed, exit the MySQL prompt.

Prepare to Install WordPress on Ubuntu

Create a configuration file, for example :WordPress.conf. Locate it to /etc/apache2/sites-available/. This will be a copy of the default configuration file that is already present in this location.

Note: All locale names in Linux are case sensitive!

Additionally, create a WordPress directory (or provide any other name at location /var/www/). The complete location would appear as /var/www/wordpress.

For testing this, the file WordPress.conf will be the Apache configuration file. In the file, you can enable .htaccess by including these lines to the VirtualHost block:

After editing this, save the file.

Next, enable the mod_rewrite to use WordPress permalink feature. You can do it with the below command:

In the file /etc/apache2/apache2.conf, change the ServerName directive by offering the server’s IP or hostname.

This complete configuration can be tested by using the below command:

Note: Check if it gives the Syntax OK message. Ignore any other additional message as this won’t impact the installation.

For verifying the changes done, restart the Apache server using the previously mentioned restart command:

Configure and Install WordPress on Ubuntu

You can change your location to a directory and start downloading WordPress. This can be done as shown below:

Use the below command to extract this file:

Now you can create a .htaccess file:

Save the file and rename the wp-config-sample.php file using the command:

Create the below folder at the given location:

With this, the initial setup gets completed which can be copied to the document root.

To check if everything works correctly, you will have to change the ownership of WordPress files to the www-data users and groups. These users are those that Apache web server will use.

For changing the ownership, you can use this command:

Also, it is important to set the correct permission to the directories and files:

For the initial configuration, it requires the WordPress salt to be generated. This can be done using:

This will give a different output every time and will comprise of a list of salt values. The output of the above command needs to be copied and added to the wp-config.php file.

Replace the existing dummy values within this file. Save the file after making the changes.

The wp-config.php file contains some Database configuration at the top. Replace the DB_NAME, DB_USER, DB_PASSWORD with values you have created for WordPress.

Saving this file completes the backend setup. Now WordPress can be accessed via the interface by using the URL http://Your_IP_Address.

Next settings will be similar to the regular WordPress setup. First, you will be asked to select a language.

Then you will be redirected to a page where you can set the username and password.

Make sure that you change the username and password for enhanced WordPress security. After clicking the Install WordPress button, you will complete your WordPress setup and will be directed to a login screen.

Here enter the WordPress user name and password to access the dashboard.

Wrap Up

Now you have learned to install WordPress on Ubuntu 18.04 with the LAMP stack. From here you can start discovering all the amazing WordPress features and develop some amazing websites.

Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.
Need help? We’re always here for you.
Register Your Free Domain Name