Objective

Install WordPress on Ubuntu 18.04 Bionic Beaver

Distributions

Ubuntu 18.04

Requirements

A working install of Ubuntu 18.04 with root privileges

Difficulty

Easy

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Introduction

Whether or not you like it, WordPress is a huge deal. It powers a gigantic portion of the Internet, and it remains one of the easiest ways to get a website online. Installing WordPress is dead simple, once you have a LAMP or LEMP server running on Ubuntu. This guide piggy-backs on the existing PHP server guides to get you running WordPress in as little time as possible.

Install the PHP Packages

WordPress requires some additional PHP packages to get running. It's a fairly large web app, and it makes use of quite a few of PHP's capabilities. Before you an get started with WordPress, you'll need to install these packages.
$ sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc

Set Up LAMP/LEMP

WordPress is build with PHP. You can host it like you would any other web app written in PHP. So, you're going to need to set Ubuntu up as either a LAMP or LEMP server. If you haven't done so already, use our traditional LAMP guide, our MariaDB LAMP guide, or our LEMP guide to set up Ubuntu to serve PHP before you continue.

SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Create A Database

Unless you created a database specifically for WordPress during your LAMP/LEMP setup, you're going to need to create a new one for WordPress to use. Sign in to MySQL as your root user.
$ mysql -u root -p
Once you're in the MySQL console, create a new database.
mysql> CREATE DATABASE wordpress;
Create a new user for it too.
mysql> CREATE USER `wp_admin`@`localhost` IDENTIFIED BY 'yourpass';
Grant your new user permissions on the DB.
mysql> GRANT ALL ON wordpress.* TO `wp_admin`@`localhost`;
Flush your privileges and exit.
mysql> FLUSH PRIVILEGES;

Get WordPress

The WordPress packages that are available in package repositories aren't alway up-to-date, and that's a big deal when you're talking about WordPress security. The best way to install WordPress is with the tarball available directly from the developers. Grab the latest release with wget.
$ wget https://wordpress.org/latest.tar.gz
Extract the archive into the location where you want your web root.

$ cd /var/www
$ sudo tar xpf ~/Downloads/latest.tar.gz
Then, give the web server ownership of the directory.
$ sudo chown -R www-data:www-data /var/www/wordpress


Configure The Web Server

Your web server configuration is going to depend on whether you're using Apache or Nginx. Either one will assume that you're going to host on a server with more than one site using virtual hosts.

Apache

You're going to need to create a new virtual host for your site. Start by copying either the default configuration or a previous configuration to modify to host WordPress.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wordpress.conf
Open your configuration and modify the DocumentRoot to point at where you unpacked the wordpress directory.
DocumentRoot /var/www/wordpress
Set the ServerName to your site's domain(or localhost if you're just testing).
ServerName your-site.com
Create an alias for the www version too.
ServerAlias www.your-site.com
When you're done, save your file and exit. Enable your site in Apache.
$ sudo a2ensite wordpress.conf
Reload Apache.
$ sudo systemctl reload apache2

Nginx

Create a new site configuration for WordPress in the /etc/nginx/sites-available directory. Open that file. Everything here is completely standard for a PHP configuration. Create a new server block for your WordPress site. It should look similar to this one.
NOTE: Update the below Nginx configuration file with your installed PHP version! To check your PHP version execute php --version command.
server {
	listen 80;
	listen [::]:80;
	server_name your_site.com;

	index index.php;
	root /var/www/wordpress;

	access_log /var/log/nginx/your-site.com.access_log;
	error_log /var/log/nginx/your-site.com.error_log;

	location / {
		try_files $uri $uri/ =404;
	}

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
	}
}
If you're using SSL, include that and the 301 redirect as well. Don't forget to link your site configuration and restart Nginx.

$ sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
$ sudo systemctl restart nginx


WordPress Install

Ubuntu Bionic Select WordPress Language

Open your browser and navigate to the address where you're hosting WordPress. When you first get there, you'll see a screen where WordPress asks you to select your language. Select it, and move on to the next stage.

Ubuntu Bionic Begin WordPress Install

WordPress will then display a screen saying that you need to collect the information needed to connect to your database. Make sure you have it handy.

Ubuntu Bionic Connect To WordPress Database

The next screen asks you to input your database information. When you have it all correct, submit the form. If all goes well, you'll see a screen telling you that you can begin the actual installation.

Ubuntu Bionic Setup WordPress Site Information

On the next screen, you can set up your site's information and your admin user. Pick a strong password. WordPress sites are often targets for attackers online. After you submit the form, WordPress will begin installing your site and creating the configuration.

Ubuntu Bionic WordPress Installed Successfully

After the installation completes, you'll see a new message telling you to sign in to your site. After you sign in, you'll have access to the WordPress dashboard as your admin user. WordPress is now running on your Ubuntu server!

Ubuntu Bionic WordPress Dashboard

Closing Thoughts

This is WordPress. The possibilities are virtually limitless. Feel free to play around with WordPress itself and develop your site. You can also tune your server for better performance and security if you should choose too.
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.