开机启动:
CentOS7执行
chmod +x /etc/rc.d/rc.local
然后vi /etc/rc.d/rc.local
加入以下内容
/usr/local/nginx-1.11.10/sbin/nginx &
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
需要的包:http://download.csdn.net/detail/u011513939/9801791
php7+nginx编译后的包 http://download.csdn.net/detail/u011513939/9802684
前言:解决CentOS7 下面没有iptabls:
centos从7开始默认用的是firewalld,这个是基于iptables的,虽然有iptables的核心,但是iptables的服务是没安装的。所以你只要停止firewalld服务即可:
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service
如果你要改用iptables的话,需要安装iptables服务:
sudo yum install iptables-services
sudo systemctl enable iptables && sudo systemctl enable ip6tables
sudo systemctl start iptables && sudo systemctl start ip6tables
创建目录:
mkdir -p /usr/local/src
cd /usr/local/src
上传或者下载ncurses-5.6.tar.g包:下载的有点慢
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure -prefix=/usr/local -with-shared -without-debug
make
make install
nginx-1.11.10.tar 上传到 /usr/local/src 目录下面
wget http://nginx.org/download/nginx-1.11.10.tar.gz
安装nginx
yum install pcre-devel zlib-devel
cd /usr/local/src
mv nginx-1.11.10 ../
cd ..
cd nginx-1.11.10
./configure --prefix=/usr/local/nginx-1.11.10
make && make install && make clean
cd /usr/local/nginx-1.11.10/sbin/
./nginx -c /usr/local/nginx-1.11.10/conf/nginx.conf
cd /usr/local/nginx-1.11.10/logs
touch nginx.pid
nginx 配置环 境变量
vi /etc/profile
/usr/local/nginx-1.11.10/sbin
source /etc/profile
平滑启动nginx
/usr/local/nginx-1.11.10/sbin/nginx -s reload
正常启动nginx
/usr/local/nginx-1.11.10/sbin/nginx &
然后浏览器就可以看到nginx的环境页面了
nginx 开机启动
vi /etc/init.d/nginx
在脚本中添加以下内容
#!/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-1.11.10/sbin"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx-1.11.10/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:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
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
}
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/local/nginx-1.11.10/sbin” 修改成nginx执行程序的路径。
NGINX_CONF_FILE=”/usr/local/nginx-1.11.10/conf” 修改成配置文件的路径。
保存脚本文件后设置文件的执行权限:
chmod a+x /etc/init.d/nginx
然后,就可以通过该脚本对nginx服务进行管理了:
/etc/init.d/nginx start
/etc/init.d/nginx stop
先将nginx服务加入chkconfig管理列表:
chkconfig --add /etc/init.d/nginx
加完这个之后,就可以使用service对nginx进行启动,重启等操作了。
service nginx start
service nginx stop
设置终端模式开机启动:
chkconfig nginx on
不用执行:参考 vi /etc/rc.local su - root -c
‘/usr/local/nginx-1.11.10/sbin/nginx &’
测试开机启动
reboot
1:上传 libxml2-2.9.3.tar.gz到/usr/local/src目录下
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.3.tar.gz
tar -zxvf libxml2-2.9.3.tar.gz
cd libxml2-2.9.3
./configure --prefix=/usr/local/libxml2 --with-python=no
make
make install
这里–with-python=no是
安装php
上传 php-7.1.2.tar.gz到/usr/local/src目录下
wget http://cn2.php.net/distributions/php-7.1.2.tar.gz
yum install libxml2 libxml2-devel openssl-devel bzip2-devel libcurl-devel enchant enchant-devel libpng-devel gmp-devel libc-client libc-client-devel pam-devel firebird-devel libicu-devel openldap openldap-devel libmcrypt-devel unixODBC-devel freetds freetds-devel
tar -zxvf php-7.1.2.tar.gz
cd php-7.1.2
./configure –prefix=/usr/local/php –with-libxml-dir=/usr/local/libxml2 –with-config-file-path=/usr/local/php/etc –enable-mbstring –enable-fpm –with-xml –with-curl –with-mbstring –with-mysql –with-pdo-mysql –with-mcrypt –with-mysqli
make
make install
开始配置(php-fpm)
cd /usr/local/src/php-7.1.2
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
运行php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
php 加入环境变量中:
vi /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
source /etc/profile
然后输入 php-v
可以看到php的环境
配置虚拟机
cd /usr/local/nginx-1.11.10/conf
mkdir vhosts
vim nginx.conf
最后一个}前增加如下
include /usr/local/nginx-1.11.10/conf/vhosts/*.conf;
增加virtual host
vi vhosts/myhost.com.conf
myhost.com.conf内容如下:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#转发静态html文件
location / {
root /usr/local/webapps/myhost.com/;
index index.html index.htm;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
#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
#转发php的请求
location ~ \.php$ {
root /usr/local/webapps/myhost.com/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
创建目录:
mkdir -p /usr/local/webapps/myhost.com
测试:
cd /usr/local/webapps/myhost.com
vi index.html
内容如下:
myhost.com 测试
vi index.php
内容如下:
phpinfo();
重启nginx
/usr/local/nginx-1.11.10/sbin/nginx -s reload
显示index.html中内容
curl http://localhost/index.html
显示php相关环境配置信息
curl http://localhost/index.php
也可在浏览器中访问