Install WordPress Ubuntu

1. Create a MySQL Database and User for WordPress

To get started, log into the MySQL root account by issuing this command:

$ mysql -u root -p

Now, we are going to create a database for our WordPress website by entering the following command(s):

CREATE DATABASE wordpress;

GRANT ALL ON wordpress.* to ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘password’;

FLUSH PRIVILEGES;

EXIT;

2. Install PHP Exensions

We can download and install some of the most popular PHP extensions for use with WordPress by typing:

$ sudo apt-get update
$ sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc

Now, restart Apache to leverage these new extensions in the next section. Enter the following command:

$ sudo systemctl restart Apache2

3. Adjust Apache’s Config to allow .htaccess

Open the primary Apache configuration file to make our fist change:

$ sudo nano /etc/apache2/apache2.conf

To allow .htaccess files, we need to set the AllowOverride directive within a Directory block pointing to our document root. Towards the bottom of the file, add the following block:

When you are finished, save and close the file.

Next, we can enable mod_rewrite so that we can utilize the WordPress permalink feature:

$ sudo a2enmod rewrite

Before we implement the changes we’ve made, check to make sure we haven’t made any syntax errors:

$ sudo apache2ctl configtest

Restart Apache to implement the changes:

$ sudo systemctl restart apache2

4. Download WordPress

Change into a wiritable directory and then download the compressed release by typing:

$ cd /tmp
$ curl -O https://wordpress.org/latest.tar.gz

Extract the compressed file to create the WordPress directory structure:

$ tar xzvf latest.tar.gz

We will be moving these files into our document root momentarily. Before we do, we can add a dummy .htaccess file and set its permissions so that this will be available for WordPress to use later.

Create the file and set the permissions by typing:

$ touch /tmp/wordpress/.htaccess
$ chmod 660 /tmp/wordpress/.htaccess

We’ll also copy over the sample configuration file to the filename that WordPress actually reads:

$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

We can also create the upgrade directory, so that WordPress won’t run into permissions issues when trying to do this on its own following an update to its software:

$ mkdir /tmp/wordpress/wp-content/upgrade

Now, we can copy the entire contents of the directory into our document root. We are using the -a flag to make sure our permissions are maintained. We are using a dot at the end of our source directory to indicate that everything within the directory should be copied, including hidden files (like the .htaccess file we created):

$ sudo cp -a /tmp/wordpress/. /var/www/html

5. Configure the WordPress Directory

We’ll start by assigning ownership over all of the files in our document root to our username. We will use sammy as our username in this guide, but you should change this to match whatever your sudo user is called. We will assign group ownership to the www-data group:

$ sudo chown -R sammy:www-data /var/www/html

We can set the setgid bit on every directory in our WordPress installation by typing:

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

Now, we are going to give the wp-content directory rights by enter the following command:

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

As part of this process, we will give the web server write access to all of the content in these two directories:

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

Now, we have to grab secure values from the WordPress secret key generator, type:

$ curl -s https://api.wordpress.org/secret-key/1.1/salt/

You will get back unique values that look something like this:

Warning! It is important that you request unique values each time. Do NOT copy the values shown below!

These are configuration lines that we can paste directly in our configuration file to set secure keys. Copy the output you received now.

Now, open the WordPress configuration file:

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

Find the section that contains the dummy values for those settings. It will look something like this:

Delete those lines and paste in the values you copied from the command line:

The other change we need to make is to set the method that WordPress should use to write to the filesystem. Since we’ve given the web server permission to write where it needs to, we can explicitly set the filesystem method to “direct”. Failure to set this with our current settings would result in WordPress prompting for FTP credentials when we perform some actions.

This setting can be added below the database connection settings, or anywhere else in the file:

Save and close the file when you are finished.

6. – Complete the installation

Now that the server configuration is complete, we can complete the installation through the web interface.

In your web browser, navigate to your server’s domain name or public IP address:

http://server_domain_or_IP

Select the language you would like to use:

Next, you will come to the main setup page.

Follow all these steps and fill in your details to complete the installation.

WordPress is succesfully installed!

If you got any suggestions, questions or feedback, please feel free to contact us: info@yourlinuxguide.com