1、安装php7.0(注意使用root权限)
首先安装yum源
centos-6.*
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
centos-7.*
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
查看可安装版本
yum list php*
然后安装php7.0及相关拓展
yum install php70w-common php70w php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-devel
2、yum 安装 nginx
第一种方法:
(1) cd /etc/yum.repos.d/
(2) vim nginx.repo
输入:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
然后:
yum install nginx -y
第二种方法:
(1)ububtu平台编译环境
apt-get install build-essential
apt-get install libtool
centos平台编译环境
yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++
(2)选择源码路径
cd /usr/local/src
(3)安装 zlib
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
(4)安装openssl
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
(5)安装pcre
wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install
(6)下载nginx
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.37 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1t
make
make install
--with-pcre=/usr/local/src/pcre-8.37
--with-zlib=/usr/local/src/zlib-1.2.11
--with-openssl=/usr/local/src/openssl-1.0.1t
都是指源码路径
安装完成后 /usr/local/nginx 目录
(7)启动nginx
usr/local/nginx/nginx #root权限
如果还不能访问 就配置一下防火墙
iptables -I INPUT 5 -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
service iptables save
service iptables restart
nginx 命令:
service nginx start # 启动Nginx服务
service nginx stop # 停止Nginx服务
服务开启后输入服务器地址会出现:
查看nginx目录:
find / -name nginx
配置开机启动:
vim /etc/rc.d/rc.local
# nginx 启动
/usr/local/nginx/sbin/nginx
# 赋予执行权限
chmod 755 /etc/rc.d/rc.local
快速启动脚本:
《1》编辑文件
vim /usr/bin/nginx
《2》复制代码进去
#然后将下面代码复制进去
#!/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/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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
killall -9 nginx
}
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
《3》添加执行权限
chmod 755 nginx
《4》然后就可以在任意目录下
nginx start #启动
nginx stop #停止
nginx status
nginx restart
修改nginx 默认站点目录
修改配置文件
/etc/nginx/conf.d/default.conf
将红框中修改为自己想要的站点目录
然后重启 nginx 服务
如果此时页面为403则是自定义站点目录没有访问权限
修改文件夹权限
chmod -R 755 目标文件夹路径
然后重启 nginx 服务
但是 nginx自带 selinux 安全系统,如果你不懂得如何设置它关闭它吧
#查看是否开启
方法1:
/usr/sbin/sestatus
方法2:
getenforce
setenforce 0 #临时关闭(重启后无效)
#永久关闭
vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
#重启后生效
reboot
关闭状态