1)安装libiconv支持
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13
./configure --prefix=/usr/local
make && make install
#为PHP编译创建连接,PHP默认调用/usr/lib/libiconv.so.2库文件
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
2)安装mcrypt支持
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make && make install
3)安装并配置PHP & PHP-FPM FastCGI
tar xjvf php-5.2.10.tar.bz2
gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1 #为PHP打FPM补丁
cd php-5.2.10
#修正PHP源码文件时间戳,默认解压时提示文件时间戳警告
find . -type f -exec touch {} \;
#因为编译时PHP存在一个BUG,默认不安装pear包--without-pear
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/bin/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local/bin --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-gd --with-mcrypt --with-curl --with-curlwrappers --enable-xml --enable-mbstring --enable-bcmath --enable-shmop --enable-mbregex --enable-gd-native-ttf --enable-sysvsem --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-inline-optimization --enable-discard-path --disable-rpath --with-openssl --without-pear
#针对iconv库修改Makefile配置内容
sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
make && make install
#安装PDO扩展
tar xzvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL_1.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
#安装eAccelerator扩展
tar xjvf eaccelerator-0.9.5.tar.bz2
cd eacceleraotr-0.9.5
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
#创建eAccelerator缓存目录
mkdir /usr/local/php/ecache
#创建PHP错误日志目录
mkdir /usr/local/php/logs
#创建PHP配置文件,根据自己的需要修改配置选项
cp php.ini-dist /usr/local/php/etc/php.ini
vi /usr/local/php/etc/php.ini
#修改扩展路径
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613"
#添加PDO和eAccelerator扩展支持
extension = "pdo_mysql.so"
#配置eaccelerator加速PHP,在末尾加入以下信息
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/php/ecache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
#添加WEB用户组
groupadd www
#添加WEB用户
useradd -g www www
#创建WEB目录
mkdir -p /root/www/htdocs
#修改WEB目录权限,添加写权限
chmod +w /root/www/htdocs
#修改root目录所属组及用户,注意此处必须将WEB目录所在的服目录全部更改为WEB服务器及PHP FastCGI进程同一个用户组及用户,否则在访问PHP脚本时可能返回[404]No input file specified.错误
chown www:www /root
#修改www目录所属组及用户
chown -R www:www /root/www
#创建PHP-FPM配置文件,并输入以下内容
vim /usr/local/php/etc/php-fpm.conf
<?xml version="1.0" ?>
<configuration>
<section name="global_options">
<value name="pid_file">/usr/local/php/logs/php-fpm.pid</value>
<value name="error_log">/usr/local/php/logs/php-fpm.log</value>
<value name="log_level">notice</value>
<value name="emergency_restart_threshold">10</value>
<value name="emergency_restart_interval">1m</value>
<value name="process_control_timeout">5s</value>
<value name="daemonize">yes</value>
</section>
<workers>
<section name="pool">
<value name="name">default</value>
<value name="listen_address">127.0.0.1:9000</value>
<value name="listen_options">
<value name="backlog">-1</value>
<value name="owner"></value>
<value name="group"></value>
<value name="mode">0666</value>
</value>
<value name="php_defines">
<value name="sendmail_path">/usr/sbin/sendmail -t -i</value>
<value name="display_errors">1</value> #0改为1显示php错误信息,否则nginx会报500空白页
</value>
<value name="user">www</value>
<value name="group">www</value>
<value name="pm">
<value name="style">static</value>
<value name="max_children">128</value>
<value name="apache_like">
<value name="StartServers">20</value>
<value name="MinSpareServers">5</value>
<value name="MaxSpareServers">35</value>
</value>
</value>
<value name="request_terminate_timeout">0s</value>
<value name="request_slowlog_timeout">0s</value>
<value name="slowlog">logs/slow.log</value>
<value name="rlimit_files">51200</value>
<value name="rlimit_core">0</value>
<value name="chroot"></value>
<value name="chdir"></value>
<value name="catch_workers_output">yes</value>
<value name="max_requests">10240</value>
<value name="allowed_clients">127.0.0.1</value>
<value name="environment">
<value name="HOSTNAME">$HOSTNAME</value>
<value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
<value name="TMP">/tmp</value>
<value name="TMPDIR">/tmp</value>
<value name="TEMP">/tmp</value>
<value name="OSTYPE">$OSTYPE</value>
<value name="MACHTYPE">$MACHTYPE</value>
<value name="MALLOC_CHECK_">2</value>
</value>
</section>
</workers>
</configuration>
#修改系统最大打开文件句柄数,此值一定要与php-fpm.conf配置文件中的rlimit_files值相同,否则启动PHP时会有警告
ulimit -SHn 51200
#启动PHP FastCGI进程
/usr/local/php/sbin/php-fpm start &
4)安装并配置Nginx
tar xzvf nginx-0.7.61.tar.gz
cd nginx-0.7.61/
find . -type f -exec touch {} \;
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
#编辑Nginx配置文件并输入一下内容
vim /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 8;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include 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"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_types text/plain text/css application/x-javascript application/xml;
fastcgi_connect_timeout 500;
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_intercept_errors on;
server {
listen 80;
server_name localhost;
index index.html index.php;
root /root/workspace/htdocs;
access_log logs/host.access.log main;
location ~ \.php$ {
root /root/workspace/htdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.(gif|jpg|jpeg|png|swf|bmp)$ {
expires 30d;
}
location ~ \.(css|js)$ {
expires 1h;
}
#charset koi8-r;
#location / {
# root html;
# index index.html 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 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
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
#启动Nginx
/usr/local/nginx/sbin/nginx &
5)配置并启动MySQL服务
#修改MySQL默认数据库目录权限
chmod -R 766 /var/lib/mysql
#启动MySQL服务
mysqld_safe --defaults-file=/etc/my.cnf &
