How to Install and Configure WordPress on Ubuntu


WordPress is a PHP-based open-source content management system that works with either a MySQL or MariaDB database. Among the features are a plugin architecture and a design scheme known as Themes in WordPress. WordPress has exploded in popularity and is an excellent alternative for having a website up and running quickly. Almost all administration can be done via the web frontend once it’s been set up.

Here you will learn how to install and setup WordPress on Ubuntu server with LAMP stack.


Install LAMP Stack on server: WordPress being a PHP-based CMS needs PHP on the server and to store data it requires a database and in this MySQL. To host the WordPress site, we need a web server i.e, Apache. You can follow this blog to install the LAMP stack on your Ubuntu server.

WordPress Setup

Step 1. Create a Database and a User in MySQL:

Create a separate database for WordPress that will be used in the steps of setting up site.

Login to MySQL database using the password that you have set while installing MySQL:

$ mysql -u root -p

Now, run the below query to create a database named “wordpressdb”:

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

NOTE: Semi-colon (;) is used in every MySQL’s queries.

We will create a separate MySQL user that is going to be used to access the WordPress database created above. We will provide all the access to the wordpressdb database.

mysql> GRANT ALL ON wordpressdb.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

Note: You can replace the password with your desired password.

We have created a MySQL database and user specifically for the WordPress. Now to apply changes we need to flush the privileges.


Then exit from MySQL.

mysql> EXIT;

Step 2. Additional PHP Extension Installation:

While installing LAMP stack we need to install necessary php extensions to do required tasks but now we need to install some additional extensions to work with WordPress and its plugins.

Download them by running these simple commands:

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

Here we will restart the Apache to add these extensions for use.

$ sudo systemctl restart apache2

Step 3. Allowing Rewrites and Overrides of .htaccess through Apache’s Configuration File:

First, we will prepare an Apache configuration file for WordPress in /etc/apache2/sites-available/ directory. You can use this basic example belowfor the config file /etc/apache2/sites-available/worpdress.conf .

Next, to allow .htaccess files, we can add these lines in config file.

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

And now the final file would look like this:

$ sudo nano /etc/apache2/sites-available/worpdress.conf
 <VirtualHost *:80>
     ServerAdmin webmaster@localhost
     ServerName localhost
     DocumentRoot /var/www/wordpress
         <Directory /var/www/wordpress/>
             AllowOverride All
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

Save and close the file.

Enabling Config file and rewrite module

 $ sudo a2ensite wordpress.conf
 $ sudo a2enmod rewrite 

Disable the default apache file.

$ sudo a2dissite 000-default.conf

Check for any configuration errors:

$ sudo apache2ctl configtest

The output should look like this

 Syntax OK 

$ sudo systemctl restart apache2

Step 4. Download WordPress:

After installation and configuration all the necessary software now it’s time to download the WordPress itself. It’s always a best practise to download the latest version of WordPress from their website.

Download the WordPress in a writable directory.

 $ cd /tmp
 $ curl -O 

Extract the downloaded the tar file.

$ tar xzvf latest.tar.gz

Now create a .htaccess file in extracted WordPress folder.

$ touch /tmp/wordpress/.htaccess

We will copy the sample file to the actual name that WordPress understand.

$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Let’s create an upgrade folder in the directory so that it will not give any permission error later on while creating this by its own.

$ mkdir /tmp/wordpress/wp-content/upgrade

Next, copy the whole WordPress content to our document directory.

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

Step 5. WordPress Configuration

First, we need to configure Ownership for WordPress files and folders.

Updating the ownership of WordPress content:

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

Next, we need to add some secret keys in WordPress configuration files. We can generate those secret keys form the key generator from WordPress.

To get the secret keys run the below command:

$ curl -s

We will get some unique secret keys which look like these:

NOTE: Do not copy these examples.

define('AUTH_KEY',         'P@x)Jxn^I1y$WJ|bbU~+kt@zuUz<Do not Copy these>(+GBZK,>k]T621|y3L@OD+1|5E|Vd@');
define('SECURE_AUTH_KEY',  ':-hB42KzS:o|=KT{+9OXWrI<Do not Copy these>ZiA5+R;a]j+W8e.EENXLO^qKKru@6O'); 
define('LOGGED_IN_KEY',    '9G~A)_a&N<Do not Copy these>tKvu4l6YA(,|SwNQYP'); 
define('NONCE_KEY',        '@SsESb@Y|H0JW#rQv(<Do not Copy these>opH|Pc+V*jf0H-z>$e6 < 6');
define('AUTH_SALT',        '-)_irj[7+gT|.^e-<Do not Copy these>mIZ3: ?pn,IB-!S%[v=vOFiu');
define('SECURE_AUTH_SALT', 'eR8{_->1Z>hGWWG? <Do not Copy these>S#7Sl9HgH[2$YCf(+T4Vly6');
define('LOGGED_IN_SALT',   '0~F%Ty<Do not Copy these>%n;02hOR8YhTp{6YN9 _>1gC[UE1rw|d,');
define('NONCE_SALT',       '-iaYGbTGz),/K[W<Do not Copy these>! dsfsfedX>5V@mj+meS9*I{');

Paste the output keys you got into our configuration file (/var/www/wordpress/wp-config.php) in the below section.

. . .
 define( 'AUTH_KEY',         'put your unique phrase here' );
 define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
 define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
 define( 'NONCE_KEY',        'put your unique phrase here' );
 define( 'AUTH_SALT',        'put your unique phrase here' );
 define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
 define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
 define( 'NONCE_SALT',       'put your unique phrase here' );
 . . .

Replace all the secret keys generated in the respective line in the config file.

Now, we need to add the database details in the wp-config.php file and set the FS_METHOD to direct so that we will not face any issue while installing any plugin in WordPress.

$ sudo nano /var/www/wordpress/wp-config.php
. . .
 define('DB_NAME', 'wordpressdb');
 /** MySQL database username */
 define('DB_USER', 'wordpressuser');
 /** MySQL database password */
 define('DB_PASSWORD', 'password');
 . . .
 define('FS_METHOD', 'direct');

Save and close the config file.

Step 6. WordPress Installation from Web Browser

To complete the installation we need to go to the web browser and use the public IP of the server.

https://server _IP

First, select the desired language from the options


Next, provide the required data and the setup will get completed.


Now, login with the credentials and you will get redirected to WordPress dashboard.



Now, you have WordPress installed and setup on the server. After this, you can install some useful plugins, apply any theme, and set the permalinks for the posts. WordPress is ready use for you to create your desired website.

5 thoughts on “How to Install and Configure WordPress on Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *