CentOS7.xにWordPressをインストールする
|
はじめに
VM環境にCentOS7.Xをインストールし、WordPressを使えるようにインストールを行う。OSのインストールは割愛する。
各種インストールと設定
PHPインストール
1 2 |
yum -y install php-mysql php php-gd php-mbstring |
インストール後、バージョンを確認する
1 2 3 4 5 6 |
[root@cent7-sv ~]# php –version PHP 5.4.16 (cli) (built: Nov 6 2016 00:29:02) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies [root@cent7-sv ~]# |
phpの初期設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/etc/php.ini ・・・ 690行目付近 ; PHP’s default character set is set to empty. ; http://php.net/default-charset default_charset = "UTF-8" ★コメントアウト解除・設定変更 ・・・ 875行目付近 [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = "Asia/Tokyo" ★コメントアウト解除・設定変更 ・・・ 1675行目付近 [mbstring] ; language for internal character representation. ; http://php.net/mbstring.language mbstring.language = Japanese ★コメントアウト解除 ; internal/script encoding. ; Some encoding cannot work as internal encoding. ; (e.g. SJIS, BIG5, ISO-2022-*) ; http://php.net/mbstring.internal-encoding mbstring.internal_encoding = UTF-8 ★コメントアウト解除・設定変更 ; http input encoding. ; http://php.net/mbstring.http-input ;mbstring.http_input = auto ; http output encoding. mb_output_handler must be ; registered as output buffer to function ; http://php.net/mbstring.http-output ;mbstring.http_output = SJIS ; enable automatic encoding translation according to ; mbstring.internal_encoding setting. Input chars are ; converted to internal encoding by setting this to On. ; Note: Do _not_ use automatic encoding translation for ; portable libs/applications. ; http://php.net/mbstring.encoding-translation mbstring.encoding_translation = Off ★コメントアウト解除 ; automatic encoding detection order. ; auto means ; http://php.net/mbstring.detect-order mbstring.detect_order = auto ★コメントアウト解除 ; substitute_character used when character cannot be converted ; one from another ; http://php.net/mbstring.substitute-character mbstring.substitute_character = none; ★コメントアウト解除 ; overload(replace) single byte functions by mbstring functions. ; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(), ; etc. Possible values are 0,1,2,4 or combination of them. ; For example, 7 for overload everything. ; 0: No overload ; 1: Overload mail() function ; 2: Overload str*() functions ; 4: Overload ereg*() functions ; http://php.net/mbstring.func-overload mbstring.func_overload = 0 ★コメントアウト解除 ; enable strict encoding detection. mbstring.strict_detection = Off ★コメントアウト解除 ; This directive specifies the regex pattern of content types for which mb_output_handler() ; is activated. ; Default: mbstring.http_output_conv_mimetype=^(text/|application/xhtml\+xml) mbstring.http_output_conv_mimetype= ★コメントアウト解除 `````` ### mariadbのインストール ```bash yum -y install mariadb mariadb-server |
文字コードを設定する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@cent7-sv ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd # 文字コードの設定 character-set-server=utf8 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d |
MariaDBの初期設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
[root@cent7-sv ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we’ll need the current password for the root user. If you’ve just installed MariaDB, and you haven’t set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): ★[enter]キー OK, successfully used password, moving on… Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] ★[enter]キー New password: ★パスワードを入力し[enter]キー Re-enter new password: ★パスワードを入力し[enter]キー Password updated successfully! Reloading privilege tables.. … Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] ★[enter]キー … Success! Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] ★[enter]キー … Success! By default, MariaDB comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] ★[enter]キー – Dropping test database… … Success! – Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ★[enter]キー … Success! Cleaning up… All done! If you’ve completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! [root@cent7-sv ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement. MariaDB [(none)]> show databases; +——————–+ | Database | +——————–+ | information_schema | | mysql | | performance_schema | +——————–+ 3 rows in set (0.00 sec) MariaDB [(none)]> |
WordPress用DBの作成
1 2 3 4 5 6 |
mysql> create database wordpress; Query OK, 1 row affected (0.02 sec) mysql> grant all privileges on wordpress.* to wordpress@localhost identified by ‘password’; Query OK, 0 rows affected (0.09 sec) |
自動起動できるようにデーモンを登録し確認する
1 2 3 4 5 |
[root@cent7-sv ~]# systemctl enable mariadb.service Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@cent7-sv ~]# systemctl list-unit-files |grep mariadb mariadb.service enabled |
デーモンを起動し確認する
1 2 3 4 5 |
[root@cent7-sv ~]# systemctl start mariadb.service [root@cent7-sv ~]# systemctl list-units |grep mariadb mariadb.service loaded active running MariaDB database server [root@cent7-sv ~]# |
Apacheのインストール
1 2 |
yum -y install httpd |
Apacheの初期設定
最小限として、サーバ名の変更を行う
1 2 3 4 5 6 7 |
# ここでは、必要最小限のサーバー名だけ設定しておきます。 $ vi /etc/httpd/conf/httpd.conf … # サーバー名だけ指定しておく。 ServerName cent7-sv:80 … |
自動起動できるようにデーモンを登録し確認する
1 2 3 4 5 |
[root@cent7-sv ~]# systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@cent7-sv ~]# systemctl list-unit-files |grep httpd.service httpd.service enabled |
デーモンを起動し確認する
1 2 3 4 5 |
[root@cent7-sv ~]# systemctl start httpd.service [root@cent7-sv ~]# systemctl list-units |grep httpd httpd.service loaded active running The Apache HTTP Server [root@cent7-sv ~]# |
テストページ表示
phpのページが表示されることを確認
1 2 3 4 |
[root@cent7-sv ~]# cd /var/www/html [root@cent7-sv html]# echo ‘<!–?php echo phpinfo(); ?–>’ > index.php [root@cent7-sv html]# |
ブラウザでhttp://localhost/にアクセスし確認。
WordPressのインストール
WordPress日本語サイトにアクセスし、最新版のファイル名をチェックする
※2017/01/03現在 Ver4.7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@cent7-sv ~]# cd /var/www/html [root@cent7-sv html]# wget http://ja.wordpress.org/wordpress-4.7-ja.zip –2017-01-03 18:05:24– http://ja.wordpress.org/wordpress-4.7-ja.zip ja.wordpress.org (ja.wordpress.org) をDNSに問いあわせています… 66.155.40.250, 66.155.40.249 ja.wordpress.org (ja.wordpress.org)|66.155.40.250|:80 に接続しています… 接続しました。 HTTP による接続要求を送信しました、応答を待っています… 301 Moved Permanently 場所: https://ja.wordpress.org/wordpress-4.7-ja.zip [続く] –2017-01-03 18:05:24– https://ja.wordpress.org/wordpress-4.7-ja.zip ja.wordpress.org (ja.wordpress.org)|66.155.40.250|:443 に接続しています… 接続しました。 HTTP による接続要求を送信しました、応答を待っています… 200 OK 長さ: 9234057 (8.8M) [application/zip] `wordpress-4.7-ja.zip’ に保存中 100%[======================================>] 9,234,057 199KB/s 時間 25s 2017-01-03 18:05:49 (366 KB/s) – `wordpress-4.7-ja.zip’ へ保存完了 [9234057/9234057] [root@cent7-sv html]# unzip -q wordpress-4.7-ja.zip [root@cent7-sv html]# rm -f wordpress-4.7-ja.zip [root@cent7-sv html]# chown -R apache:apache /var/www [root@cent7-sv html]# chmod -R 2777 /var/www |
テストなので、パーミションは777に設定しているが、運用するには問題あり。
ブラウザWordpressにアクセス
以下アドレスにアクセスし、WordPressの初期画面が表示されれば、インストール完了となる
1 2 |
http://localhost/wordpress |