在编译安装nginx、mysql、和php时依赖的包提前安装:
yum install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
wget http://nginx.org/download/nginx-1.7.4.tar.gz
解压nginx压缩包 tar -zxvf nginx-1.7.4.tar.gz
进入nginx安装目录 cd nginx-1.7.4
./configure $默认安装在/usr/local/nginx 指定--prefix=/www/server/nginx 安装此目录
make
make install
如果没有报错,顺利完成后,最好看一下nginx的安装目录
如果出现“[emerg] 10464#0: unknown directive "ssl" in /usr/local/nginx-0.6.32/conf/nginx.conf:74”则说明没有将ssl模块编译进nginx,在configure的时候加上“--with-http_ssl_module”即可^^
nginx.conf 配置文件
error_log /www/logs/nginx_error.log crit;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 30m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
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_vary on;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /www/htdocs;
fastcgi_intercept_errors on;
error_page 404 403 /html/404.htm;
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include vhosts/*.conf;
}
/etc/init.d/nginx 启动文件
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by ruijie. at 2014.02.26
# if you find any errors on this scripts,please contact ruijie.
# and send mail to ruijie at gmail dot com.
# [email protected]
nginxd=/www/server/nginx/sbin/nginx
nginx_config=/www/server/nginx/conf/nginx.conf
nginx_pid=/www/server/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ] && netstat -tunpl | grep nginx &> /dev/null;then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog!"
$nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog!"
$nginxd -s stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/nginx
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog!"
#kill -HUP `cat ${nginx_pid}`
$nginxd -s reload
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|help}"
exit 1
esac
exit $RETVAL
./configure --prefix=/www/server/php --with-config-file-path=/www/server/php/etc --enable-fastcgi --with-mysqli=/www/server/mysql/bin/mysql_config --with-mysql=/www/server/mysql --with-iconv-dir --with-freetype-dir=/www/server/phpextend/freetype --with-jpeg-dir=/www/server/phpextend/jpeg6 --with-png-dir=/www/server/phpextend/libpng --with-mhash= --with-gd=/www/server/phpextend/gd --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --without-pear --enable-cli --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap
make
make install
PHP + GD 安装完成
安装php5.6.12. pdo_mysql报错教训经验总结
如果报 php_mysql.c:999: undefined reference to `_mysqlnd_init'
./configure --prefix=/www/server/php5.6 --with-config-file-path=/www/server/php5.6/etc --with-mysql=/usr/local/server/mysql --with-mysqli=/usr/local/server/mysql/bin/mysql_config --with-xpm-dir --enable-mysqlnd --with-iconv-dir=/usr/local --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --with-freetype-dir --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
一定要带--enable-mysqlnd
php-fpm 配置文件
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = error
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10s
daemonize = yes
[www]
listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 40
request_terminate_timeout = 60
request_slowlog_timeout = 20
slowlog = /www/logs/$pool.phpslow.log
rlimit_files = 65535
rlimit_core = 0
chroot =
chdir =
catch_workers_output = yes
php_flag[display_errors] = on
php-fpm 启动文件
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/www/server/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
status)
if [ ! -r $php_fpm_PID ] ; then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
exit 1
;;
esac
编译安装pdo_mysql
cd /usr/local/src #进入软件包存放目录
tar zxvf phpredis-2.2.4.tar.gz #解压
cd phpredis-2.2.4 #进入安装目录
/usr/local/php/bin/phpize #用phpize生成configure配置文件
./configure --with-php-config=/usr/local/php/bin/php-config #配置
make #编译
make install #安装
安装完成之后,出现下面的安装路径
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
2、配置php支持
vi /usr/local/php/etc/php.ini #编辑配置文件,在最后一行添加以下内容
添加
extension="redis.so"
:wq! #保存退出
3 重启服务
sudo service nginx restart
sudo /etc/init.d/php-fpm restart
编译安装amqp
到这里下载rabbitmq-c的v0.2版:https://github.com/alanxz/rabbitmq-c/tags
第一步:
# 下载 rabbitmq-c library
mkdir rabbitmq-c
cd rabbitmq-c
wget https://github.com/alanxz/rabbitmq-c/tarball/0.2
tar zxvf 0.2
# 删除压缩包
rm -rf 0.2
cd alanxz-rabbitmq-c-f8f4fc7
# 下载最新版的codegen配件
wget https://github.com/rabbitmq/rabbitmq-codegen/tarball/master
tar zxvf master
mv rabbitmq-rabbitmq-codegen-7597914 codegen
# 删除压缩包
rm -rf master
# 配置、编译、安装
autoreconf -i
备:如果autoreconf -i -f时提示说缺少 libtoolize
解决方法:# yum install libtool
)
./configure
make
sudo make install
第二步:
安装php的amqp扩展:
wget http://pecl.php.net/get/amqp-1.0.7.tgz
tar -zxvf amqp-1.0.7.tgz
cd amqp-1.0.7
/usr/local/starcast/php/bin/php
./configure --with-php-config=/usr/local/starcast/php/bin/php-config --with-amqp
make
sudo make install
#直接在php.ini中添加生成的amqp.so
vim /usr/local/starcast/php/lib/php.ini
# 加入一行 extension = amqp.so
configure: error: Please install libgearman
yum install libgearman-devel.i686 libgearman.i686 后,此问题解决,却出现另外一问题:
libgearman version 0.21 or later required
从错误信息来看,是libgearman-devel 的版本低于0.21所至
yum install -y boost boost-devel