How to Install WordPress on Ubuntu?

Ubuntu is a popular Linux distribution based on Debian, it is mostly a free and open-source operating system. Ubuntu is a popular operating system in the cloud computing space, it supports Open Stack too.

One may ask, in the world of one-click WordPress installation why we are writing documentation about manual WordPress installation on a bare operating system? At Vikreed, we develop a variety of WordPress based solutions. We build run-of-mill websites and complicated solutions too.

For a simple portfolio website Elementor is enough, but to build a corporate website we choose a custom development approach. Then there are projects which need in-depth control of web architecture as well as the underlying operating system. So we build our capacity to build custom WordPress based solutions on popular Linux distros like Ubuntu and Debian.

Here is this article we see how to install WordPress on Ubuntu manually. Note that you need system administrator level experience and access credentials.

Install dependencies

sudo apt update
sudo apt install apache2 \
                 ghostscript \
                 libapache2-mod-php \
                 mysql-server \
                 php \
                 php-bcmath \
                 php-curl \
                 php-imagick \
                 php-intl \
                 php-json \
                 php-mbstring \
                 php-mysql \
                 php-xml \

This installs Apache, PHP, and MySQL on the server.

Install WordPress

  • Create a directory and assign appropriate permissions and group.
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
  • Download WordPress from . They maintain the latest WordPress version at this location, it is the best source to download WordPress.
curl | sudo -u www-data tar zx -C /srv/www

Configure Apache for WordPress

  • Create /etc/apache2/sites-available/wordpress.conf and add following lines to set Apache for WordPress
DocumentRoot /srv/www/wordpress
<Directory /srv/www/wordpress>
    Options FollowSymLinks
    AllowOverride Limit Options FileInfo
    DirectoryIndex index.php
    Require all granted
<Directory /srv/www/wordpress/wp-content>
    Options FollowSymLinks
    Require all granted
  • enable Apache site
sudo a2ensite wordpress
  • enable URL rewriting
sudo a2enmod rewrite
  • reload apache2
sudo service apache2 reload
  • disable the default “It works” page
sudo a2dissite 000-default

Configure Database

  • Login to MySQL
$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  • Create a database
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0,00 sec)

Note that you can choose any database name, here we have created a database named “wordpress“.

  • Create administrator user and assign privileges.
mysql> CREATE USER wordpress@localhost IDENTIFIED BY 'sample_password';
Query OK, 1 row affected (0,00 sec)

    -> ON wordpress.*
    -> TO wordpress@localhost;
Query OK, 1 row affected (0,00 sec)

Query OK, 1 row affected (0,00 sec)

mysql> quit
  • Enable MySQL
sudo service mysql start

Connect WordPress with database

  • Copy wp-config-sampe.php to create wp-config.php
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
  • set the database credentials in the configuration file
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/<your-password>/' /srv/www/wordpress/wp-config.php

or simply open /srv/www/wordpress/wp-config.php and add values for the following parameters and save the file.

/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'sample_password');
  • Update Keys

open /srv/www/wordpress/wp-config.php again and delete the following lines

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' );

Go to and get a unique set of keys and save it in wp-config.php file.

define('AUTH_KEY',         '+j4J63F.C>l+6bQRVmZvQ3pnm2d{jlDV2ig|pDB1(2G_(4JL+`mRG`RAY4Xx!T7]');
define('SECURE_AUTH_KEY',  'JyacbTtABaW8}{+Y.mpt=*dwA+;ZL/QnaZkWunLr.N2;Nh7J@Wr5I =lb=&52pRw');
define('LOGGED_IN_KEY',    'bxF=9BrmQbrr+0,-Ir1k1lNy2@CLZ`I1&$YHEg{Y22P9Mr|or|WMg RSmx?k{GV2');
define('NONCE_KEY',        '2:+q}$2NzL+m/m4W><L|!r3:Vj^=;c*H/ltWjqo,={hpYnPi~7S7R7M;0/.PiBP9');
define('AUTH_SALT',        '$+w=R4[Q/@I<{J%N`I#$*nc{zb+&|+G@_|A#{|jg9tJj9Wna@?*=D?s]K+%=p+9L');
define('SECURE_AUTH_SALT', '`L-(B|B&Ns{|]$@QQ55]z?P|:NoGNEw8Z3W!2BkH|<8[cD^f&[,.(j^PF#-JFp4!');
define('LOGGED_IN_SALT',   '}>i-%}$E~Wo7HU]}ZNycQ+-K0Bn0Wfc(yTF<<X~5+EV>,Pq1-ItbGA1t+a-Q/ 7K');
define('NONCE_SALT',       'qy#@Z!O>FfmRN9C+ga%:&YA=+`jjODNH%M5+D<Rr-&+HvrEK&ux#Q4&p8cGw4O:r');

On every visit, it creates a different set of keys. This is done to prevent websites from “known secrets” attacks.

WordPress Configuration

Open http://localhost/ in your browser. Add site name, username, password, and admin email ID and then follow a regular WordPress setup process.

About Author

Sorry, Comments are closed!