centos7 安装php5.6.0 、nginx1.7.4、phpssdbadmin

1 创建用户、网站目录和下载相关的安装包
  groupadd www #添加www组

创建目录/data/www/

chown www:www /data/www/ -R #设置目录所有者

chmod 700 /data/www -R #设置目录权限

useradd -g www www -s /bin/false #创建nginx运行账户www并加入到www组,不允许www用户直接登录系统

下载:libmcrypt-2.5.8.tar.gz、php-5.6.0.tar.gz 、nginx-1.7.4.tar.gz、openssl-1.0.1i.tar.gz、pcre-8.35.tar.gz、zlib-1.2.8.tar.gz 并复制到 /usr/local/ 目录

2 安装php5.6.0

添加依赖应用
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

安装加密扩展库

cd /usr/local/
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install

cd /usr/local/
tar zxvf php-5.6.0.tar.gz
cd php-5.6.0
./configure --prefix=/usr/local/php --enable-fasecgi --enable-fpm --with-ncurses --enable-soap --with-libxml-dir --with-XMLrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --with-pear
make && make install

cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除系统自带配置文件
ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加软链接
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件

vi /usr/local/php/etc/php-fpm.conf #编辑修改
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号

设置 php-fpm开机启动

cp /usr/local/php-5.6.0/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
添加到自启动# echo "/etc/rc.d/init.d/php-fpm start">>/etc/rc.local
chkconfig php-fpm on #设置开机启动

3 安装nginx-1.7.4

zlib:主要用于支持将http内容进行gzip压缩,用于减少网络传输流量
cd /usr/local #选定安装的目录
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install

pcre:用于支持nginx的正则表达式,配置文件中都需要用到正则表达式
cd /usr/local
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make
make install

openssl:用于nginx支持https请求
cd /usr/local
wget http://www.openssl.org/source/openssl-1.0.1i.tar.gz
tar -zxvf openssl-1.0.1i.tar.gz
cd openssl-1.0.1i
./configure
make
make install

cd /usr/local
tar -zxvf nginx-1.7.4.tar.gz
cd nginx-1.7.4
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.35 --with-zlib=/usr/local/zlib-1.2.8 --with-openssl=/usr/local/openssl-1.0.1i
make
make install

修改/usr/local/nginx/conf/nginx.conf

user  www www;
worker_processes  2;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid        /var/run/nginx.pid; #修改
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       8090;
        server_name  localhost;
       index index.php index.html index.htm;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   /data/www;
            index  index.html index.htm;
        }
        #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;
        }
    #添加ssdb web   location
/phpssdbadmin {   root /data/www; try_files $uri $uri/ /phpssdbadmin/index.php?$args;   } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /data/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }

手动管理: 

启动: /usr/local/nginx/sbin/nginx
停止:kill -QUIT `cat /var/run/nginx.pid`
重启:kill -HUP `cat /var/run/nginx.pid`

开机自动启动Nginx(通过Shell脚本管理):
vi /etc/init.d/nginx #输入下面的代码并保存退出

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限

chkconfig nginx on #设置开机启动
echo "/etc/rc.d/init.d/nginx start">>/etc/rc.local 

启动服务:
/usr/local/php/sbin/php-fpm start
/etc/rc.d/init.d/nginx start

CentOS 7.0默认使用的是firewall作为防火墙。
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

测试php:
在/data/www/目录下创建test.php

<?php
phpinfo();
?>

浏览器( 注意端口要和配置的一致):http://127.0.0.1:8090/test.php  

 

centos7 安装php5.6.0 、nginx1.7.4、phpssdbadmin_第1张图片

你可能感兴趣的:(centos)