Debian 8: Install WordPress for CMS

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

set -e

debian_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
}

debian_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 debian-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}"
}

debian_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
}

debian_main()
{
  [ -z "${WORDPRESS_DOMAIN}" ] && \
    WORDPRESS_DOMAIN=debian-8-wordpress.hiroom2.com
  [ -z "${WORDPRESS_SITENAME}" ] && \
    WORDPRESS_SITENAME=wordpress
  MYSQL_VERSION=5.5
  [ -z "${MYSQL_PASSWD}" ] && \
    MYSQL_PASSWD=mysql
  debian_install_mysql
  debian_install_wordpress
  debian_install_apache
}

debian_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_SetLocale.png

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

0003_WordPress.png