WordPress is, truly, the most broadly utilized blogging stage on the planet. In any case, the device can be utilized for considerably more than simply blogging. With the correct expansion of augmentations, you can transform WordPress into a web based business website, a mixed media webpage, and substantially more. On the off chance that you happen to have your very own server, you can have a WordPress establishment, without hosting to go to a third get-together. Furthermore, that is actually what we will do here. In this instructional exercise, you will figure out how to introduce the vital segments just as the WordPress stage on Ubuntu Server 18.04. This will just expect a certain something: That you have Ubuntu Server going.


The main activity is to get our LAMP (Linux Apache MySQL PHP) server fully operational. Since Ubuntu is as of now there, every one of that should be done is introduce the optional segments. Since we’re utilizing Ubuntu, this should be possible with a solitary direction. In any case, before we do that, we need to ensure our server is exceptional. Open a terminal window and issue the accompanying directions:

you can also like WordPress Tips & Tricks for Developers

Install and Configure Apache 2

LAMP uses Apache web server 2 which is popular and widely used. You can install Apache using Ubuntu’s package manager as shown below:

sudo apt update
sudo apt install apache2

These commands require you to provide passwords. Press Y on the command prompt and hit ENTER to continue the installation.

UFW firewall is available in all the Ubuntu installations by default. The UFW firewall should allow HTTP and HTTPS traffic. If you don’t use UFW, feel free to skip this step. You can check the UFW application profiles using the following command:

sudo ufw app list

This will provide an output as:

Available applications:
 Apache Full
 Apache Secure

To allow HTTP and HTTPS traffic for Apache Full profile you can execute the command below:

sudo ufw allow in "Apache Full"

To confirm this, have a look at this profile information by using:

sudo ufw app info "Apache Full"

To verify if Apache was installed correctly, you would need the public IP address. You can get it by using the command below:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

This command will provide you with 2-3 IPs. You might have to try all of this by using your_public_IPAddress on a browser. It will display the default Ubuntu Apache page.

Install MySQL

Once you have the web server running, you can install the MySQL database. The command below will help you with the task:

sudo apt install mysql-server

This command will prompt for a password. Once the installation starts, based on your requirement you can press Y and ENTER which completes the installation. Open MySQL terminal using:

sudo mysql

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

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

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


You can type exit to come back from the MySQL prompt. This completes the MySQL installation.

Install PHP

To display dynamic content, you need PHP which you can install by using:

sudo apt install php libapache2-mod-php php-mysql

Install Additional PHP extensions for WordPress using the command below:

sudo apt install php-curl php-gd php-xml php-mbstring  php-xmlrpc php-zip php-soap php-intl

When you request for a directory the index.html is displayed as a default setting. In case you want to show index.php instead of index.html, you need to open the dir.conf file using the vi editor:

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

It will look as shown below:

<IfModule mod_dir.c>
   DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

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

For the changes to be visible, restart the Apache server using:

sudo systemctl restart apache2

To test the PHP, you can create a sample PHP file sample.php and add these lines of code:


This file needs to be added to the Web Root of Apache which is located at – /var/www/html/

Once this is saved, you can try to access this page by using Your_Public_IP/Sample.php.

MySQL Setup for WordPress

You will have to login into MySQL as a root user. To do so, use the command below:

mysql -u root -p

You will get a prompt to type the password for root, which you had set up earlier. Once you have logged in, you can create a separate database for WordPress.

Below we have created a new DB called WordPressDB:


Next, you will create a separate user for WordPress. Name this as WordPressUser. To create a new user and grant privileges using the command below:

mysql> GRANT ALL ON WordPressDB.* TO ' WordPressUser '@'localhost' IDENTIFIED BY 'NewPasswordToBeSet';

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


Once this is completed exit the MySQL prompt.

Prepare to Install WordPress on Ubuntu

Create a configuration file, for example :WordPress.conf. Place it to /etc/apache2/sites-available/. This will be a replica of the default configuration file which already exists in this location.

Protip: Remember, all locale names in Linux are case sensitive!

Also, create a WordPress directory (or you can provide any other name at location /var/www/). The complete location would be /var/www/wordpress.

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

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

Once this is edited, save the file.

Next, you can enable the mod_rewrite to use WordPress permalink feature. This can be done using:

sudo a2enmod rewrite

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

You can test this complete configuration by using the below command.

Protip: Ensure it gives the Syntax OK message. Any other additional message can be ignored as this will not impact the installation.

sudo apache2ctl configtest

To see the changes made, restart the Apache server using the previously mentioned restart command:

sudo systemctl restart apache2

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:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz

Extract this file using:

tar xzvf latest.tar.gz

Here you can create a .htaccess file:

vi /tmp/wordpress/.htaccess

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

mv /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Create the below folder at the given location:

mkdir /tmp/wordpress/wp-content/upgrade

This completes our initial setup which can be copied to the document root.

sudo cp -a /tmp/wordpress/. /var/www/wordpress

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

To change the ownership, you can use this command:

sudo chown -R www-data:www-data /var/www/wordpress

Also, you will have to set the correct permission to the directories and files:

sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;

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

curl -s https://api.wordpress.org/secret-key/1.1/salt/

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

vi /var/www/wordpress/wp-config.php

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.

define('DB_NAME', 'WordPressDB');

/** MySQL database username */
define('DB_USER', 'WordPressUser');
/** MySQL database password */
define('DB_PASSWORD', 'DB_Password');

Also, you can add the file system method at the very bottom, as shown below:

define('FS_METHOD', 'direct');

Save the file.

This completes the backend setup. Now you can access WordPress via the interface by using the URL Your_IP_Address.

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

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

Be sure to change the username and password to improve WordPress security. By pressing the Install WordPress button, you will complete your WordPress setup and will be prompted to a login screen.

Provide the WordPress user name and password to access the dashboard.


With this, you now know how to install WordPress on Ubuntu 18.04 with the LAMP stack. From here you can start exploring all the amazing WordPress features and develop some jaw-dropping websites.


Please enter your comment!
Please enter your name here