Centos 7 PHP7+PHP5.6+NGINX+MYSQL+FTP

Centos 7 PHP7+PHP5.6+NGINX+MYSQL+FTP

一、PHP安裝

1、wget  http://cn2.php.net/distributions/php-7.0.13.tar.gz

2、yum install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel curl-devel libxslt-devel openssl-devel openssl libmcrypt

3、./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-msyql --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --with-zlib-dir --with-mhash --with-mcrypt-dir --with-openssl-dir --with-jpeg-dir --enable-gd-jis-conv --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip

4、make && make install

5 、cp php.ini-production /usr/local/php7/etc/php.ini  

6、cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

7、cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

8、cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

9、加入服務
    chmod +x /etc/init.d/php-fpm
    chkconfig --add php-fpm
    啓動
    /etc/init.d/php-fpm start
10、/usr/local/php7/bin/php -v

二、NGINX安裝

1、wget http://nginx.org/download/nginx-1.8.0.tar.gz

2、tar -zxvf nginx-1.8.0.tar.gz

3、 yum install pcre*
    yum install openssl*
    yum install zlib 
    yum install zlib-devel
    yum install wget

4、cd nginx-1.8.0
./configure --prefix=/usr/local/nginx-1.8.0

5、make && make install

6、./sbin/nginx

7、./sbin/nginx -s stop

8、nginx加入服務

原地址:http://blog.sina.com.cn/s/blog_a51d7b7a0102v0c2.html

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx-1.10.0/conf/nginx.conf
# pidfile:     /usr/local/nginx-1.10.0/logs/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.10.0/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx-1.10.0/conf/nginx.conf"

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
}

restart() {
    configtest || return $?
    stop
    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

9、chmod a+x /etc/init.d/nginx

10、chkconfig --add nginx          chkconfig nginx on

三、NGINX配置

  location / {
        root   /www;
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        root           /www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

四、多版本PHP配置

原文:http://www.lnmp.cn/multiple-php-versions-under-lnmp.html

1、[root@lnmp php-5.6.21]# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
[root@lnmp php-5.6.21]# vim /usr/local/php5/etc/php-fpm.conf

2、查找 listen 將
listen = 127.0.0.1:9000
改成
listen = 127.0.0.1:9001

3、配置 php-fpm 服務

因爲 PHP 7 的服務文件爲 php-fpm.service 所以這裏用 php5-fpm.service
[root@lnmp php-5.6.21]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php5-fpm.service
[root@lnmp php-5.6.21]# vim /usr/lib/systemd/system/php5-fpm.service
將:
PIDFile=${prefix}/var/run/php-fpm.pid
ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf
改成
PIDFile=/usr/local/php5/var/run/php-fpm.pid
ExecStart=/usr/local/php5/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php5/etc/php-fpm.conf
這裏做的就是用剛纔 PHP 5 安裝路徑替代 prefix 變量
重新載入 systemd
[root@lnmp php-5.6.21]# systemctl daemon-reload

4、systemctl start php5-fpm

5、配置不同的 nginx 站點使用不用的 PHP 版本

一、爲網站創建一個目錄:
[root@lnmp php-5.6.21]# mkdir -p /www/dev.lnmp.cn

二、創建 phpinfo 文件
[root@lnmp php-5.6.21]# vim /www/dev.lnmp.cn/phpinfo.php

三、輸入,並保存:
<?php
phpinfo();

四、創建 nginx 站點配置文件
[root@lnmp php-5.6.21]# cd /etc/nginx/conf.d/
[root@lnmp conf.d]# vim dev.lnmp.cn.conf
輸入,並且保存:
server {
    listen       80;
    server_name  dev.lnmp.cn;
    root         /www/dev.lnmp.cn;
    location / {
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

五、MYSQL

yum install mysql

六、ftp配置

原文地址:http://www.osyunwei.com/archives/9006.html

1、關閉firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
2、安裝iptables防火牆
yum install iptables-services #安裝
vi /etc/sysconfig/iptables #編輯防火牆配置文件
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10060:10090 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
systemctl restart iptables.service #最後重啓防火牆使配置生效
systemctl enable iptables.service #設置防火牆開機啓動
說明:21端口是ftp服務端口;10060到10090是Vsftpd被動模式需要的端口,可自定義一段大於1024的tcp端口。
系統運維  www.osyunwei.com  溫馨提醒:qihang01原創內容©版權所有,轉載請註明出處及原文鏈接

二、關閉SELINUX

vi /etc/selinux/config
#SELINUX=enforcing #註釋掉
#SELINUXTYPE=targeted #註釋掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效

三、安裝vsftpd

yum install -y vsftpd #安裝vsftpd
yum install -y psmisc net-tools systemd-devel libdb-devel perl-DBI  #安裝vsftpd虛擬用戶配置依賴包
systemctl start vsftpd.service #啓動
systemctl enable vsftpd.service #設置vsftpd開機啓動

四、配置vsftp服務器

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak #備份默認配置文件
執行以下命令進行設置
sed -i "s/anonymous_enable=YES/anonymous_enable=NO/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#anon_upload_enable=YES/anon_upload_enable=NO/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#chown_uploads=YES/chown_uploads=NO/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#async_abor_enable=YES/async_abor_enable=YES/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#ascii_upload_enable=YES/ascii_upload_enable=YES/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#ascii_download_enable=YES/ascii_download_enable=YES/g" '/etc/vsftpd/vsftpd.conf'
sed -i "s/#ftpd_banner=Welcome to blah FTP service./ftpd_banner=Welcome to FTP service./g" '/etc/vsftpd/vsftpd.conf'
echo -e "use_localtime=YES\nlisten_port=21\nchroot_local_user=YES\nidle_session_timeout=300
\ndata_connection_timeout=1\nguest_enable=YES\nguest_username=vsftpd
\nuser_config_dir=/etc/vsftpd/vconf\nvirtual_use_local_privs=YES
\npasv_min_port=10060\npasv_max_port=10090
\naccept_timeout=5\nconnect_timeout=1" >> /etc/vsftpd/vsftpd.conf

五、建立虛擬用戶名單文件

touch /etc/vsftpd/virtusers
編輯虛擬用戶名單文件:(第一行賬號,第二行密碼,注意:不能使用root做用戶名,系統保留)
vi /etc/vsftpd/virtusers
web1
123456
web2
123456
web3
123456
:wq! #保存退出

六、生成虛擬用戶數據文件

db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
chmod 600 /etc/vsftpd/virtusers.db #設定PAM驗證文件,並指定對虛擬用戶數據庫文件進行讀取

七、在/etc/pam.d/vsftpd的文件頭部加入以下信息(在後面加入無效)

修改前先備份 cp /etc/pam.d/vsftpd /etc/pam.d/vsftpdbak
vi /etc/pam.d/vsftpd
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers
注意:如果系統爲32位,上面改爲lib,否則配置失敗

八、新建系統用戶vsftpd,用戶目錄爲/home/wwwroot, 用戶登錄終端設爲/bin/false(即使之不能登錄系統)

useradd vsftpd -d /home/wwwroot -s /bin/false
chown vsftpd:vsftpd /home/wwwroot -R
chown www:www /home/wwwroot -R #如果虛擬用戶的宿主用戶爲www,需要這樣設置。

九、建立虛擬用戶個人Vsftp的配置文件

mkdir /etc/vsftpd/vconf
cd /etc/vsftpd/vconf
touch web1 web2 web3 #這裏創建三個虛擬用戶配置文件
mkdir -p /home/wwwroot/web1/http/
vi web1 #編輯用戶web1配置文件,其他的跟這個配置文件類似
local_root=/home/wwwroot/web1/http/
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
allow_writeable_chroot=YES
十、最後重啓vsftpd服務器
systemctl restart vsftpd.service
備註:
guest_username=vsftpd #指定虛擬用戶的宿主用戶(就是我們前面新建的用戶)
guest_username=www #如果ftp目錄是指向網站根目錄,用來上傳網站程序,可以指定虛擬用戶的宿主用戶爲nginx運行賬戶www,可以避免很多權限設置問題

至此,CentOS 7.0安裝配置Vsftp服務器配置完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章