【WordPress】WordPress移行

  • WordPress移行
    Raspberry PiのWordPressをNUCのWordPressに移行します。
    移行元の管理画面から「ツール」-「エクスポート」を選択し、xmlファイルでエクスポートしておきます。

    移行先の管理画面から「ツール」-「インポート」を選択すると
    インポート元のシステムを選択する画面になるので、「WordPress」を選択します。
    「WordPress Importer」というプラグインをインストールし、
    先ほどエクスポートしておいたxmlファイルを指定して移行完了です。

    ・・・となるはずが、画面が変わらず反応がありません。

  • 試したこと1
    ダッシュボードの設定をある程度同じにしておかないとエラーになるのかと思い、
    設定変更後に挑戦しましたが、変わらず。

  • 試したこと2
    xmlファイルを読めていないのかと思い、phpのプラグインをインストール。

    yum -y install php-xml
    

    だめでした。

  • 試したこと3
    本家のBBSに下記のような記事がありました。
    https://wordpress.org/support/topic/wordpress-importer-04-not-importing

    Jon Caveさんの解決方法を試してみました。

    cd /var/www/html/任意ディレクトリ名/wp-content/plugins/wordpress-importer
    cp -pi parsers.php parsers.php.org
    vi parsers.php
    
    下記内容に変更
    if ( extension_loaded( 'simplexml' ) ) {
    ↓
    if ( false && extension_loaded( 'simplexml' ) ) {
    

    修正したif文の上でparseメソッドを呼び出しており、
    戻り値がfalseになってしまうので、falseが返ってきても
    強制的に処理を進めてしまうよう変更しています。

    かなり強引ですが、この解決方法で無事インポートできました。
    プラグインの設定を行い、ドキュメントルートからのパスは一緒なので、画像は再配置のみで
    NUCへの移行が完了しました。
    管理画面はNUCの方が性能が良いからなのか体感で早く感じます。

【WordPress】WordPress導入

  • WordPress導入

    mysql -u root -pデータベースパスワード
    
    create database データベース名;
    grant all privileges on データベース名.* to データベースユーザ名@localhost identified by "データベースパスワード";
    exit
    
    cd /var/www/html
    wget http://ja.wordpress.org/latest-ja.zip
    unzip latest-ja.zip
    mv wordpress/ 任意ディレクトリ名
    chown -R apache.apache 任意ディレクトリ名/
    cd 任意ディレクトリ名
    cp -pi wp-config-sample.php wp-config.php
    vi wp-config.php
    
    # 下記内容を変更
    define('DB_NAME', 'database_name_here');
    ↓
    define('DB_NAME', 'データベース名');
    
    define('DB_USER', 'username_here');
    ↓
    define('DB_USER', 'データベースユーザ名');
    
    define('DB_PASSWORD', 'password_here');
    ↓
    define('DB_PASSWORD', 'データベースパス');
    
    # 下記内容を「編集が必要なのはここまで(略)」より上に追加
    /* リビジョン無効 */
    define('WP_POST_REVISIONS', false);
    
    /* ログイン・管理画面SSL強制 */
    define('FORCE_SSL_LOGIN', true);
    define('FORCE_SSL_ADMIN', true);
    
    cd ../
    rm -f latest-ja.zip
    /etc/rc.d/init.d/iptables stop
    

    http://z-area.net/任意ディレクトリ名/wp-admin/install.php

    手順にそってインストールを行います。
    インストール後にログイン画面に飛ぶと自動でSSLに遷移もします。

【PHP】php5導入

php5インストール

yum -y install php php-mbstring php-mysql

拡張モジュールはmbstringとmysqlの2つ。

php5設定

vi /etc/httpd/conf/httpd.conf
下記内容を変更
DirectoryIndex index.html index.html.var
↓
DirectoryIndex index.html index.htm index.cgi index.php

下記内容を追加(「AddType application/x-gzip .gz .tgz」の下)
AddType application/x-httpd-php .php
vi /etc/php.ini
short_open_tag = Off
↓
short_open_tag = On

expose_php = On
↓
expose_php = Off

max_execution_time = 30
↓
max_execution_time = 300

;default_charset = "iso-8859-1"
↓
default_charset = "UTF-8"

post_max_size = 8M
↓
post_max_size = 20M

upload_max_filesize = 2M
↓
upload_max_filesize = 20M

;date.timezone =
↓
date.timezone = Asia/Tokyo

;mbstring.language = Japanese
↓
mbstring.language = Japanese

;mbstring.internal_encoding = EUC-JP
↓
mbstring.internal_encoding = UTF-8

;mbstring.http_input = auto
↓
mbstring.http_input = UTF-8

;mbstring.http_output = SJIS
↓
mbstring.http_output = pass

;mbstring.encoding_translation = Off
↓
mbstring.encoding_translation = On

;mbstring.detect_order = auto
↓
mbstring.detect_order = auto

;mbstring.substitute_character = none;
↓
mbstring.substitute_character = none;
/etc/rc.d/init.d/httpd restart
  • php5の動作確認

    echo "<?php phpinfo(); ?>" > /var/www/html/info.php
    /etc/rc.d/init.d/iptables stop
    

    http://192.168.11.30/info.php

    php5の情報が表示されれば正常です。

    /etc/rc.d/init.d/iptables start
    rm -f /var/www/html/info.php
    

【DBサーバ】MySQL導入

  • MySQLインストール

    yum -y install mysql-server
    
  • MySQL設定

    vi /etc/my.cnf
    
    # 下記内容を追加([mysqld]に)
    # クライアントの文字コードに依存しない
    skip-character-set-client-handshake
    # 文字コード
    character-set-server=utf8
    
    下記内容を追加
    [mysql]
    default-character-set=utf8
    
    /etc/rc.d/init.d/mysqld start
    chkconfig mysqld on
    chkconfig --list mysqld
    

    ランレベルが2~5でonを確認する。

  • rootユーザのパスワード設定とUTF-8の確認

    mysql -u root
    
    SET PASSWORD FOR root@localhost=password('データベースパスワード');
    

    character_set_filesystemとcharacter_sets_dir以外がUTF-8であることを確認する。

    show variables like 'char%';
    

    Variable_nameValue
    character_set_clientutf8
    character_set_connectionutf8
    character_set_databaseutf8
    character_set_filesystembinary
    character_set_resultsutf8
    character_set_serverutf8
    character_set_systemutf8
    character_sets_dir/usr/share/mysql/charsets/
  • 初期ユーザと初期データベースの削除

    mysql -u root -pデータベースパスワード
    

    ユーザ名が空のユーザを確認し、削除する。

    SELECT user,host FROM mysql.user;
    
    userhost
    root127.0.0.1
    localhost
    rootlocalhost
    z-area.net
    rootz-area.net
    DELETE FROM mysql.user WHERE user='';
    

    データベースを確認しデータベースtestを削除する。

    SHOW DATABASES;
    
    Database
    informationschema
    mysql
    test
    DROP DATABASE test;
    exit
    

【WEBサーバ】Apache2SSL導入

  • 秘密鍵作成

    cd /etc/pki/tls/certs
    openssl genrsa -aes256 1024 > server.key
    
    Generating RSA private key, 1024 bit long modulus
    ......................++++++
    ............++++++
    e is 65537 (0x10001)
    Enter pass phrase:パスワード入力
    Verifying - Enter pass phrase:パスワード再入力
    
  • 公開鍵作成

    openssl req -new -key server.key > server.csr
    
    Enter pass phrase for server.key:パスワード入力
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    略
    Country Name (2 letter code) [XX]:JP
    State or Province Name (full name) []:Tokyo
    Locality Name (eg, city) [Default City]:Akihabara
    Organization Name (eg, company) [Default Company Ltd]:OreOreCA
    Organizational Unit Name (eg, section) []:z-area
    Common Name (eg, your name or your server's hostname) []:z-area.net
    Email Address []:空欄
    A challenge password []:空欄
    An optional company name []:空欄
    
  • 証明書作成

    openssl x509 -in server.csr -days 36500 -req -signkey server.key > server.crt
    
    Signature ok
    subject=/C=JP/ST=Tokyo/L=Akihabara/O=OreOreCA/OU=z-area/CN=z-area.net
    Getting Private key
    Enter pass phrase for server.key:パスワード入力
    
  • 秘密鍵パスワード解除
    現状のままだとApache2の再起動のたびにパスワードを求められるので、
    秘密鍵のパスワードを解除しておきます。

    mv server.key server.key.org
    openssl rsa -in server.key.org > server.key
    
    Enter pass phrase for server.key.org:パスワード入力
    writing RSA key
    
  • Apache2のSSL導入

    yum install mod_ssl
    
  • Apache2のSSL設定

    cp -pi /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.org
    vi /etc/httpd/conf.d/ssl.conf
    
    下記内容に変更
    #DocumentRoot "/var/www/html"
    ↓
    DocumentRoot "/var/www/html"
    
    #ServerName www.example.com:443
    ↓
    ServerName z-area.net:443
    
    
    ErrorLog logs/ssl_error_log
    ↓
    ErrorLog /var/log/httpd/ssl_error_log
    
    TransferLog logs/ssl_access_log
    ↓
    #TransferLog logs/ssl_access_log
    
    CustomLog logs/ssl_request_log \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    ↓
    CustomLog /var/log/httpd/ssl_access_log \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
    
    # POODLE SSLv3.0 脆弱性問題対処
    SSLProtocol all -SSLv2
    ↓
    SSLProtocol all -SSLv2 -SSLv3
    
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    ↓
    SSLCertificateFile /etc/pki/tls/certs/server.crt
    
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ↓
    SSLCertificateKeyFile /etc/pki/tls/certs/server.key
    
  • Apache2SSLの動作確認

    echo '<h1>It works!</h1>' > /var/www/html/index.html
    /etc/rc.d/init.d/iptables stop
    /etc/rc.d/init.d/httpd restart
    

    https://192.168.XXX.YYY/

    証明書の確認が表示された後、「It works!」が表示されれば正常です。

    /etc/rc.d/init.d/iptables start
    rm -f /var/www/html/index.html
    

【WEBサーバ】Apache2ログ設定

  • Apache2のログ設定

    vi /etc/httpd/conf/httpd.conf
    
    # エラーログ出力先
    ErrorLog /var/log/httpd/error_log
    
    # 通常ログからwormのログを除外
    SetEnvIf Request_URI "^/_mem_bin/" nolog
    SetEnvIf Request_URI "^/_vti_bin/" nolog
    SetEnvIf Request_URI "^/c/" nolog
    SetEnvIf Request_URI "^/d/" nolog
    SetEnvIf Request_URI "^/msadc/" nolog
    SetEnvIf Request_URI "^/MSADC/" nolog
    SetEnvIf Request_URI "^/scripts/" nolog
    SetEnvIf Request_URI "^/default.ida" nolog
    
    # 通常ログから画像、CSS、JavaScript参照ログを除外
    SetEnvIf Request_URI "\.(jpg|png|gif|css|js)$" nolog
    
    # 通常ログから自身の接続ログを除外
    SetEnvIf Remote_Addr 192.168.XX. nolog
    SetEnvIf Remote_Addr 10.8.0. nolog
    
    # 通常ログからロボットログを除外
    SetEnvIf User-Agent "Mediapartners-Google" nolog
    SetEnvIf User-Agent "msnbot" nolog
    SetEnvIf User-Agent "Yahoo! Slurp" nolog
    SetEnvIf User-Agent "Googlebot" nolog
    SetEnvIf User-Agent "Ask Jeeves" nolog
    SetEnvIf User-Agent "Gigabot" nolog
    SetEnvIf User-Agent "BecomeBot" nolog
    SetEnvIf User-Agent "Baiduspider" nolog
    SetEnvIf User-Agent "TurnitinBot" nolog
    SetEnvIf User-Agent "BecomeJPBot" nolog
    SetEnvIf User-Agent "Yeti" nolog
    SetEnvIf User-Agent "IRLbot" nolog
    SetEnvIf User-Agent "ia_archiver" nolog
    
    # 除外していない参照ログを通常ログとしてcombinedレベル(詳細)で出力
    CustomLog /var/log/httpd/access_log combined env=!nolog
    
  • Apache2の動作確認

    echo '<h1>It works!</h1>' > /var/www/html/index.html
    /etc/rc.d/init.d/iptables stop
    /etc/rc.d/init.d/httpd start
    

    http://192.168.XXX.YYY/

    「It works!」が表示されれば正常です。

    /etc/rc.d/init.d/iptables start
    rm -f /var/www/html/index.html
    
  • Apache2起動設定

    chkconfig httpd on
    chkconfig --list httpd
    

    ランレベルが2~5でonを確認する。

【WEBサーバ】Apache2設定

  • Apache2のドキュメントルート設定
    基本的な設定は完了したので、次にドキュメントルートの設定を行います。
    Apache2の設定はRaspberry Pi(Debian系)と違って1ファイルにまとまってます。

    vi /etc/httpd/conf/httpd.conf
    
    下記の設定となるように変更(変更部分または重要部分のみ記載)
    # ドキュメントルート
    DocumentRoot "/var/www/html"
    
    # 最上位の制御
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    
    # ドキュメントルートの制御
    <Directory "/var/www/html">
        Options -Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    
    # アクセス制御ファイル名
    AccessFileName .htaccess
    
    # ファイル名を指定しない場合の検索優先順位(index.html)
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
    </Files>
    
    # iconsルートの制御
    <Directory "/var/www/icons">
        Options -Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
  • welcome.confの無効化

    mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org
    
  • ドキュメントルートの権限変更

    chown -R ユーザ名 /var/www/html
    

【WEBサーバ】Apache2導入

  • Apache2導入

    yum -y install httpd
    yum list installed | grep httpd
    
    インストールした内容
    httpd.x86_64            2.2.15-39.el6.centos
    httpd-tools.x86_64      2.2.15-39.el6.centos
    
    cp -pi /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
    vi /etc/httpd/conf/httpd.conf
    
    下記内容を変更
    # サーバ情報表示内容
    ServerTokens OS
    ↓
    ServerTokens ProductOnly
    
    # サーバ署名表示内容
    ServerSignature On
    ↓
    ServerSignature Off
    
    # サーバー名
    #ServerName www.example.com:80
    ↓
    ServerName z-area.net:80
    

【CentOS】セキュリティ向上その2

  • TCP WrapperによるSSH接続アクセス制御

    SSH接続のセキュリティを高めるため、指定したクライアントのみから
    サーバーにSSH 接続できるようにします。

    vi /etc/hosts.deny
    
    下記内容を追加
    ALL: ALL
    
    vi /etc/hosts.allow
    
    下記内容を追加
    sshd: ALL
    

    書式は「サービス名: IP」です。
    denyは拒否するサービスとIPを指定。
    allowは許可するサービスとIPを指定し、denyより優先。
    ALLは「全て」を表します。

    ただしALLとはいってもLinuxの全てのサービスを拒否するわけではなく、
    サービスのデーモンがTCP Wrapperのライブラリであるlibwrapを
    含んでいるかどうかで決まるそうです。

  • SSH接続設定

    vi /etc/ssh/sshd_config
    
    下記内容のコメントを削除
    # rootでのログイン禁止
    #PermitRootLogin yes
    ↓
    PermitRootLogin yes
    
    # 空パスワード禁止
    #PermitEmptyPasswords no
    ↓
    PermitEmptyPasswords no
    
    下記内容を追加
    # hogeユーザのみログイン許可
    AllowUsers hoge
    
    /etc/rc.d/init.d/sshd restart
    
  • SELinux無効化

    vi /etc/sysconfig/selinux
    
    下記内容を変更
    SELINUX=enforcing
    ↓
    SELINUX=disabled
    
  • バッファオーバーフロー対策

    vi /etc/sysctl.conf
    
    # 下記内容を最終行に追加
    # exec-shield
    kernel.exec-shield = 2
    
  • TeraTermの公開鍵設定
    Raspberry Piと同様なので省略。
    TeraTermで生成した鍵を保存する際は任意の名前に変更できます。
    サーバーの数が複数ある場合、秘密鍵の名前は変えておいた方が管理が楽。

【CentOS】セキュリティ向上その1

  • 作業ユーザ追加

    useradd hoge
    passwd hoge
    
    パスワードを2回入力
    ユーザー hoge のパスワードを変更。
    新しいパスワード:
    新しいパスワードを再入力してください:
    passwd: 全ての認証トークンが正しく更新できました。
    
  • rootになれるユーザへ追加

    usermod -G wheel hoge
    
  • rootになれるユーザの制限

    vi /etc/pam.d/su
    
    下記内容のコメントを解除
    #auth           required        pam_wheel.so use_uid
    ↓
    auth           required        pam_wheel.so use_uid
    

    コメント解除するのはsufficientの方ではなく、requiredの方です。

    vi /etc/login.defs
    
    下記内容を追加
    SU_WHEEL_ONLY yes
    

    visudoコマンドも制御します。

    visudo
    
    下記内容を変更
    # %wheel        ALL=(ALL)       ALL
    ↓
    %wheel        ALL=(ALL)       ALL