コンテンツマネージメントシステムのWordPressをインストールする手順を記載します。
Table of Contents
1 WordPressをインストールする
- WORDPRESS_DOMAINをお使いの環境のFQDNに変更してください。
- この記事ではhttpsの為にデフォルトのSSL/TLS証明書を使っています。別にSSL/TLS証明書を用意している場合は変更してください。
#!/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 WordPressへアクセスする
WORDPRESS_DOMAINで設定したFQDNにhttps経由でアクセスします。ブラウザでこのページの証明書を許可してください。
https://<WORDPRESS_DOMAIN>