安装nginx
安装pcre
为了支持rewrite功能,我们需要安装pcre
yum install -y pcre*
//如过你已经装了,请跳过这一步
需要ssl的支持,如果不需要ssl支持,请跳过这一步
yum install -y openssl*
编译安装
./configure --prefix=/usr/local/nginx-1.8.1 \
--with-http_spdy_module \
--with-http_stub_status_module \
--with-pcre
--with-http_stub_status_module:支持nginx状态查询
--with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
--with-pcre:为了支持rewrite重写功能,必须制定pcre
报错
checking for OS
+ Linux 2.6.32-642.4.2.el6.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
安装所需的软件
yum -y install gcc gcc-c++
再 configure
报错
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
安装所需软件
yum install -y zlib-devel
再 configure
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using system zlib library
nginx path prefix: "/usr/local/nginx-1.8.1"
nginx binary file: "/usr/local/nginx-1.8.1/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx-1.8.1/conf"
nginx configuration file: "/usr/local/nginx-1.8.1/conf/nginx.conf"
nginx pid file: "/usr/local/nginx-1.8.1/logs/nginx.pid"
nginx error log file: "/usr/local/nginx-1.8.1/logs/error.log"
nginx http access log file: "/usr/local/nginx-1.8.1/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
安装
make //确定你的服务器有安装make,如果没有安装请执行yum install make
make install
添加启动脚本
这个网页可以 https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/ 下载启动脚本
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
修改下面脚本中两项为实际的路径
#nginx="/usr/sbin/nginx"
nginx="/usr/local/nginx-1.8.1/sbin/nginx"
#NGINX_CONF_FILE="/etc/nginx/nginx.conf"
NGINX_CONF_FILE="/usr/local/nginx-1.8.1/conf/nginx.conf"
把文件写入到 /etc/init.d/nginx
中
给权限,开启服务器
chmod +x /etc/init.d/nginx
service nginx start
php 编译安装,版本 php-7.0.11
取官方下载程序包
安装依赖包
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
configure: error: Please reinstall the libzip distribution
7.3需要安装高版本的libzip
# 先安装高版本的cmake,不然无法安装libzip
wget https://gitlab.kitware.com/cmake/cmake/-/archive/v3.0.2/cmake-v3.0.2.tar.gz
tar -zxvf cmake-v3.0.2.tar.gz
cd cmake-v3.0.2
./bootstrap
gmake && gmake install
# 安装libzip
先删除老的版本
yum remove libzip
wget https://nih.at/libzip/libzip-1.5.1.tar.gz
tar -zxvf libzip-1.5.1.tar.gz
cd libzip-1.5.1
mkdir build
cd build
cmake ..
make
make test
make install
编译安装(64位系统需要加上最后一个 --with-libdir=lib64
)
./configure --prefix=/usr/local/php-7.0.11 \
--with-config-file-path=/usr/local/php-7.0.11/etc \
--with-bz2 \
--with-curl \
--enable-ftp \
--enable-sockets \
--disable-ipv6 \
--with-gd \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local \
--enable-gd-native-ttf \
--with-iconv-dir=/usr/local \
--enable-mbstring \
--enable-calendar \
--with-gettext \
--with-libxml-dir=/usr/local \
--with-zlib \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-mysql=mysqlnd \
--enable-dom \
--enable-xml \
--enable-fpm \
--with-libdir=lib64
安装
make
make test
make install
复制 php 配置文件
cp php.ini-production /usr/local/php-7.0.11/etc/php.ini
复制 php-fpm 配置文件
cp /usr/local/php-7.0.11/etc/php-fpm.d/www.conf.default /usr/local/php-7.0.11/etc/php-fpm.d/www.conf
加入 service 管理脚本,修改到实际的路径即可
vim /etc/init.d/php7.0.11-fpm
#!/bin/bash
#
# Startup script for the PHP-FPM server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: php-7.0.11-fpm
# config: /usr/local/php/etc/php.ini
# config: /usr/local/php-7.0.11/etc/php.ini
# Source function library.
. /etc/rc.d/init.d/functions
# php 编译安装的目录
PHP_DIRECTORY=php-7.0.11
PHP_PATH=/usr/local/
DESC="php7.0.11-fpm daemon"
NAME=php-fpm
# php-fpm路径
DAEMON=$PHP_PATH/$PHP_DIRECTORY/sbin/$NAME
# 配置文件路径
CONFIGFILE=$PHP_PATH$PHP_DIRECTORY/etc/php-fpm.d/www.conf
# PID文件路径(在php-fpm.conf设置)
PIDFILE=$PHP_PATH/$PHP_DIRECTORY/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$PHP_DIRECORY
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
rh_start() {
$DAEMON -y $CONFIGFILE || echo -n " already running"
}
rh_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
rh_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
rh_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
rh_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
rh_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
rh_stop
sleep 1
rh_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
给执行权限
chmod +x php-7.0.11-fpm
设置 php-fpm pid 文件
在 php-fpm 配置文件的 [global] 部分加入 pid 设置项
vim /usr/local/php-7.0.11/etc/php-fpm.d/www.conf
#添加
[global]
pid = run/php-fpm.pid
nginx 配置
server {
server_name www.jintest1.com;
root /www/www.jintest1.com;
index index.html index.php;
location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
ok