CORE STUDY: Installing wordpress on Ubuntu

Reading Time: 2 minutes

Last Revised: 2/24/2022
This is being published on an emergency basis so that I can use it.
Please see the first URL in the recommended URLs below. This basically covers the majority of what you will want.

STEP 1: Get perquisites in place

sudo apt update
sudo apt install apache2 \
                 ghostscript \
                 libapache2-mod-php \
                 mysql-server \
                 php \
                 php-bcmath \
                 php-curl \
                 php-imagick \
                 php-intl \
                 php-json \
                 php-mbstring \
                 php-mysql \
                 php-xml \
                 php-zip

STEP 2: Install wordpress

sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www

STEP 3: Configure Apache for WordPress

Default apache configuration files are stored at: /etc/apache2/sites-available
You can create a “wordpress.conf” file that looks like

<VirtualHost *:80>
    DocumentRoot /srv/www/wordpress
    <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /srv/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

To enable the site you would enter

sudo a2ensite wordpress
sudo a2dissite 000-default

Finally you are ready to reload apache and it will load with the your newly config site.

sudo service apache2 reload

STEP 4: Configure database

sudo mysql -u root
CREATE DATABASE wordpress;
CREATE USER wordpress@localhost IDENTIFIED BY 'Secure1!';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    ON wordpress.*
    TO wordpress@localhost;

STEP 5 – Establish default wordpress configuration

Now it’s time to configure wordpress. We do this by establishing a configuration file and then modifying the default config with a few well chosen values.

This first step copies a sample config file into place that will server as the initial default configuration.

sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/Secure1!/' /srv/www/wordpress/wp-config.php

Next, there is a series of default keys that need to be established. The wp-config.php file (at line 51) has a section that looks like the following:

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

If you visit:

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

The page will literally create for you a a set of keys and configuration that you can copy into the file. Please make sure to delete the default values first. Then you can literally paste in the values from the page.

STEP 7: Configure wordpress

SECTION: Additional – integrate SSL cert into wordpress

I AM IGNOREING A LOT OF THE TECHNICAL DETAILS. Please see the openssl post or use your favorite way for creating and using a cert.

make cert
put server-cert in /etc/ssl/certs
put request-key in /etc/ssl/certs

The following bit can be appended to the wordpress.conf file in /etc/apache2/sites-available

<VirtualHost *:443>
   DocumentRoot /srv/www/wordpress
   ServerName wp.my.lab
   ServerAlias wp.my.lab
   SSLEngine on
   SSLProtocol all -SSLv2 -SSLv3 -TLSV1
   SSLCertificateFile /etc/ssl/certs/wp.crt
   SSLCertificateKeyFile /etc/ssl/certs/wp-privkey.pem
   #LCertificateChainFile /var/www/letsencrypt/live/www.test.com/chain.pem
   <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
   </Directory>
</VirtualHost>

Enable the SSL module

sudo a2enmod ssl

Then reload service.

 sudo service apache2 reload

SECTION – Diagnostics

If necessary use the following to test

apachectl configtest

URLS:

https://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview
https://digitaloceancode.com/how-to-install-wordpress-on-ubuntu-18-04-and-ssl-certificate/
https://www.yanivp.net/install-free-https-ssl-on-wordpress-with-ubuntu/
https://csrgenerator.com/

This entry was posted in Ubuntu. Bookmark the permalink.