VirtualboxのCentos7にLAMP(Nginx)を構築しWordpressインストール
VirtualboxにCentosのminimalをインストールした状態から
LAMP(Nginx使用)
を構築しWordPressをインストールします。
ファイアウォール設定
SSHとHTTPを開放します。 Centos7からはfirewalldを用いるようになっているみたいですが、 minimalにはインストールされていなかったのでインストール。
yum install -y firewalld # HTTP の永続的な開放 firewall-cmd --permanent --zone=public --add-service=http # 変更の反映 firewall-cmd --reload
Nginx インストール
# リポジトリ追加 vi /etc/yum.repos.d/nginx.repo # 下記内容で新規作成 [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=0 # Nginx インストール yum --enablerepo=nginx install nginx #起動 systemctl start nginx systemctl enable nginx
ウェブブラウザからhttp://192.168.56.xxxにアクセスすると以下のページが表示されます。 (192.168.56.xxxはip addressです。)
Nginx 設定
cp -a /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org vi /etc/nginx/conf.d/default.conf # 以下の内容を記述 server { root /var/www/html; listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /var/www/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } }
PHP インストール
# EPEL, Remi リポジトリ追加 yum install epel-release rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm yum --enablerepo=remi update remi-release vim /etc/yum.repos.d/epel.repo # [epel のenable = 1 から0 に変更 # PHP インストール yum --enablerepo=epel,remi,remi-php70 install php php-gd php-mbstring php-mysqlnd php-opcache
PHP-FPM インストール
NginxでPHPを実行するパッケージをインストールします。
yum --enablerepo=remi,remi-php70 install php-fpm cp -a /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org vi /etc/php-fpm.d/www.conf # 修正箇所 listen = /var/run/php-fpm/php-fpm.sock user = nginx group = nginx listen.owner = nginx listen.group = nginx listen.mode = 0660 # 起動 sytemctl start php-fpm.service systemctl enable php-fpm.service
NginxからPHPを動かす
vi /etc/nginx/conf.d/default.conf # 以下記述 server { root /var/www/html; listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { root /var/www/html; index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # PHP-FPM 設定 location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
http://192.168.56.xxx/index.phpにアクセスすると以下のようにが表示されます。
MariaDB インストール
yum install mariadb mariadb-server # 起動設定 systemctl start mariadb.service systemctl enable mariadb.service # 確認 systemctl status mariadb.service # 設定 vi /etc/my.cnf.d/server.cnf # 以下追加 [client] default-character-set = utf8mb4 vi /etc/my.cnf.d/client.cnf # 以下追加 [server] character-set-server = utf8mb4 # 設定の反映 systemctl restart mariadb.service
MariaDBにDB作成
- データベース : kirIndb
- ユーザ : kirIn
- パスワード : kirInpass
mysql -u root -p # パスワードを打つように言われますが、Enter キーを押します。 # コンソールに以下内容を記述 MariaDB [(none)]> GRANT ALL PRIVILEGES ON kirIndb.* TO kirIn@localhost IDENTIFIED BY 'kirInpass'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> CREATE DATABASE kirIndb CHARACTER SET utf8; MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | kirIndb | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.01 sec) MariaDB [(none)]> exit
WordPress インストール
# nginx設定 vi /etc/nginx/conf.d/default.conf # 以下内容 server { root /var/www/html; listen 80; server_name localhost; index index.html index.htm index.php; #try_files $url $url/ /index.php; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { # WordPress パーマリンク設定を利用可能にする if (!-e $request_filename) { rewrite ^.+?(/wp-.*) $1 last; rewrite ^.+?(/.*\.php)$ $1 last; # ドキュメントルートから WordPress までの相対パス # (ドキュメントルートにインストールしたため相対パスは記入なし) rewrite ^ /index.php last; } } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # PHP-FPM 設定 location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # 再読み込み systemctl restart nginx systemctl restart php-fpm
wp-cli インストール
cd /root curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar # インストール確認 php wp-cli.phar --info # wp コマンドで使用可能にする(実行権限付与とパスを通す) chmod +x wp-cli.phar mv wp-cli.phar /usr/local/bin/wp # wp コマンド使用確認 wp --info # worepress ダウンロード wp core config --dbname=kirIndb --dbuser=kirIn --dbpass=kirInpass --locale=ja --extra-php <<PHP > define('WP_POST_REVISIONS', 3); > PHP # Wordpress 初期設定 wp core install --url=http://192.168.56.121/ --title=ex --admin_user=kirIn --admin_password=kirInpass --admin_email=test@example.com # 確認 wp user list wp option get siteurl wp option get blogname wp option get admin_email
http:192.168.56.xxx/にウェブブラウザでアクセスするとwordpressで作成されたホームページが表示されます。