How to install WordPress on Ubuntu 18.04

Filed Under: Ubuntu

In this article, we will focus on how to install WordPress on Ubuntu 18.04. WordPress is a free and open-source content management platform based on PHP and MySQL. It’s the world’s leading blogging and content management system with a market share of over 60%, dwarfing its rivals such as Joomla and Drupal.

WordPress was first released on May 27th, 2003 and powers over 60 million websites to date! So powerful and popular it has become that some major brands/companies have hosted their sites on the platform. These include Sony Music, Katy Perry, New York Post, and TED.

Why WordPress is so Popular?

So why is WordPress this popular? Let’s briefly look into some of the factors that have led to the immense success of the platform.

Ease of Use

WordPress comes with a simple, intuitive and easy to use dashboard. The dashboard doesn’t require any knowledge in web programming languages like PHP, HTML5, and CSS3 and you can build a website with just a few clicks on a button. In addition, there are free templates, widgets, and plugins that come with the platform to help you get started with your blog or website.

Cost effectiveness

WordPress drastically saves you the agony of having to pay developer tonnes of cash to develop your website. All you have to do is to get a free WordPress theme or purchase one and install it. Once installed, you have the freedom to deploy whatever features that suit you and customize a myriad of features without running much code. What’s more, is that it takes a much shorter time to design your site that coding from scratch.

WordPress sites are Responsive

WordPress platform is inherently responsive and you do not have to stay awake worrying about your sites being able to fit across multiple devices. This benefit also adds to your site being ranked higher in Google’s SEO score!

WordPress is SEO ready

WordPress is built using well-structured, clean and consistent code. This makes your blog/site easily indexable by Google and other search engines thereby making your site rank higher. In addition, you can decide which pages rank higher or alternatively use SEO plugins like the popular Yoast plugin which enhances your site’s ranking on Google.

Easy to install and upgrade

It’s very easy to install WordPress on Ubuntu or any other operating system. There are so many open-source scripts to even automate this process. Many hosting companies provide a one-click install feature for WordPress to get you started in no time.

Install WordPress on Ubuntu 18.04

Before we begin, let’s update and upgrade the system. Login as the root user to your system and update the system to update the repositories.

apt update && apt upgrade


update and upgrade the ubuntu system

Next, we are going to install the LAMP stack for WordPress to function. LAMP is short for Linux Apache MySQL and PHP.

Step 1: Install Apache

Let’s jump right in and install Apache first. To do this, execute the following command.

apt install apache2


Install Apache2

To confirm that Apache is installed on your system, execute the following command.

systemctl status apache2


how to check apache2 status

To verify further, open your browser and go to your server’s IP address.



Apache Web Server Default Page

Step 2: Install MySQL

Next, we are going to install the MariaDB database engine to hold our WordPress files. MariaDB is an open-source fork of MySQL and most of the hosting companies use it instead of MySQL.

apt install mariadb-server mariadb-client


Install MySQL Mariadb Server Mariadb Client

Let’s now secure our MariaDB database engine and disallow remote root login.

$ mysql_secure_installation

The first step will prompt you to change the root password to login to the database. You can opt to change it or skip if you are convinced that you have a strong password. To skip changing type n.

Change The Root Password

For safety’s sake, you will be prompted to remove anonymous users. Type Y.

Remove Anonymous Users

Next, disallow remote root login to prevent hackers from accessing your database. However, for testing purposes, you may want to allow log in remotely if you are configuring a virtual server

Disallow Root Login Remotely

Next, remove the test database.

Remove Test Database

Finally, reload the database to effect the changes.

Reload Privilege Table

Step 3: Install PHP

Lastly, we will install PHP as the last component of the LAMP stack.

apt install php php-mysql


Install Php

To confirm that PHP is installed , created a info.php file at /var/www/html/ path

vim /var/www/html/info.php

Append the following lines:


Save and Exit.

Open your browser and append /info.php to the server’s URL.



Info Php Webpage

Step 4: Create WordPress Database

Now it’s time to log in to our MariaDB database as root and create a database for accommodating our WordPress data.

$ mysql -u root -p


Mysql Root Login

Create a database for our WordPress installation.

CREATE DATABASE wordpress_db;


Create WordPress Database

Next, create a database user for our WordPress setup.

CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'password';


Create User For WordPress Database
Grant privileges to the user

Next, grant the user permissions to access the database

GRANT ALL ON wordpress_db.* TO 'wp_user'@'localhost' IDENTIFIED BY 'password';


Grant Privileges To Wp User On WordPress Database

Great, now you can exit the database.



Step 5: Install WordPress CMS

Go to your temp directory and download the latest WordPress File

cd /tmp && wget


Download WordPress

Next, Uncompress the tarball which will generate a folder called “wordpress”.

tar -xvf latest.tar.gz


Uncompress WordPress Tarball

Copy the wordpress folder to /var/www/html/ path.

cp -R wordpress /var/www/html/

Run the command below to change ownership of ‘wordpress’ directory.

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

change File permissions of the WordPress folder.

chmod -R 755 /var/www/html/wordpress/

Create ‘uploads’ directory.

$ mkdir /var/www/html/wordpress/wp-content/uploads

Finally, change permissions of ‘uploads’ directory.

chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads/

Open your browser and go to the server’s URL. In my case it’s


You’ll be presented with a WordPress wizard and a list of credentials required to successfully set it up.

install wordpress on ubuntu 18.04

Fill out the form as shown with the credentials specified when creating the WordPress database in the MariaDB database.

Leave out the database host and table prefix and Hit ‘Submit’ button.

install wordpress on ubuntu 18.04

If all the details are correct, you will be given the green light to proceed. Run the installation.

Alright Sparky Run The Installation

Fill out the additional details required such as site title, Username, and Password and save them somewhere safe lest you forget. Ensure to use a strong password.

Welcome More Information Needed

Scroll down and Hit ‘Install WordPress’.

If all went well, then you will get a ‘Success’ notification as shown.

Success installing WordPress


Click on the ‘Login’ button to get to access the Login page of your fresh WordPress installation.

Log In To WordPress

Provide your login credentials and hit ‘Login’.

wordpress dashboard

Voila! there goes the WordPress dashboard that you can use to create your first blog or website!

Congratulations for having come this far. You can now proceed to discover the various features, plugins, and themes and proceed setting up your first blog/website!


  1. muhammad afnan afif says:

    the best tutor ever thanks

  2. Saintly says:

    Uh hello.

    I’ve just finished installing WordPress on my webserver.
    Everything worked fine for some minutes, then, out of the nowhere,
    it tells me “Error establishing a database connection”.
    I have done everything exactly like you (except setting up Apache2, I already did that way before).
    Where am I/did go wrong? Could anyone give me a solution/explanation if possible?

    However, this is a great tutorial. If you would include some troubleshooting with (probably) common errors like this, it would be even way better!

    Thanks in advance,


    1. Pankaj says:

      Check wp-config.php file for database settings.

  3. NUTHORDE says:

    I just finished installing Apache but now I’m trying to go to my server IP address on my bowser but I keep getting the “Unable to connect” error. I tried accessing to other websites and they work fine but my server is not giving me the same result. Please help me.

  4. MAteusz says:

    The best tutorial which I have ever seen.

  5. Anurag Malti Chaurasia says:

    This article is really good, thanks for the same. I ran into few errors will update soon


    change apache2 conf file to change the path from http://ip/wordpress to http://ip

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


    DocumentRoot /home/user/www/wordpress

    sudo service apache2 restart

    1. freddie21Mon says:

      thats work for me, but it’s just for the index.php not for the entire settings, ive already tried to click some button and it’s redirect to ip/wordpress and got 404 not found. any help?

  7. ah007 says:

    great man, great work
    انت راجل عظيم فشخ

  8. Luis says:

    The best internet tutorial

  9. Miracle says:

    Hello thanks for this guide. please i am a really bite confused, do you i have to follow all this process if i want to create a new wp on my server with my subdomain? if yes how can i extract the wp files to the subdomain folder

    someone helped me set on my server but now i want to learn how to do it on my own

  10. Emre Yildirim says:

    Hello, I followed all the steps but my server is on a virtual box as a virtual server. When I type my virtual servers IP adress to access to WordPress, it doesnt seem to work. What Ip adress am I supposed to use to access wordpress from my virtual machine

  11. Ben Tai says:

    Thanks for the tutorial. You just save my day.

  12. Brayan z says:

    Excelent tutorial, just one thing, i need that my index redirects directly to wordpress, how can i do that? thanks for the help

    1. Vedat says:

      Could you figure out how you can do that?

  13. Sam says:

    Everything worked well thank you but now I’m lost, what are you meant to do with the index.html file to replace it? I never did and after I change my site url it just loads the apache2 default page.

  14. Bakri says:

    I stell have a problem when I try to save the info.php file I did everythng right but I can’t save the file and exit from the terminal can u help please

  15. markel says:

    Great. got the site up.

    thank you

  16. cysersery says:

    Thank you very much, very well explained

  17. pablitoo says:

    How to fix 2MB upload file? I tried everything ;(

  18. Edwin Masripan says:

    in your chown you did not do ‘-R’, as a result, I can’t upload anything to WP.

    I added chown -R www-data:www-data /var/www/html/wordpress.

    Now it works handsomely TQ

    1. Pankaj says:

      Thanks, I have fixed the tutorial.

  19. Nathan says:

    I am trying to install any plugin or theme but it always asks for FTP credentials, no matter what I do it always says it failed to create the directory, but when I check the Site Health all the directories are writable.

    Where could I have gone wrong?

    Should I reinstall the entire server and start over?

    Thanks, this was really helpful to get WordPress up and running quickly!

  20. Alex de la Rosa says:

    Also had to add
    a2enmod proxy_fcgi setenvif
    a2enconf php7.0-fpm
    service apache2 restart

    If Apache is showing the html code instead of the php information page.

  21. Ahmet says:

    Great document, thanks mate

  22. xpil says:

    Great article. You are missing one small step though: after php installation, apache2 service needs to be restarted for the php to kick in.

  23. Manas says:

    Please add how to add desired url to instead of port number

  24. Tuhin Debnath says:

    Hi Pankaj,

    Thank you for the nice post, please correct the first command to

    apt-get update && apt-get upgrade

  25. Stephen Liu says:


    OS-Ubuntu 18.04 desktop

    Just followed your tutorial to install WordPress. It work without problem until coming to;
    –> [Submit]
    Can’t select database
    We were able to connect to the database server (which means your username and password is okay) but not able to select the wordpress database.

    Also having tried creating wp-config.php manually but without result.

    Please advise how to fix the problem. Thanks

    Please advise how to fix the problem.

  26. Sarkhan says:

    Hello. I’m stuck in the https://server-ip/wordpress part. I put my IP address but nothing happens, it’s just loading.

    1. Arun Joseph says:

      just open http://localhost in incognito

  27. Numbian says:

    Great tutorial thank you.

    There is one tiny mistake though:
    “apt install mariabd-server mariadb-client”
    should be
    “mariadb-server” 🙂

    1. Pankaj says:

      Thanks for noticing the typo error, I have fixed it.

      1. Numbian says:

        One more thing – on the first screen there are different db name and user than in – not really important, but can be a problem for beginers.

        CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘password’;
        GRANT ALL ON wordpressdb.* TO ‘wpuser’@’localhost’ IDENTIFIED BY ‘password’;

        1. Pankaj says:

          Thanks, I have changed the code snippet to match it to the image.

Comments are closed.

Generic selectors
Exact matches only
Search in title
Search in content