Fedora 27: 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.
#!/bin/sh

set -e

[ -z "${WORDPRESS_DOMAIN}" ] && \
  WORDPRESS_DOMAIN=fedora-27-wordpress.hiroom2.com
WORDPRESS_PASSWD=$(openssl rand -base64 32 | head -c 32)

php_install()
{
  sudo dnf install -y php-pecl-imagick php-pecl-ssh2 \
       php-opcache php-pecl-zendopcache php-pecl-apc
}

mysql_install()
{
  sudo dnf install -y mariadb-server
  sudo systemctl enable mariadb
  sudo systemctl start mariadb

  cat<<EOF | sudo mysql -u root
create database wordpress;
grant all privileges on wordpress.* to wordpress@localhost
  identified by '${WORDPRESS_PASSWD}';
flush privileges;
exit
EOF
}

wordpress_install()
{
  sudo dnf install -y wordpress

  cat <<EOF | sudo tee /etc/wordpress/wp-config.php
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', '${WORDPRESS_PASSWD}');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', '$(openssl rand -base64 64 | head -c 64)');
define('SECURE_AUTH_KEY', '$(openssl rand -base64 64 | head -c 64)');
define('LOGGED_IN_KEY', '$(openssl rand -base64 64 | head -c 64)');
define('NONCE_KEY', '$(openssl rand -base64 64 | head -c 64)');
define('AUTH_SALT', '$(openssl rand -base64 64 | head -c 64)');
define('SECURE_AUTH_SALT', '$(openssl rand -base64 64 | head -c 64)');
define('LOGGED_IN_SALT', '$(openssl rand -base64 64 | head -c 64)');
define('NONCE_SALT', '$(openssl rand -base64 64 | head -c 64)');
\$table_prefix  = 'wp_';
define('WP_CONTENT_DIR', '/var/lib/wordpress/wp-content');
define('DISALLOW_FILE_MODS', false);
define('AUTOMATIC_UPDATER_DISABLED', false);
define('WP_DEBUG', false);
\$_SERVER['HTTPS'] = 'on';
define('FS_METHOD', 'direct');
if ( !defined('ABSPATH') )
  define('ABSPATH', '/usr/share/wordpress');
require_once(ABSPATH . 'wp-settings.php');
?>
EOF

  sudo mkdir -p /var/lib/wordpress/wp-content
  for dir in languages plugins themes uploads; do
    sudo mkdir /var/lib/wordpress/wp-content/${dir}
  done
  sudo chown -R apache:apache /var/lib/wordpress/wp-content

  for top in languages plugins themes; do
    cd /var/lib/wordpress/wp-content/${top}/
    for dir in /usr/share/wordpress/wp-content/${top}/*; do
      sudo ln -s "${dir}"
    done
  done
}

apache_install()
{
  sudo dnf install -y httpd mod_ssl

  cat <<EOF | sudo tee /etc/httpd/conf.d/wordpress.conf
<VirtualHost _default_:443>
  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/localhost.crt
  SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

  ServerName ${WORDPRESS_DOMAIN}
  DocumentRoot /usr/share/wordpress/
  DirectoryIndex index.php index.html
  ErrorLog /var/log/httpd/wp-error.log
  TransferLog /var/log/httpd/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 setsebool -P httpd_can_sendmail 1
  sudo firewall-cmd --add-service=https --permanent
  sudo firewall-cmd --reload
  sudo systemctl enable httpd
  sudo systemctl restart httpd
}

wordpress_main()
{
  php_install
  mysql_install
  wordpress_install
  apache_install
}

wordpress_main

2 Access to WordPress

Access to your FQDN via https. Accept this page's certification to browser.

https://<WORDPRESS_DOMAIN>

0001_WordPress.png