centos:centos_nginx_php
文書の過去の版を表示しています。
即効 環境構築
○ SELINUX 設定
# getenforce ← SELinux状態確認 Enforcing ← SELinux有効 # setenforce 0 ← SELinux無効化 # getenforce ← SELinux状態確認 Permissive ← SELinux無効 # vi /etc/sysconfig/selinux ← SELinux設定ファイル編集 SELINUX=enforcing ↓ SELINUX=disabled ← システム起動時にSELinuxを無効化
○ iptables(ファイアウォール)設定
# vi /etc/sysconfig/iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # /etc/rc.d/init.d/iptables restart 起動確認 httpサーバ(nginxなど)を動かして、ブラウザからアクセス
○ nginx
● EPELリポジトリを登録 # rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-4.noarch.rpm ● nginx インストール # yum -y install nginx ● 設定 デフォルトの document root は /usr/share/nginx/html その他、設定ファイル確認 # vi /etc/nginx/nginx.conf ● nginx 起動 # /etc/init.d/nginx start ● 自動起動設定 # chkconfig nginx on ● 本ドキュメント最下部に SSL の設定例あり
○ PHP 5.3
● remiリポジトリを登録 # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm ● PHP インストール # yum -y --enablerepo=remi install php
○ PDO
# yum -y --enablerepo=remi install php-pdo
○ pear
# yum -y --enablerepo=remi install php-pear
○ APC(PHP用アクセラレータ)
# yum -y --enablerepo=remi install php-devel # yum -y --enablerepo=remi install httpd-devel # pecl install apc # echo "extension=apc.so" | sudo tee /etc/php.d/apc.ini
○ FastCGI
●参考サイト http://ja.wikipedia.org/wiki/FastCGI http://d.hatena.ne.jp/IT7C/20101003/1286082204 > fpm(FastCGI Process Manager)はphpでFastCGIを使うための実装の一つです。 > php 5.3.3でfpmが標準で使えるようになったので使ってみる。今まではphpに > パッチを当てる必要がありました。ただし、標準になったとはいえ、PHPのコ > ンパイル時にオプションの設定が必要なので、configureからやり直す必要が > ある。尚、fpmのコンパイルするにあたって予め1.4系のlibeventをインストール > しておく必要があります。 ⇒ 5.3.4 では全く作業しなくても動いている。。。
○ PHP-FPM
●参考サイト
http://php.net/manual/ja/install.fpm.php
● PHP-FPM インストール
# yum -y --enablerepo=remi install php-fpm
● nginx への設定追加
# vi /etc/nginx/nginx.conf
108行目付近、以下の行を追加。
101行目付近にコメントされている行があるので、「\.php」の「\」をはずし、
SCRIPT_FILENAE のパスを修正。
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
● PHP-FPM 起動
# /etc/rc.d/init.d/php-fpm start
● nginx 再起動(設定反映)
# /etc/init.d/nginx restart
● 自動起動設定
# chkconfig php-fpm on
● ブラウザからphpファイルにアクセスして表示されることを確認
○ TokyoCabinet/TokyoTyrant
●参考サイト
http://blog.livedoor.jp/sasata299/archives/51322051.html
> TokyoCabinet が key-valueストアの機能を持っていて、データを保存したり、
> 取り出したり出来ます。TokyoTyrant は TokyoCabinet をネットワーク越しに
> 操作できるようにしたラッパーです。キャビネット(内閣)を傀儡にするタイ
> ラント(僭主)ということでこのような名前が付けられたそうです
使ってみようTokyo Cabinet
http://fallabs.com/mikio/tech/promenade.cgi?id=72
公式
http://fallabs.com/
tokyo_tyrant
http://www.php.net/manual/ja/book.tokyo-tyrant.php
TokyoTyrant の定数
http://www.php.net/manual/ja/class.tokyotyrant.php#tokyotyrant.constants.types
●下準備
# yum -y install zlib-devel bzip2-devel
● TokyoCabinet インストール
# wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.46.tar.gz
# tar xvzf tokyocabinet-1.4.46.tar.gz
# cd tokyocabinet-1.4.46
# ./configure
# make
# make install
● TokyoTyrant インストール
# wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
# tar xvzf tokyotyrant-1.1.41.tar.gz
# cd tokyotyrant-1.1.41
# ./configure
# make
# make install
● PECL::tokyo_tyrantをインストール
# pecl install tokyo_tyrant-beta
# echo "extension=tokyo_tyrant.so" | sudo tee /etc/php.d/tokyo_tyrant.ini
# /etc/rc.d/init.d/php-fpm restart
以下、動作確認用コードサンプル
<?php
$tt = new TokyoTyrant('localhost', 1978);
$tt->put('some_key', 'some_value');
echo $tt->get('some_key');
● chkconfig 登録
■ 自動起動ファイルを修正する
# vi /usr/local/sbin/ttservctl
3行目付近、以下の6行を追加
# chkconfig: 345 99 01
# description: Startup script for the server of Tokyo Tyrant
# processname: tokyotyrant
# Source function library.
. /etc/init.d/functions
17行目付近、以下の行変更
#cmd="ttserver"
cmd="/usr/local/bin/ttserver"
152行目付近、以下の3行追加
status)
status -p "$pidfile" $prog
;;
163行目付近、以下の行変更
# printf 'Usage: %s {start|stop|restart|hup}\n' "$prog"
printf 'Usage: %s {start|stop|status|restart|hup}\n' "$prog"
■ シンボリックリンク作成
# ln -s /usr/local/sbin/ttservctl /etc/rc.d/init.d/
■ 確認
起動
# service ttservctl start
終了
# service ttservctl stop
状態確認
# service ttservctl status
● 不正終了など、サービス再起動できないときの対処(pidファイルの削除)
# rm /var/ttserver/pid
Tips)
/usr/local/sbin/ttservctl stop
rm /var/ttserver/pid
/usr/local/sbin/ttservctl start
/etc/rc.d/init.d/php-fpm restart
/etc/init.d/nginx restart
○ nginx + SSL
● OpenSSL の鍵を作成
# cd /etc/nginx/
■ RSA形式の秘密鍵を作成する
# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
..............................................................................++++++
.......++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:aaaaaaaaaa
Verifying - Enter pass phrase for server.key:aaaaaaaaaa
■ CSRファイルを作成する。
# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:aaaaaaaaaa
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:jp
State or Province Name (full name) [Berkshire]:Osaka
Locality Name (eg, city) [Newbury]:Osaka
Organization Name (eg, company) [My Company Ltd]:Aska-ltd.
Organizational Unit Name (eg, section) []:Main Section
Common Name (eg, your name or your server's hostname) []:testsv
Email Address []:testsv@aska-ltd.jp
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# cp server.key server.key.org
# openssl rsa -in server.key.org -out server.key
Enter pass phrase for server.key.org:
writing RSA key
■ デジタル証明書(server.crt)の作成
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=jp/ST=Osaka/L=Osaka/O=Aska-ltd./OU=Main Section/CN=testsv/emailAddress=testsv@aska-ltd.jp
Getting Private key
● nginx の SSL設定ファイルを設定
# vi /etc/nginx/conf.d/ssl.conf
5行目付近「sever {」以下のコメントをすべてはずす。
10~11行目付近、鍵のパスを修正
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
ssl_certificate server.crt;
ssl_certificate_key server.key;
26行目付近、PHPを使うために以下を追加
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
● SSL 有効化(nginx 再起動)
# /etc/init.d/nginx restart
● ブラウザでアクセスして動作確認
http://www.example.com
centos/centos_nginx_php.1360734418.txt.gz · 最終更新: 2025/02/16 13:50 (外部編集)
