Install WordPress on Ubuntu 18.04LTS
WordPress is the most popular Blog / CMS platform used all over the internet. Whether you want a Blog / Shop / Intranet or a simple info website, WordPress can do it all. So go on, install WordPress!
But how do you install WordPress from scratch, on on a brand new server – in our case a brand new Ubuntu server? Well read on and learn.
WordPress requires a few things to get started:
- Up-to-date Linux – in our case Ubuntu.
- A Web Server – we’re going to be using Apache.
- A Database – we’ll be using MariaDB
- PHP – The scripting / programming language.
- A domain name or subdomain pointing to our server.
I’ve covered the installation of the above in previous posts. Your best starting point is the post Installing LAMP with MySQL or MariaDB on Ubuntu 1804LTS.
If you don’t have a domain name or subdomain handy, take a look at the post Using a Local Domain Name for Testing.
When you’ve completed those instructions – or if you already have a LAMP stack installed, continue here.
Lets ensure our ubuntu packages are all up-to-date
> sudo apt update && sudo apt upgrade
Now lets ensure all our PHP packages are installed.
> sudo apt install php-gd php-mbstring php-curl php-xmlrpc php-xml
Some of the packages may already be installed in previous steps and be up-to-date. That’s OK. Type[Y] and hit [ENTER].
2. Installing WordPress
Next we want to download and install WordPress.
Ensure you are in you’re home directory.
> cd ~
and download the latest version of WordPress.
> wget -c http://wordpress.org/latest.tar.gz
Next unpack the downloaded compressed archive.
> tar -xzvf latest.tar.gz
Lots of files will fly by on the screen as they’re unpacked.
There are two main options as to where you can store and run your WordPress instance, the default /var/www/html directory or a custom directory.
The default /var/www/html directory contains the following page:
We’re going to install in a custom directory and leave the default page as it is for now.
Create a directory to store the unpacked files.
> sudo mkdir /var/www/myownwebsite
myownwebsite with the name of your website of course. You knew that didn’t you? I didn’t have to point that out did I?
Now we now want to move the unpacked WordPress files to our newly created directory.
> sudo mv ./wordpress/* /var/www/myownwebsite
and set the correct ownership.
> sudo chown -R www-data:www-data /var/www/myownwebsite
> sudo chmod -R 755 /var/www/myownwebsite
3. Setting Up The WordPress Database
The last thing we need to do before we can launch the WordPress Installer through our browser is to create a Database to hold our WordPress site.
> sudo mysql -uroot -p
Enter password for your root user (store this somewhere safe).
> create database myownwebsite;
> grant all privileges on myownwebsite.* to 'your_username_here'@'localhost' identified by 'your_user_password_here';
> flush privileges;
OK – so that wasn’t too painful was it?
4. Configuring Apache
Now because we have chosen a custom location for our website rather than /var/www/html, we need to carry out a few additional steps to tell the webserver about our new site.
If you want to understand the following, then you can visit the post Basic Apache Configuration On Ubuntu first or just follow the simple steps below.
Go to the directory where the Apache configs are held.
> cd /etc/apache2/sites-available
Copy the default configuration file to the name of the website
> sudo cp 000-default.conf myownwebsite.conf
Using your favourite editor bring up the copied file so :
> sudo nano myownwebsite.conf
or my favourite editor
> sudo vi myownwebsite.conf
If you haven’t used vi before you may be better sticking with nano.
Change the DocumentRoot to point to our web directory – which we created using mkdir under /var/www/myownwebsite. So after your change it should look like this:
Create a new line and add : Servername www.myownwebsite.com.
Edit the configuration file so that the logfile names are unique to our website.
Now save the file and exit back to the command line.
Now that all the hard work is done, we need to enable our website:
> sudo a2ensite myownwebsite.conf
With our website enabled we need to tell Apache to reload the config changes.
> sudo service apache2 reload
5. Running WordPress for the First Time
Now that all the hard work is done, we simply need to launch WordPress from our browser and finish off the installation.
If this is a test server and your WordPress site is the only website on the server then we can disable the default website and use the ip address of the server.
This will basically replace the default page below, with your WordPress site.
Before you go down the IP Address route, read the “Alternatively” below.
To disable the default site.
> sudo a2dissite 000-default.conf
And to reread the new configuration.
> sudo service apache2 reload
Alternatively if you have your domain name configured (in our test case www.myownwebsite.com) then type this into your browser. Remember, if you don’t have a domain name or sub domain set up, take a look at the post Using a Local Domain Name for Testing.
So from your browser, go to your WordPress site via ip address or domain name.
Choose your language and click [Continue].
The page below will be displayed.
Click the [Let’s Go!] button.
Enter the required information – you should remember the top 3 from section 3. Setting Up the WordPress Database.
Leave the database host as localhost and the table prefix as wp_.
Click the [Submit] button.
You’ll then be presented with this friendly message.
Click the [Run The Installation] button.
Type a username – this is the admin user you will use to log in for the first time.
Then type a password or accept the one presented – keep it somewhere safe.
Now type your email address.
Don’t tick the ‘Search Engine Visibility’ checkbox unless want to be hard to find.
Click the [Install WordPress] button.
You’ll then be presented with the following:
Now click the [Log In] button.
Well done. You’re ready to go.