編譯安裝php7
進入如下目錄
cd /usr/local/src php
下載源碼包
wget http://hk2.php.net/distributions/php-7.1.24.tar.gzhtml
解壓
tar -xzvf php-7.1.24.tar.gzmysql
進入解壓後的文件夾
cd php-7.1.24nginx
安裝依賴
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel正則表達式
編譯前配置
./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --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-zipsql
看到下面的提示說明配置成功了
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+vim
Thank you for using PHP.api
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commandsphp7
編譯與安裝
make && make installapp
添加 PHP 命令到環境變量
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php7/bin
export PATH
或
export PATH=$PATH:/usr/local/php7/bin
要使改動當即生效執行
./etc/profile
或
source /etc/profile
查看環境變量
echo $PATH
查看php版本
php -v
配置php-fpm
cp php.ini-production /usr/local/php7/lib/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
啓動php-fpm
/etc/init.d/php-fpm start
配置開機啓動
cd /etc/init.d
vim php7-fpm
文件內容以下
#!/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/php7/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
配置權限
chmod a+x /etc/init.d/php7-fpm
chkconfig --add php7-fpm
chkconfig php7-fpm on
啓動中止服務
service php7-fpm start
service php7-fpm stop
卸載方式
先停掉 php,而後刪除安裝後的目錄便可
配置nginx虛擬機
vim /etc/nginx/conf.d/default.conf
把下面的內容複製到default.conf裏
server{
listen 80;
server_name localhost;
root /www/html; # 該項要修改成你準備存放相關網頁的路徑
index index.php index.html index.htm;
location / {
#若是請求既不是一個文件,也不是一個目錄,則執行一下重寫規則
if (!-e $request_filename)
{
#地址做爲將參數rewrite到index.php上。
rewrite ^/(.*)$ /index.php/$1;
#如果子目錄則使用下面這句,將subdir改爲目錄名稱便可。
#rewrite ^/subdir/(.*)$ /subdir/index.php/$1;
}
}
#proxy the php scripts to php-fpm
location ~ \.php$ {
##pathinfo支持start
#定義變量 $path_info ,用於存放pathinfo信息
set $path_info "";
#定義變量 $real_script_name,用於存放真實地址
set $real_script_name $fastcgi_script_name;
#若是地址與引號內的正則表達式匹配
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
#將文件地址賦值給變量 $real_script_name
set $real_script_name $1;
#將文件地址後的參數賦值給變量 $path_info
set $path_info $2;
}
#配置fastcgi的一些參數
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
###pathinfo支持end
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
location ^~ /data/runtime {
return 404;
}
location ^~ /application {
return 404;
}
location ^~ /simplewind {
return 404;
}
}
檢查nginx配置
nginx -t
重啓nginx nginx -s reload