1. Home
  2. Linux

How To Install WordPress On Ubuntu server

WordPress is the worlds most famous blogging and CMS platforms for the web. It is easy to develop for, customize, and scale for production. It also runs on countless server operating systems (Linux, Windows, and even BSD), has dozens of users and powers a good chunk of the entire internet.  Installing WordPress manually on a server is a very involved process, and isn’t for everyone. If you’ve stumbled upon this guide, and you’re not very good with stuff like this, consider checking out Presslabs. It’s a great service that allows users to easily scale the blog software, secure it make it run efficiently. If you’d rather do everything yourself, this guide will show you how to install WordPress on Ubuntu server.

Note: though this guide will mainly focus on Ubuntu server and Linux, WordPress can run on other server operating systems. To use it, you’ll need PHP, MySQL and a web server.

Installing LAMP

During the setup process for Ubuntu server, users have the option to select many packages to set up right away. One of the options to choose from is a LAMP stack (Linux Apache MySQL and PHP). If you’re installing Ubuntu server for the first time, for this guide, select this option during the package selection process during setup.

Already have Ubuntu server installed? Not to worry, a LAMP setup can be installed after the fact. To do this, run the following command in the terminal:

sudo apt install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc libapache2-mod-php7.0 libapache2-mod-php lamp-server^

Then, restart the web server with:

sudo systemctl restart apache2

When all the LAMP-related packages have been installed on the system, you’ll be prompted to set a root MySQL password. Do so, and make sure that it’s secure (and memorable). Without setting a root password, there will be no way to log into MySQL to create a new database for WordPress to use.

Lastly, create a user to use with WordPress (if you don’t already have one).

adduser ubuntu-wordpress

passwd ubuntu-wordpress

usermod -aG sudo ubuntu-wordpress

Configure Apache2

Using WordPress on Apache 2 requires a little bit of modification to work correctly. Using the nano text editor, open the apache2 web server configuration file.

sudo nano /etc/apache2/apache2.conf

Once inside nano, use the arrow keys to move all the way to the bottom of the file. Once at the bottom, paste this code inside of it:

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

Save the updated configuration file with Ctrl + O, and exit it with Ctrl + X.

Lastly, enable the required Apache 2 modules.

sudo a2enmod rewrite

sudo a2enmod php7.0

Be sure to restart the web server when done, to apply the changes.

sudo systemctl restart apache2

Installing WordPress

Start off the installation process by downloading the latest version of WordPress.

Note: do not do this installation on Ubuntu as the root user.

wget tar.gz -P /tmp/ https://wordpress.org/latest.tar.gz

Extract the contents of the tar.gz file to the default web directory.

tar xzvf /tmp/latest.tar.gz -C /var/www/html/ --strip-components=1

Next, create a new .htaccess file, and update its permissions.

touch /var/www/html/.htaccess

chmod 660 /var/www/html/.htaccess

Using, CP copy the sample configuration over as the default configuration file.

cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

With chown, give your user ownership of the WordPress files:

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

Adjusting Permissions

Ubuntu-wordpress now has better access to /var/www/html. The next step in the installation process is to tweak the permissions, so that WordPress operates correctly:

sudo find /var/www/html -type d -exec chmod g+s {} \;

sudo chmod g+w /var/www/html/

The themes and plugins directory also needs permission changes, so that everything goes smoothly.

sudo chmod -R g+w /var/www/html/wp-content/themes

sudo chmod -R g+w /var/www/html/wp-content/plugins

Setting Up Secret Keys

For security purposes, each new WordPress install must be verified with a few secret keys. These keys can easily be grabbed with the curl command.

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

Using curl, the WordPress salt keys are located in /wp-keys. Use cat to view them.

cat /wp-keys

Open a second terminal, and edit your WordPress config file.

nano /var/www/html/wp-config.php

Scroll all the way to the middle of the file and fill out each of the keys into the correct spots. Use /wp-keys as a reference.

Note: copy between the ‘ ‘

Creating An SQL Database

Log into the MySQL interface using the root password you set up during the LAMP installation process earlier. Once in, use the prompt to create a new database for WordPress.

mysql -u root -p

Note: change ‘securepassword‘ with a secure password. DO NOT REMOVE THE ‘ .

CREATE DATABASE wordpressdb;

CREATE USER ubuntuwordpress@localhost IDENTIFIED BY 'securepassword';

GRANT ALL PRIVILEGES ON wordpressdb.* TO ubuntuwordpress@localhost;



Restart the Apache 2 web server, and MySQL to reflect the changes.

sudo service apache2 restart

sudo service mysql restart

Final Tweaks

The last thing to do in terms of terminal-based setup is to fill out the database information inside of the config.php file. Open it in nano, and fill out the required information. It should look like this:

nano /var/www/html/wp-config.php

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpressdb’);

/** MySQL database username */
define(‘DB_USER’, ‘ubuntuwordpress’);

/** MySQL database password */
define(‘DB_PASSWORD’, securepassword);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Setting Up Your WordPress Blog

When the configuration is complete, load your server’s domain, and go through the WordPress setup process. The installer is very detailed, and will walk you through every step.

Leave a comment