nginx php iconv,Nginx +PHP部署一
Nginx??+PHP部署一
Alvin.zeng
目錄
一、安裝PHP
1、Yum安裝需要的包
yum?-y?install?gcc?gcc-c++?autoconf?libjpeg?libjpeg-devel?libpng?libpng-devel?freetype?freetype-devel?libxml2?libxml2-devel?zlib?zlib-devel?glibc?glibc-devel?glib2?glib2-devel?bzip2?bzip2-devel?ncurses?ncurses-devel?curl?curl-devel?e2fsprogs?e2fsprogs-devel?krb5?krb5-devel?libidn?libidn-devel?openssl?openssl-devel?openldap?openldap-devel?nss_ldap?openldap-clients?openldap-servers?mysql-devel?libevent-devel
2、編譯gd和libiconv
官方網站GD
http://www.libgd.org/releases/gd-2.0.35.tar.bz2
#:tar–xvfgd-2.0.35.tar.bz2–C?/opt/
#:cd?/opt/gd-2.0.35
#:./configure??--prefix=/usr/local/gd2
#:?make?&&?make?install
需要make兩次,第一次會出錯,
編譯libiconv
#:?tar–xvflibiconv-1.13.1.tar.gz
#:?cdlibiconv-1.13.1
#:./configure?--prefix=/usr/local/libiconv
#:?make?&&?make?install
3、編譯PHP5.3.3
官方網站
http://cn.php.net/distributions/php-5.3.3.tar.gz
#:rpm?-vih?libmcrypt-2.5.8-4.el5.centos.x86_64.rpm
#:rpm?-vih?libmcrypt-devel-2.5.8-4.el5.centos.x86_64.rpm
#:?tar–xvfphp-5.3.3.tar.gz–C?/opt/
#:cd?/opt/php-5.3.3
#:./configure?--prefix=/usr/local/php5.3?--enable-fpm?--with-mysql?--with-iconv=/usr/local/libiconv/?--with-pdo-mysql?--with-mysqli?--with-fpm-user?--with-config-file-path=/etc?--disable-sqlite3?--enable-soap?--with-zlib?--enable-xml?--with-gd=/usr/local/gd2??--enable-mbstring?--enable-mcrypt?--enable-mbstring?--enable-gd-native-ttf?--with-jpeg-dir?--with-png-dir?--with-freetype-dir?--with-openssl?--with-mcrypt
#:?make?&&?make?install
錯誤:configure:?error:?mysql?configure?failed.?Please?check?config.log?for?more?information.
解決:export?LDFLAGS=-L/usr/lib64/mysql/指定一下64位環境變量,默認是找32位的。
4、編譯eaccelerator和編譯xhprof和Client-phpredis
官方網站
http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
#:tar–xvfeaccelerator-0.9.6.1.tar.bz2–C?/opt/
#:?cd?/opt/eaccelerator-0.9.6.1
#:/usr/local/php5.3/bin/phpize運此命令生成configure文件
#:./configure?--prefix=/usr/local/eaccelerator?--with-php-config=/usr/local/php5.3/bin/php-config?--enable-eaccelerator
#:?make?&&?make?install
官方網站
http://pecl.php.net/get/xhprof
#:tar–xvfxhprof-0.9.2.tar.gz–C?/opt/
#:cd/opt/xhprof-0.9.2/extension
#:/usr/local/php5.3/bin/phpize運此命令生成configure文件
#:?./configure--with-php-config=/usr/local/php5.3/bin/php-config
#:?make?&&?make?install
官方網站,
http://download.github.com/owlient-phpredis-2.0.8-0-g0c0409a.tar.gz
#:tar–xvfowlient-phpredis-2.0.8-0-g0c0409a.tar.gz/opt/
#:?cdowlient-phpredis-2.0.8-0-g0c0409
#:/usr/local/php5.3/bin/phpize運此命令生成configure文件
#:?./configure--with-php-config=/usr/local/php5.3/bin/php-config
#:?make?&&?make?install
5、配置PHP
(1)、拷貝庫
#:cd?/usr/local/php5.3/lib/php/extensions/no-debug-non-zts-20090626/
#:cp?eaccelerator.soxhprof.so??/usr/local/php5.3/lib/php/extensions/
(2)、創建PHP用戶
#:groupadd?php
#:useradd–g?php?php
#:chgrp–R?php?/usr/local/php5.3
(3)、拷貝PHP.ini
#:cp?php.ini?/etc/
將PHP這兩個功能打開
extension?=?"xhprof.so"
extension?=?"eaccelerator.so"
[xhprof]
xhprof.output_dir=/tmp/xhprof
[eAccelerator]
;extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
(4)、拷貝fpm配置文件
#:cp?/usr/local/php5.3/etc/php-fpm.conf.default/usr/local/php5.3/etc/php-fpm.conf
(5)、修改fpm配置文件
#?cat?/usr/local/php5.3/etc/php-fpm.conf?|?grep?-v?";"
[global]
[www]
listen?=?127.0.0.1:9000
user?=?php
group?=?php
pm?=?dynamic
pm.max_children?=?50
pm.start_servers?=?20
pm.min_spare_servers?=?5
pm.max_spare_servers?=?35
pm.max_requests?=?500
6、啟動PHP
#:cd?/usr/local/php5.3/sbin/
#?./php-fpm
#:?ps–ef?|?grep?php
#?ps?-ef?|?grep?php
root?????14104?24282??0?22:43?pts/1????00:00:00?grep?php
root?????27635?????1??0?20:54??????????00:00:00?./php-fpm
php??????27636?27635??0?20:54??????????00:00:00?./php-fpm
php??????27637?27635??0?20:54??????????00:00:00?./php-fpm
php??????27638?27635??0?20:54??????????00:00:00?./php-fpm
php??????27639?27635??0?20:54??????????00:00:00?./php-fpm
php??????27640?27635??0?20:54??????????00:00:00?./php-fpm
php??????27641?27635??0?20:54??????????00:00:00?./php-fpm
php??????27642?27635??0?20:54??????????00:00:00?./php-fpm
php??????27643?27635??0?20:54??????????00:00:00?./php-fpm
php??????27644?27635??0?20:54??????????00:00:00?./php-fpm
php??????27645?27635??0?20:54??????????00:00:00?./php-fpm
php??????27646?27635??0?20:54??????????00:00:00?./php-fpm
php??????27647?27635??0?20:54??????????00:00:00?./php-fpm
php??????27648?27635??0?20:54??????????00:00:00?./php-fpm
php??????27649?27635??0?20:54??????????00:00:00?./php-fpm
php??????27650?27635??0?20:54??????????00:00:00?./php-fpm
php??????27651?27635??0?20:54??????????00:00:00?./php-fpm
php??????27652?27635??0?20:54??????????00:00:00?./php-fpm
php??????27653?27635??0?20:54??????????00:00:00?./php-fpm
php??????27654?27635??0?20:54??????????00:00:00?./php-fpm
php??????27655?27635??0?20:54??????????00:00:00?./php-fpm
二、安裝Nginx
1、創建用戶,建立網站數據目錄
#:groupadd??www
#:useradd–g?www?www
#:mkdir–p?/data/htdocs/zeng
#:mkdir–p?/data/htdocs/yong
#:chown?+?w?/data/htdocs/zeng
#:chwon?+w?/data/htdocs/yong
#:chown–R?www:www?/data/htdocs/zeng
#:chwon–R?www:www?/data/htdocs/yong
2、編譯pcre-8.10穩定版
官方網站
下載ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
#:tar–xvf?pcre-8.10–C?/opt/
#:cd?/opt/pcre-8.10
#:./configure?????注意不要指定路經,否則下面Nginx會編譯出錯
#:make?&&?make?install
3、編譯nginx-0.8.51穩定版
官方網站下載
下載http://nginx.org/download/nginx-0.8.52.tar.gz
#:tar–xvf?nginx-0.8.52.tar.gz–C?/opt/
#:cd?/opt/?nginx-0.8.52
#:./configure?--user=www?--group=www?--prefix=/usr/local/nginx?--with-http_stub_status_module?--with-http_ssl_module
#:make?&&?make?install
4、創建日志目錄
#:mkdir–p?/nginxlog/logs
#:chmod?+w?/nginxlog/logs
#:chown–R?www:www?/nginxlog/logs
5、編輯Nginx配置文件
#:vi/usr/local/nginx/confuser??www?www;
worker_processes8;#:啟動8個進程
error_log??/nginxlog/logs/nginx_error.log??crit;#:日志文件路徑
pid????????/usr/local/nginx/nginx.pid;#:pid文件路經
#Specifies?the?value?for?maximum?file?descriptors?that?can?be?opened?by?this?process.
worker_rlimit_nofile?65535;#:連接數量65535
events
{
use?epoll;
worker_connections?65535;#:連接數量65535
}
http
{
include???????mime.types;
default_type??application/octet-stream;
#charset??gb2312;
server_names_hash_bucket_size?128;
client_header_buffer_size?32k;
large_client_header_buffers?4?32k;
client_max_body_size?8m;
sendfile?on;
tcp_nopush?????on;
keepalive_timeout?60;
tcp_nodelay?on;
fastcgi_connect_timeout?300;
fastcgi_send_timeout?300;
fastcgi_read_timeout?300;
fastcgi_buffer_size?64k;
fastcgi_buffers?4?64k;
fastcgi_busy_buffers_size?128k;
fastcgi_temp_file_write_size?128k;
gzip?on;
gzip_min_length??1k;
gzip_buffers?????4?16k;
gzip_http_version?1.0;
gzip_comp_level?2;
gzip_types???????text/plain?application/x-javascript?text/css?application/xml;
gzip_vary?on;
#limit_zone??crawler??$binary_remote_addr??10m;
server
{
listen???????80;#:監聽端口80
server_name??www.yong.com;#:網站域名
index?index.html?index.htm?index.php;
root??/data0/htdocs/blog;#:網站數據聚路徑
#limit_conn???crawler??20;
location?~?.*\.(php|php5)?$
{
#fastcgi_pass??unix:/tmp/php-cgi.sock;
fastcgi_pass??127.0.0.1:9000;
fastcgi_index?index.php;
include?fcgi.conf;
}
location?~?.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires??????30d;
}
location?~?.*\.(js|css)?$
{
expires??????1h;
}
log_format??access??'$remote_addr?-?$remote_user?[$time_local]?"$request"?'
'$status?$body_bytes_sent?"$http_referer"?'
'"$http_user_agent"?$http_x_forwarded_for';
access_log??/data1/logs/access.log??access;
}
server
{
listen???????80;#:監聽端口
server_name??www.zeng.com;#:網站域名
index?index.html?index.htm?index.php;#:主頁格式
root??/data0/htdocs/www;#:網站數據存放路徑
location?~?.*\.(php|php5)?$
{
#fastcgi_pass??unix:/tmp/php-cgi.sock;
fastcgi_pass??127.0.0.1:9000;
fastcgi_index?index.php;
include?fcgi.conf;
}
log_format??wwwlogs??'$remote_addr?-?$remote_user?[$time_local]?"$request"?'
'$status?$body_bytes_sent?"$http_referer"?'
'"$http_user_agent"?$http_x_forwarded_for';
access_log??/data1/logs/wwwlogs.log??wwwlogs;#:數據日志存放路徑
}
server
{
listen??80;
server_name??status.blog.s135.com;
location?/?{
stub_status?on;
access_log???off;
}
}
}
6、新建fcgi配置文件
#vi/usr/local/nginx/conf/fcgi.conf
fastcgi_param??GATEWAY_INTERFACE??CGI/1.1;
fastcgi_param??SERVER_SOFTWARE????nginx;
fastcgi_param??QUERY_STRING???????$query_string;
fastcgi_param??REQUEST_METHOD?????$request_method;
fastcgi_param??CONTENT_TYPE???????$content_type;
fastcgi_param??CONTENT_LENGTH?????$content_length;
fastcgi_param??SCRIPT_FILENAME????$document_root$fastcgi_script_name;
fastcgi_param??SCRIPT_NAME????????$fastcgi_script_name;
fastcgi_param??REQUEST_URI????????$request_uri;
fastcgi_param??DOCUMENT_URI???????$document_uri;
fastcgi_param??DOCUMENT_ROOT??????$document_root;
fastcgi_param??SERVER_PROTOCOL????$server_protocol;
fastcgi_param??REMOTE_ADDR????????$remote_addr;
fastcgi_param??REMOTE_PORT????????$remote_port;
fastcgi_param??SERVER_ADDR????????$server_addr;
fastcgi_param??SERVER_PORT????????$server_port;
fastcgi_param??SERVER_NAME????????$server_name;
#?PHP?only,?required?if?PHP?was?built?with?--enable-force-cgi-redirect
fastcgi_param??REDIRECT_STATUS????200;
7、優化Linux內核參數
#:vi?/etc/sysctl.conf?在文件末尾增加
#:/sbin/sysctl?–p可立即生效
#?Add
net.ipv4.tcp_max_syn_backlog?=?65536
net.core.netdev_max_backlog?=??32768
net.core.somaxconn?=?32768
net.core.wmem_default?=?8388608
net.core.rmem_default?=?8388608
net.core.rmem_max?=?16777216
net.core.wmem_max?=?16777216
net.ipv4.tcp_timestamps?=?0
net.ipv4.tcp_synack_retries?=?2
net.ipv4.tcp_syn_retries?=?2
net.ipv4.tcp_tw_recycle?=?1
#net.ipv4.tcp_tw_len?=?1
net.ipv4.tcp_tw_reuse?=?1
net.ipv4.tcp_mem?=?94500000?915000000?927000000
net.ipv4.tcp_max_orphans?=?3276800
#net.ipv4.tcp_fin_timeout?=?30
#net.ipv4.tcp_keepalive_time?=?120
net.ipv4.ip_local_port_range?=?1024??65535
8、啟動Nginx
檢查配置文件是否正確,
#:/usr/local/nginx/sbin/nginx?–t
啟動
#:/usr/local/nginx/sbin/nginx
8.0X版本,重起
#:/usr/local/nginx/sbin/nginx–sreload
9、每寫每天定時切割Nginx日志的腳本
#:vi?/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
#!/bin/bash
#?This?script?run?at?00:00
#?The?Nginx?logs?path
logs_path="/usr/local/webserver/nginx/logs/"
Cutlog(){
mkdir?-p?${logs_path}$(date?-d?"yesterday"?+"%Y")/$(date?-d?"yesterday"?+"%m")/
mv?${logs_path}access.log?${logs_path}$(date?-d?"yesterday"?+"%Y")/$(date?-d?"yesterday"?+"%m")/access_$(date?-d?"yesterday"?+"%Y%m%d").log
kill?-USR1?`cat?/usr/local/webserver/nginx/nginx.pid`
}
Main()
{
Cutlog
}
#:Main
Main
設置crontab,每天凌晨00:00切割nginx訪問日志
crontab?-e
00?00?*?*?*?/bin/bash??/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
總結
以上是生活随笔為你收集整理的nginx php iconv,Nginx +PHP部署一的全部內容,希望文章能夠幫你解決所遇到的問題。