How to Install WordPress 4.7 on Ubuntu 16.04 with Apache, MariaDB, PHP7
WordPress 4.7, codenamed “Vaughan”, was released on December 6, 2016. Existing WordPress users can push the update button to upgrade to the latest version. This tutorial is going to show you how to install a new WordPress 4.7 instance on Ubuntu 16.04 with Apache, MariaDB and PHP7.
Here is what’s new in WordPress 4.7:
- A brand new Twenty Seventeen theme for businesses
- Starter content support for themes
- Video header support
- PDF previews
- Custom CSS in customizer
- User-specific language settings
- Improvements in WordPress editor
- Other developer features
This tutorial assumes that you have already set up a LAMP stack on Ubuntu 16.04. If not so, please click the link below to check out the LAMP tutorial.
After finishing LAMP installation, come back here and read on.
Step 1: Download WordPress 4.7
Log into your Ubuntu 16.04 VPS or server via SSH, then update all software.
sudo apt update && sudo apt upgrade
Next, download the latest WordPress tar archive to your Ubuntu 16.04 machine which can be done with the following command:
wget https://wordpress.org/latest.tar.gz
Once downloaded, extract the archive using the command below.
tar xvf latest.tar.gz
A new directory named wordpress
will be created in the current working directory. Now We move this directory and all its content to Apache web root. Replace your-site.com
with you real domain name.
sudo mv wordpress/ /var/www/your-site.com
Step 2: Create a Database and User for WordPress Site
Log into MariaDB shell as root. Please note that this is the MariaDB database root user, not the root user of Ubuntu 16.04 system.
mysql -u root -p
If you can’t login but you are sure that you entered the correct password, then you can switch to root user first,
sudo su
Then run the command below to log into MariaDB shell.
mysql
Once you are logged in, create a database for WordPress using the following command. I named it wordpress
, but you can use whatever name you like such as you site name.
create database wordpress;
Then enter the command below to create a database user for WordPress. This command also grant all privileges on WordPress database to the user.
grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';
Flush the privileges table for the changes to take effect and then exit out of MariaDB shell.
flush privileges; exit;
Step 3: Configure WordPress
Go to your WordPress site installation directory.
cd /var/www/your-site.com
Copy the sample configuration file.
sudo cp wp-config-sample.php wp-config.php
Now edit the new config file.
sudo nano wp-config.php
Find the following lines and replace the red texts with the database name, username and password you created in the previous step.
/** The name of the database for WordPress */ define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here');
Save and close the file. We also need to set the Apache user (www-data
) as the owner of the WordPress site directory using the following command.
sudo chown www-data:www-data /var/www/your-site.com/ -R
Step 4: Create an Apache Virtual Host file for WordPress
First, cd into /etc/apache2/sites-available/
directory.
cd /etc/apache2/sites-available/
Then copy the default virtual host file.
sudo cp 000-default.conf your-site.com.conf
Next, edit the virtual host file for WodPress.
sudo nano your-site.com.conf
Change the values for ServerName
and DocumentRoot
like below.
ServerName www.your-site.com your-site.com ServerAdmin webmaster@localhost DocumentRoot /var/www/your-site.com
Save and close the file. Then test configurations.
sudo apache2ctl configtest
Enable this virtual host.
sudo a2ensite your-site.com.conf
And reload Apache for the changes to take effect.
sudo systemctl reload apache2
Set a correct A record for your domain name, then enter your domain name in browser address bar. You shall see the WordPress installation wizard. Select a language.
If the installation wizard isn’t displayed, then you probably should install some PHP7 extensions.
sudo apt install php7.0-mbstring php7.0-xml php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl
Then reload Apache and the wizard should be displayed.
sudo systemctl reload apache2
Create an admin account and click install WordPress button.
And now your new WordPress site is ready.
Installing a TLS Certificate
To enable HTTPS connection on your WordPress site, you can use Let’s Encrypt. First, install Let’s Encrypt client (cerbot) on Ubuntu 16.04.
sudo apt install letsencrypt python-letsencrypt-apache
Then run the following command to install a free TLS certificate.
sudo letsencrypt --apache --agree-tos --email your-email-address -d your-site.com www.your-site.com
You will be asked to choose easy or secure. It’s recommended to choose secure so that all http requests will be redirected to https.
Once you hit the OK button, a free TLS/SSL certificate is obtained and installed on your Apache server.
Now visit your WordPress site again. You will see that it’s automatically redirected to https.
That’s it!
I hope this tutorial helped you install WordPress on Ubuntu 16.04 with Apache, MariaDB and PHP7. As always, if you found this post useful, then subscribe to our free newsletter. You can also follow us on Google+, Twitter or like our Facebook page.
Hey great guide, thank’s for the tutorial. However, I’d like to point out one gotcha. If you follow your first guide to install Apache2 and you modify the ProxyPass for PHP-FPM that modifies the 000-default.conf file, and when you copy that to make your site using this tutorial you have to go modify the fcgi://localhost/var/www/html part (from html to your-site.com)
Hi there
Just wondering could you do a tutorial on setting up a multi site wordpress on the same server ?
Thanks
Hi
The tutorial was just published -> https://www.linuxbabe.com/ubuntu/set-up-wordpress-multisite-apache