檢查更新:
[[email protected]****z ~]# yum check-update
安裝gcc gcc-c++:
[[email protected]****z ~]# yum -y install gcc gcc-c++
安裝依賴包:
[[email protected]****z ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
[[email protected]****z ~]# yum -y install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel
[[email protected]****z ~]# yum -y install libcurl libcurl-devel libedit libedit-devel libmcrypt libmcrypt-devel
[[email protected]****z ~]# yum -y install libxslt libxslt-devel
[[email protected]****z ~]# yum -y install freetype freetype-devel bison bison-devel
[[email protected]****z ~]# yum -y install mhash mhash-devel bzip2 bzip2-devel jemalloc jemalloc-devel
[[email protected]****z ~]# yum -y install readline readline-devel sqlite sqlite-devel
[[email protected]****z ~]# yum -y install epel-release unzip vsftpd
安裝MariaDB
https://blog.csdn.net/qq_21326433/article/details/82794364
1、安裝nginx
1.1 建立用來運作nginx的組及使用者
[[email protected]****z ~]# groupadd nginx
[[email protected]****z ~]# useradd -g nginx -M nginx -s /sbin/nologin
# -g:為nginx使用者指定一個組 -M:保證其不自動生成home目錄
1.2 建立安裝目錄并進入此目錄
[[email protected]****z ~]# mkdir /usr/local/nginx
[[email protected]****z ~]# cd /usr/local/nginx/
1.3 下載下傳并解壓nginx源碼包 nginx下載下傳官網
[[email protected]****z nginx]# wget http://nginx.org/download/nginx-1.15.0.tar.gz
[[email protected]****z nginx]# tar zxvf nginx-1.15.0.tar.gz
# 解壓後進入檔案夾
[[email protected]****z nginx]# cd nginx-1.15.0
1.4 執行配置指令
[[email protected]****z nginx-1.15.0]# ./configure --prefix=/usr/local/nginx \
--with-http_ssl_module
checking for OS
+ Linux 3.10.0-514.26.2.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
checking for gcc -pipe switch ... found
******************
省略中間資料
******************
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/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"
[[email protected]****z nginx-1.15.0]#
1.5 完成編譯工作:
[[email protected]****z nginx-1.15.0]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx/nginx-1.15.0'
******************
省略中間資料
******************
make[1]: Leaving directory `/usr/local/nginx/nginx-1.15.0'
[[email protected]****z nginx-1.15.0]#
1.6 配置nginx自啟動腳本,輸入以下内容,然後儲存退出
[[email protected]****z nginx-1.15.0]# vim /etc/init.d/nginx
#!/bin/bash
# nginx This shell script takes care of starting and stopping
# nginx
#
# chkconfig: - 13 68
# description: nginx is a web server
### BEGIN INIT INFO
# Provides: $named
# Short-Description: start|stop|status|restart|configtest
### END INIT INFO
#variables
NGINX_BIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
NETSTAT="/bin/netstat"
alter=$1
prog=nginx
#load system function
. /etc/rc.d/init.d/functions
#function:echo ok or error
function if_no {
if [ $2 == 0 ]; then
echo -n $"$1 ${prog}:" && success && echo
else
echo -n $"$1 ${prog}:" && failure && echo
fi
}
#start nginx
function start {
rm -f ${NGINX_PID} 2>/dev/null
if [ -s ${NGINX_PID} ]; then
echo "nginx already running"
else
if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; then
rm -f ${NGINX_PID} 2>/dev/null
${NGINX_BIN} -c ${NGINX_CONF}
if_no start $?
else
${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1 > ${NGINX_PID}
if_no start $?
fi
fi
}
#stp nginx
function stop {
if [ -s ${NGINX_PID} ]; then
cat ${NGINX_PID} | xargs kill -QUIT
if_no stop $?
else
if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; then
rm -f ${NGINX_PID} 2>/dev/null
if_no stop 0
else
rm -f ${NGINX_PID} 2>/dev/null
kill `${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1`
if_no stop $?
fi
fi
}
function restart {
if [ -s ${NGINX_PID} ]; then
cat ${NGINX_PID} | xargs kill -HUP
if_no restart $?
else
stop
sleep 1
start
fi
}
function status {
${NETSTAT} -tnpl | grep nginx | grep LISTEN
[ $? == 0 ] && echo "nginx is running" || echo "nginx is not running"
}
function configtest {
${NGINX_BIN} -t
}
case $alter in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
configtest)
configtest
;;
*)
echo "use:${NGINX} {start|stop|restart|status|configtest}"
;;
esac
1.7 給與使用者操作權限
[[email protected]****z nginx-1.15.0]# chmod +x /etc/init.d/nginx
1.8 啟動nginx
[[email protected]****z nginx-1.15.0]# service nginx start
Reloading systemd: [ OK ]
Starting nginx (via systemctl): [ OK ]
[[email protected]****z nginx-1.15.0]#
1.9 檢視nginx狀态
[[email protected]****z nginx-1.15.0]# systemctl status nginx.service
● nginx.service - LSB: start|stop|status|restart|configtest
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: active (running) since Mon 2018-09-17 15:47:20 CST; 2min 12s ago
Docs: man:systemd-sysv-generator(8)
Process: 11258 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nginx.service
├─11266 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
└─11267 nginx: worker process
Sep 17 15:47:20 i****z systemd[1]: Starting LSB: start|stop|status|restart|configtest...
Sep 17 15:47:20 i****z nginx[11258]: start nginx:[ OK ]
Sep 17 15:47:20 i****z systemd[1]: Started LSB: start|stop|status|restart|configtest.
[[email protected]****z nginx-1.15.0]#
1.10 設定開機啟動
[[email protected]****z nginx-1.15.0]# chkconfig --add nginx
[[email protected]****z nginx-1.15.0]# chkconfig --level 2345 nginx on
1.11 重新開機伺服器檢查是否設定成功
[[email protected]****z nginx-1.15.0]# reboot
[[email protected]****z ~]# systemctl status nginx.service
● nginx.service - LSB: start|stop|status|restart|configtest
Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
Active: active (running) since Mon 2018-09-17 15:53:33 CST; 34s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/nginx.service
├─874 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
└─881 nginx: worker process
Sep 17 15:53:33 i****z systemd[1]: Starting LSB: start|stop|status|restart|configtest...
Sep 17 15:53:33 i****z nginx[785]: start nginx:[ OK ]
Sep 17 15:53:33 i****z systemd[1]: Started LSB: start|stop|status|restart|configtest.
[[email protected]****z ~]#
1.12 nginx安裝完成,通過浏覽器輸入伺服器IP位址檢測
2、安裝php
2.1 建立PHP安裝目錄并進入此目錄
[[email protected]****z ~]# mkdir /usr/local/php
[[email protected]****z ~]# cd /usr/local/php/
[[email protected]****z php]#
2.2 下載下傳解壓php源碼包并進入檔案目錄 PHP下載下傳官網
[[email protected]****z php]# wget -O php-7.0.32.tar.gz http://cn2.php.net/get/php-7.0.32.tar.gz/from/this/mirror
[[email protected]****z php]# tar zxvf php-7.0.32.tar.gz
[[email protected]****z php]# cd php-7.0.32
2.3 執行配置指令。注:‘\’ 後面不能有空格
[[email protected]****Z php-7.0.32]# ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-php-config=/usr/local/php/bin/php-config \
--disable-rpath \
--disable-debug \
--disable-fileinfo \
--enable-shared \
--enable-opcache \
--enable-inline-optimization \
--enable-fpm \
--enable-mbstring \
--enable-bcmath \
--enable-soap \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--enable-zip \
--enable-gd-native-ttf \
--with-curl \
--with-zlib \
--with-bz2 \
--with-iconv-dir \
--with-mcrypt \
--with-mhash \
--with-openssl \
--with-libxml-dir \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mysql \
--with-mysqli \
--with-mysql-sock \
--with-pdo-mysql \
--with-pear \
--with-gettext \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--with-freetype-dir= \
--with-xmlrpc \
--with-readline
# 上面為要輸入的内容
# 下面為配置結束部分内容
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-php-config, --with-mysql
[[email protected]****Z php-7.0.32]#
2.4 完成編譯工作:
[[email protected]****Z php-7.0.32]# make && make install
******************
省略中間資料
******************
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM defconfig: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/php/php-7.0.32/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
[[email protected]****Z php-7.0.32]#
2.5 配置檔案
[[email protected]****Z php-7.0.32]# cp php.ini-development /usr/local/php/etc/php.ini
[[email protected]****Z php-7.0.32]# vim /usr/local/php/etc/php.ini
# 修改内容根據自己需求設定
# 例如
# upload_tmp_dir = "/usr/local/php/tmp"
# upload_max_filesize = 20M
# date.timezone = "Asia/Shanghai"
# session.save_path = "/usr/local/php/tmp"
# soap.wsdl_cache_dir="/usr/local/php/tmp"
# 建立緩存目錄
[[email protected]****Z php-7.0.32]# mkdir /usr/local/php/tmp
[[email protected]****Z php-7.0.32]# chmod -R 755 /usr/local/php/tmp/
2.6 配置php-fpm服務
[[email protected]****Z php-7.0.32]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[[email protected]****Z php-7.0.32]# vim /usr/local/php/etc/php-fpm.conf
# 取消前面的分号
pid = run/php-fpm.pid
[[email protected]****Z php-7.0.32]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[[email protected]****Z php-7.0.32]# vim /usr/local/php/etc/php-fpm.d/www.conf
# 設定php-fpm運作賬号群組為nginx
user = nginx
group = nginx
# 監聽端口
listen = 127.0.0.1:9000
2.7 配置php啟動腳本,輸入以下内容,儲存退出
[r[email protected]****Z php-7.0.32]# vim /etc/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
2.8 啟動php-fpm服務
[[email protected]****Z php-7.0.32]# systemctl start php-fpm.service
# 檢視程序
[[email protected]****Z php-7.0.32]# netstat -utnlp | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3629/php-fpm: pool
2.9 配置php-fpm開機啟動
[[email protected]****Z php-7.0.32]# vim /etc/init.d/php-fpm
# 拷貝下面一個代碼框的内容
# 設定檔案權限
[[email protected]****Z php-7.0.32]# chmod -R 755 /etc/init.d/php-fpm
# 添加到開機啟動項
[[email protected]****Z php-7.0.32]# chkconfig --add /etc/init.d/php-fpm
[[email protected]****Z php-7.0.32]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /etc/systemd/system/php-fpm.service.
# 啟動php-fpm
[[email protected]****Z php-7.0.32]# service php-fpm start
Starting php-fpm (via systemctl): [ OK ]
#!/bin/sh
# chkconfig: 2345 15 95
# description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
# with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
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 ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
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
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
2.10 配置nginx多站點及支援php
[[email protected]****Z php-7.0.32]# vim /usr/local/nginx/conf/nginx.conf
将 #user nobody; 修改為 user nginx nginx;
将 #error_log logs/error.log; 修改為 error_log logs/error.log;
# 修改Nginx運作組為nginx nginx;
# 必須與/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否則php運作出錯
# 開啟nginx錯誤日志,日志檔案位置:/uer/local/nginx/logs/
# 包含域名配置檔案(支援通配符)
# 在#gzip on; 後面添加下面一行代碼
# 屏蔽後面所有内容(修改内容在http{}中,是以最後一個‘}’不能屏蔽掉)
include /usr/local/nginx/vhost/*.conf;
2.11 配置虛拟主機公用配置檔案server.conf
[[email protected]****Z php-7.0.32]# vim /usr/local/nginx/conf/server.conf
# php檔案通路配置
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# 靜态檔案緩存30天
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
# js,css檔案緩存15個小時
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
2.12 配置虛拟主機檔案,内容根據自己需求更改
[[email protected]****Z php-7.0.32]# mkdir /usr/local/nginx/vhost
[[email protected]****Z php-7.0.32]# vim /usr/local/nginx/vhost/test.conf
server {
listen 80;
# 配置域名
server_name www.test.com test.com;
# 配置網站目錄
root /home/www/test;
# 配置域名重定向
if ($host != "www.test.com") {
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
location / {
# 配置rewrite url重寫,架構必須
#if (!-e $request_filename) {
# rewrite ^(.*)$ /index.php?s=$1 last;
# break;
#}
# rewrite ^/(.+)/(.+)[/]?$ /index.php?m=$1&a=$2 last;
# 配置預設通路檔案
index index.php index.html index.htm;
}
# 包含虛拟主機公用配置檔案
include server.conf;
}
2.13 建立網站目錄,修改目錄權限、所屬使用者群組
[[email protected]****Z php-7.0.32]# mkdir -p /home/www/test
[[email protected]****Z php-7.0.32]# chmod -R 777 /home/www/test/
[[email protected]****Z php-7.0.32]# chown -R nginx:nginx /home/www/test/
2.14 重新開機nginx
[[email protected]****Z php-7.0.32]# systemctl restart nginx
2.15 添加到環境變量
[[email protected]****Z php-7.0.32]# vim /etc/profile
# 檔案尾添加下面兩行
PATH=$PATH:/usr/local/php/bin
export PATH
# 儲存退出
# 執行指令使其修改生效
[[email protected]****z php-7.0.32]# source /etc/profile
# 檢測,任意目錄
[[email protected]****z ~]# php -v
PHP 7.0.32 (cli) (built: Sep 17 2018 18:10:31) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
[[email protected]****z ~]#
2.16 添加測試檔案
[[email protected]****Z ~]# vim /home/www/test/index.html
# 輸入内容
test html
[[email protected]****Z ~]# vim /home/www/test/index.php
# 輸入内容
<?php
echo phpinfo();
2.17 通過浏覽器檢測是否能夠通路成功