nginx+php5.5+php-fpm
概要
nginx+php5.5+php-fpmの環境設定手順
環境
CentOS6.x 64bit
手順
# nginxをインストール
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
vim /etc/yum.repos.d/nginx.repo
----
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
----
# インストール
yum install -y nginx
# 基本設定ファイル編集
vim /etc/nginx/nginx.conf
----
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip設定;
gzip on;
gzip_types text/plain
text/xml
text/css
text/javascript
image/x-icon
application/xml
application/rss+xml
application/json
application/x-javascript;
gzip_disable "MSIE [1-6]\.";
gzip_disable "Mozilla/4";
# トークン他
server_tokens off;
ignore_invalid_headers on;
# 設定ファイル読み込み
include /etc/nginx/conf.d/*.conf;
}
----
# 自動起動、再起動
service nginx start
chkconfig nginx on
# phpenvをインストール
cd
curl https://raw.github.com/CHH/phpenv/master/bin/phpenv-install.sh | sh
echo 'export PATH="$HOME/.phpenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(phpenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
which phpenv
mkdir -p ~/.phpenv/plugins
cd ~/.phpenv/plugins
git clone git://github.com/CHH/php-build.git
chmod 755 php-build/bin/rbenv-install
phpenv install
>>>>>
usage: phpenv install VERSION
Available versions:
5.2.17
5.3.10
5.3.11
いろいろ
5.5.5
5.5snapshot
master
<<<<<<
yum --enablerepo=epel install re2c libmcrypt libmcrypt-devel
yum install libxml2-devel bison bison-devel openssl-devel curl-devel libjpeg-devel libpng-devel libmcrypt-devel readline-devel libtidy-devel libxslt-devel httpd-devel enchant-devel libXpm libXpm-devel freetype-devel t1lib t1lib-devel gmp-devel libc-client-devel libicu-devel oniguruma-devel net-snmp net-snmp-devel bzip2-devel
vim /root/.phpenv/plugins/php-build/share/php-build/definitions/5.5.5
----
configure_option "--with-apxs2=/usr/sbin/apxs --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-fileinfo --enable-hash --enable-json --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-iconv --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --enable-phar --enable-shmop --enable-sockets --enable-simplexml --enable-dom --with-libxml-dir=/usr --enable-tokenizer --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --without-mm --with-enchant=/usr --with-zlib-dir=/usr --with-gd --enable-gd-native-ttf --with-gmp=/usr --with-jpeg-dir=/usr --with-xpm-dir=/usr/X11R6 --with-png-dir=/usr --with-freetype-dir=/usr --with-imap=/usr --with-imap-ssl --enable-intl --with-t1lib=/usr --with-mcrypt=/usr --with-snmp=/usr"
install_package "http://www.php.net/distributions/php-5.5.5.tar.bz2"
install_pyrus
install_xdebug "2.2.3"
enable_builtin_opcache
----
# install
phpenv install 5.5.5
# モジュールをコピー
cp /etc/httpd/modules/libphp5.so /root/.phpenv/versions/5.5.5/libphp5.so
phpenv rehash
phpenv global 5.5.5
php -v
# php-fpm
mkdir /var/log/php-fpm
chown -R nobody:nobody /var/log/php-fpm
cp -f /tmp/php-build/source/5.5.5/sapi/fpm/php-fpm.conf /usr/local/etc/php-fpm.conf
# サービス用起動スクリプトをコピー
cp -f /tmp/php-build/source/5.5.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig php-fpm on
# /etc/init.d/php-fpmを編集してconfファイルの場所を変更する
----
# php_fpm_CONF=${prefix}/etc/php-fpm.conf
↓
php_fpm_CONF=/usr/local/etc/php-fpm.conf
----
# php-fpm.confを編集
vim /usr/local/etc/php-fpm.conf
----
[global]
pid = run/php-fpm.pid
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
pm = dynamic
pm.max_children = 8
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 500
----
# 起動
service php-fpm start
chkconfig php-fpm on
# ログとドキュメントのディレクトリを作成
mkdir -p /var/log/nginx/dev1.example.com
mkdir -p /var/www/html/dev1.example.com/public
# nginxファイル作成
vim /etc/nginx/conf.d/dev1.example.com.conf
----
server {
# ポート、サーバネーム
listen 80;
server_name dev1.example.com;
# アクセスログ、エラーログ
access_log /var/log/nginx/dev1.example.com/access.log main;
error_log /var/log/nginx/dev1.example.com/error.log;
# ドキュメントルート
root /var/www/html/dev1.example.com/public;
# indexファイル
index index.php index.html index.htm;
# phpの処理
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# アクセスを制限する
location ~ (\.htaccess|\.git|\.svn) {
deny all;
}
# 文字コード
charset utf-8;
}
----
# 再起動
service nginx restart
service php-fpm restart
# 簡単なファイルを配置して確認
echo "<?php echo 'test'; phpinfo();" > /var/www/html/dev1.example.com/public/index.php
最終更新:2013年11月03日 21:54