さくらVPSにカスタムOSでCentOS7入れてLEMP
さくらVPSの標準のOSはCentOS6。せっかくなのでカスタムOSでCentOS7を入れて初期設定ちょこちょこやってLEMP環境くらい整えてみましょ−。
1.カスタムOSインストール
カスタムOSインストールガイド - CentOS 7
基本的にはここのまま。
VNCコンソールがやたらと使いにくいけどまぁ我慢。一回パーティションの切り方失敗?して起動しなくなったけど、どうも/ /home /varだけで切ってたのが良くなかったみたい?/bootとか用意してやり直したらうまく行きました。
$ cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
おっけー。
2.sshで接続してEmacsとか
設定ぶっ壊してなければ$ ssh IPアドレス or $ ssh ホストでつながるはず。
Emacsの標準は23系かと思ってたけど24系なんですね。やったね!!
$ yum info emacs
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
インストール済みパッケージ
名前 : emacs
アーキテクチャー : x86_64
エポック : 1
バージョン : 24.3
リリース : 11.el7
容量 : 14 M
リポジトリー : installed
提供元リポジトリー : base
要約 : GNU Emacs text editor
URL : http://www.gnu.org/software/emacs/
ライセンス : GPLv3+
説明 : Emacs is a powerful, customizable, self-documenting,
: modeless text editor. Emacs contains special code editing
: features, a scripting language (elisp), and the capability
: to read mail, news, and more without leaving the editor.
:
: This package provides an emacs binary with support for X
: windows.
$ sudo yum install emacs
Emacsにはmelpaとmarmalade追加して
;;=======================================================================
;;packages
;;=======================================================================
;packages
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/#/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(package-initialize)
M-x list-packagesでweb-modeとphp-modeを入れます。
あとの設定は前回記事な感じ。
・Emacsにweb-mode&php-mode入れて超快適
Mozcのとこはコメントアウト。
3.LEMP環境
LEMP server on CentOS 7 with FastCGI
CentOS 7 でLAMP(Nginx+MariaDB(MySQL)+PHP)インストールからWordPressを動かすまで(Nginx編)
Nginxはepalか公式のリポジトリを有効にしないと見つからないです。あとMySQLがMariaDBに変わってる。
$ yum info nginx
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
エラー: 表示するパッケージはありません
3−1.Nginx
どうせリポジトリ追加するなら公式から最新持ってきましょ。
$ sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ sudo yum install nginx
nginx x86_64 1:1.6.2-1.el7.ngx nginx 353 k
起動もserviceじゃなくてsystemctlになってるのでこれで起動して確認。
$ sudo systemctl start nginx.service
$ sudo systemctl list-units | grep nginx
nginx.service loaded active running nginx - high performance web server
自動起動登録
$ sudo systemctl enable nginx.service
この時点でブラウザからアクセスしたら表示されなかったけど、サーバー上から$ curl したらNginxのWelcomページは表示されてるみたい。きっとFirewall。
$ sudo firewall-cmd --permanent --add-service=http
$ sudo systemctl restart firewalld
おっけー。
3−2.PHP&PHP-FPM
$ sudo yum install php php-common php-fpm php-mysql
php x86_64 5.4.16-23.el7_0.3 updates 1.3 M
php-common x86_64 5.4.16-23.el7_0.3 updates 561 k
php-fpm x86_64 5.4.16-23.el7_0.3 updates 1.4 M
php-mysql x86_64 5.4.16-23.el7_0.3 updates 97 k
依存性関連でのインストールをします:
httpd x86_64 2.4.6-19.el7.centos updates 2.7 M
httpd-tools x86_64 2.4.6-19.el7.centos updates 78 k
libzip x86_64 0.10.1-8.el7 base 48 k
mailcap noarch 2.1.41-2.el7 base 31 k
php-cli x86_64 5.4.16-23.el7_0.3 updates 2.7 M
php-pdo x86_64 5.4.16-23.el7_0.3 updates 95 k
httpd入るのかよ・・・とか思いつつ。
設定
$ sudo emacs /etc/php-fpm.d/www.conf
apache→nginx
[www]
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock
; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: -1
;listen.backlog = -1
; List of ipv4 addresses of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will b\
e
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 127.0.0.1
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0666
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's grou\
p
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
$ sudo emacs /etc/php.ini
cgi.fix_pathinfo=0
コメントアウト外して1→0に。
3−3.PHP-fpmとNginxの連携
PHP-fpm のlistenはunixドメインソケットを使用します。
というわけでNginxのconf
ポイントは
fastcgi_pass unix:/var/run/php-fpm/php5-fpm.sock;
ここでunixドメインソケット指定
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_n\
ame;
ここはパスを間違えないように書き換え。(現在はデフォルトの/usr/share/nginx/htmlをrootディレクトリとしているのでこう)
php-fpmの方
$ sudo emacs /etc/php-fpm.d/www.conf
listen = /var/run/php-fpm/php5-fpm.sock
/usr/share/nginx/html/以下にtest.phpとしていつものphpのバージョン表示するアレを作成。
$ sudo emacs /usr/share/nginx/html/test.php
<?php
phpinfo();
?>
php−fpmとNginx再起動
$ sudo systemctl restart php-fpm
$ sudo systemctl restart nginx
http://IPアドレス/test.phpにアクセスしてアレが表示されればおっけー。
おっけー。
4.MariaDB
$ sudo yum install mariadb mariadb-server
================================================================================
Package アーキテクチャー
バージョン リポジトリー
容量
================================================================================
インストール中:
mariadb x86_64 1:5.5.41-2.el7_0 updates 8.9 M
mariadb-server x86_64 1:5.5.41-2.el7_0 updates 11 M
依存性関連でのインストールをします:
libaio x86_64 0.3.109-12.el7 base 24 k
perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k
perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k
perl-DBD-MySQL x86_64 4.023-5.el7 base 140 k
perl-DBI x86_64 1.627-4.el7 base 802 k
perl-IO-Compress noarch 2.061-2.el7 base 260 k
perl-Net-Daemon noarch 0.48-5.el7 base 51 k
perl-PlRPC noarch 0.2020-14.el7 base 36 k
systemctlでスタートと自動起動登録
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
これで一応LEMP環境は整いましたね。お疲れ様です。
試しにWPでも入れてみましょうか。
5.WPインストール
とりあえずWPのためにNginxの設定ファイルをちょこちょこ変更します。rootディレクトリは/var/www/がいいのだ。
というわけでrootディレクトリ変更とかWordpress用のURI書き換え設定とか書き加えて・・・
$ sudo emacs /etc/nginx/conf.d/default.conf
Nginxは再起動。
$ sudo systemctl restart nginx
WPは日本の本家からDL。解凍して/var/www以下に配置。
$ wget https://ja.wordpress.org/wordpress-4.1.1-ja.zip
$ unzip wordpress-4.1.1-ja.zip
$ sudo cp -r wordpress /var/www
$ sudo chown -R nginx:nginx /var/www/wordpress/
$ sudo chmod -R 755 /var/www/wordpress/
WP用のDB用意。MariaDBになってるけど操作自体はMySQLと変わりませんね。
$ mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on *.* to "tmin"@"localhost" Identified by "passwd";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
で、サーバーIP/wordpress/にアクセスして−
wp-config.phpが作られなくて手動で作ったけどそれ以外は普通にインストール完了。
おっけーですね。
さて、次は設定詰めてconcrete5を動かしたいとこだけど、初期設定すっ飛ばしてLEMP環境作っちゃったからそのへんも何とかしとかなきゃなぁ。
あぁ、そうそう、CentOSは7になって微妙にパッケージ変わってたり、さくらVPSの初期CentOSでデフォルトで入ってるリポジトリやアプリが入ってなくて戸惑うこととか、systemctlに変わってて戸惑うとことか多々ありました。使い慣れたのが変わると結構時間取られますね−。
関連記事
・CentOS 6.5でnginx+php-fpmでPHPを動かしてみる
・Cent OS 6.5でNginx+php-fpm+mysqlでFC2オープンソース版とWordPress
・CentOSサーバーにDrupal入れてみた
・CentOS6.5 x Nginx x php-fpm x MySQLでConcrete5.6
・Concrete5.7インストールのための環境つくり(未完
・Drupal Coreの手動Update(7.30→7.31)
・CentOS6.5でNFS Serverでファイル共有
・CentOS6.5+Nginx+php-fpm+MySQLでConcrete5.7
・Concrete5.7.0が正式にリリースされたので早速CentOSサーバーに入れて動かしてみたよ
・さくらVPSにカスタムOSでCentOS7入れてLEMPにconcrete5&baserCMS
・CentOS7サーバー(さくらVPS)でssh公開鍵認証を使う
- 関連記事
-
- さくらVPSにカスタムOSでCentOS7入れてLEMPにconcrete5&baserCMS (2015/03/17)
- さくらVPSにカスタムOSでCentOS7入れてLEMP (2015/03/16)
- さくらVPS(CentOS6.6)にGitlabをインストール (2015/02/09)
Windowsの目次・Linuxの目次・Linuxの目次2・ ・自作PC関連の目次・Web技術関連の目次
全記事一覧・情報サイト新着RSS一覧
Sponsored Link