Ubuntu 16.04: Install WordPress

This article will describe installing WordPress which is a content management system.

1 Install WordPress

  • Change WORDPRESS_DOMAIN to your machine's FQDN.
  • This article uses default SSL/TLS certicication file for https. Please change your SSL/TLS certification file.
  • If you use http instead of https, change 443 to 80 and delete SSLXXX directive in /etc/apache2/sites-available/wordpress.conf.
#!/bin/sh

[ -z "${WORDPRESS_DOMAIN}" ] && \
  WORDPRESS_DOMAIN=ubuntu-1604-wordpress.hiroom2.com
[ -z "${WORDPRESS_SITENAME}" ] && \
  WORDPRESS_SITENAME=wordpress
MYSQL_VERSION=5.7
[ -z "${MYSQL_PASSWD}" ] && \
  MYSQL_PASSWD=mysql

wordpress_install_mysql()
{
  cat <<EOF | sudo debconf-set-selections
mysql-server-${MYSQL_VERSION} mysql-server/root_password password ${MYSQL_PASSWD}
mysql-server-${MYSQL_VERSION} mysql-server/root_password_again password ${MYSQL_PASSWD}
EOF
  sudo apt install -y mysql-server
}

wordpress_install_wordpress()
{
  sudo apt install -y wordpress

  # Change filesystem access method from FTP to direct.
  # This will change plugin installation via FTP to plugin installation
  # with direct filesystem access.
  sudo sed -e "s/^<?php/<?php\ndefine('FS_METHOD', 'direct');/g" \
       -i /usr/share/wordpress/wp-config.php

  TMP=$(mktemp -t ubuntu-wordpress.sh.XXXXXX)
  trap 'rm $TMP* 2>/dev/null' 0
  zcat /usr/share/doc/wordpress/examples/setup-mysql.gz > "${TMP}"

  # You can select remote mysql server with -t option.
  # You can set mysql database username with -u option.
  sudo bash "${TMP}" -n "${WORDPRESS_SITENAME}" "${WORDPRESS_DOMAIN}"
}

wordpress_install_apache()
{
  sudo apt install -y apache2
  cat <<EOF | sudo tee /etc/apache2/sites-available/wordpress.conf
<VirtualHost _default_:443>
  SSLEngine on
  SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem
  SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

  ServerName ${WORDPRESS_DOMAIN}
  DocumentRoot /usr/share/wordpress/
  DirectoryIndex index.php index.html
  ErrorLog /var/log/apache2/wp-error.log
  TransferLog /var/log/apache2/wp-access.log
  Alias /wp-content /var/lib/wordpress/wp-content

  <Directory /usr/share/wordpress>
    Options FollowSymLinks
    Require all granted
  </Directory>

  <Directory /var/lib/wordpress/wp-content>
    Options FollowSymLinks
    Require all granted
  </Directory>
</VirtualHost>
EOF
  sudo a2enmod ssl
  sudo a2ensite wordpress
  sudo systemctl enable apache2
  sudo systemctl restart apache2
}

wordpress_main()
{
  wordpress_install_mysql
  wordpress_install_wordpress
  wordpress_install_apache
}

wordpress_main

2 Access to WordPress

Access to your FQDN via https.

https://<WORDPRESS_DOMAIN>

Because the chrome does not have this page's certification, the crome warns the following and cannot to access to this page. You need to click "ADVANCED" and "Proceed to <server> (unsafe)". The other browser will needs the similar way.

0001_YourConnectionIsNotPrivate.png

Locale setting is displayed.

0002_LocaleSetting.png

Account setting is displayed. After creating account, you can login to WordPress, create blog page and manage WordPress.

0003_CreateAccount.png