Install and configure WordPress

Prerequisite: Creating a LAMP server with Ubuntu 16.04

Create and configure MySQL database for WordPress

mysql -u root -p

Make sure to use the root password configured when installing MySQL previously. We will now see a mysql> prompt. Enter:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Create the user ‘wordpress’ and create a strong password.

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

Flush privileges for MySQL to be up to date.

FLUSH PRIVILEGES;

Exit mysql>

EXIT;

Install optional PHP Packages

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

Restart Apache

sudo systemctl restart apache2

Enable .htaccess Overrides

sudo nano /etc/apache2/apache2.conf

Append the following code to the end of the file:

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

CTRL+O & CTRL+X to save and quit nano

Enable mod_rewrite to allow WordPress permalinks to work properly.

sudo a2enmod rewrite

Restart Apache

sudo systemctl restart apache2

Download and Extract WordPress

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
touch /tmp/wordpress/.htaccess
chmod 660 /tmp/wordpress/.htaccess
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
mkdir /tmp/wordpress/wp-content/upgrade
sudo cp -a /tmp/wordpress/. /var/www/html

Set ownership permissions (change USERNAME to our Ubuntu login user account name)

sudo chown -R USERNAME:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod g+s {} \;
sudo chmod g+w /var/www/nickshertzer/wp-content
sudo chmod -R g+w /var/www/nickshertzer/wp-content/themes
sudo chmod -R g+w /var/www/nickshertzer/wp-content/plugins

Salt secret keys for our WordPress installation to use internally:

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

We can copy the output and paste into a blank txt file using TextEditor. Open wp-config.php and paste the unique phrases:

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

Scroll down and use “SHIFT+INSERT” to past the unique phrases in the appropriate places.

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'paste your unique phrase here');
define('LOGGED_IN_KEY',    'paste your unique phrase here');
define('NONCE_KEY',        'paste your unique phrase here');
define('AUTH_SALT',        'paste your unique phrase here');
define('SECURE_AUTH_SALT', 'paste your unique phrase here');
define('LOGGED_IN_SALT',   'paste your unique phrase here');
define('NONCE_SALT',       'paste your unique phrase here');

Also find and replace the following user defined variables in wp-config.php:

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

. . .

define('FS_METHOD', 'direct');

CTRL+O & CTRL+X to save and exit nano.

Complete the WordPress installation through the web interface. Using a browser on another machine, navigate to our server’s domain name.

https://server_domain.com

Follow the WordPress installation guide.

Updating WordPress

sudo chown -R www-data /var/www/html

Now we can browse to https:// serverdomain dot com/wp-admin/update-core.php and install updates through the WP web interface. Once updates are applied, re-lock security permissions:

sudo chown -R USERNAME /var/www/html