php下載網(wǎng)站:http://cn2.php.net/downloads.php
選擇你需要的版本.
首先ssh連接遠(yuǎn)程服務(wù)器,
在/usr/local/下創(chuàng)建php文件:
cd /usr/local/
創(chuàng)建source文件夾,專門用作下載包路徑.
mkdir source
創(chuàng)建php安裝路徑
mkdir php
進(jìn)入下載文件夾:
cd source/
下載包:
wget http://cn2.php.net/distributions/php-7.2.6.tar.gz
解壓(當(dāng)前目錄):
tar -zxvf php-7.2.6.tar.gz
查看解壓文件夾,并進(jìn)入
ls
php-7.2.6 php-7.2.6.tar.gz
移動(dòng)php-7.2.6文件夾內(nèi)文件到php里:
mv php-7.2.6/* /usr/local/php/
進(jìn)入待安裝目錄php
cd /usr/local/php/
經(jīng)過上面步驟基本上完成了下載文件,創(chuàng)建安裝目錄等操作.接下來需要做的是:
1 : 配置PHP安裝需要的環(huán)境
2 : 初始化并安裝PHP
配置PHP安裝需要的環(huán)境:
逐個(gè) 執(zhí)行下面命令,不要遺漏,也不要嫌麻煩:
yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel
yum install gcc
執(zhí)行配置(注意: 下面命令很長(zhǎng),是一行,復(fù)制時(shí)不要有換行):
./configure --prefix=/usr/local/php --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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
一段時(shí)間后執(zhí)行編譯:
make
編譯 時(shí)間比較長(zhǎng),耐心等待,
后執(zhí)行安裝:
make install
安裝成功以后,接下來配置php-fpm:
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
設(shè)置權(quán)限:
chmod +x /etc/init.d/php-fpm
配置環(huán)境變量:
vim /etc/profile
在末尾追加:
PATH=$PATH:/usr/local/php/bin
export PATH
執(zhí)行命令使得改動(dòng)立即生效:
source /etc/profile
創(chuàng)建web用戶及組(名稱自己定,這里假設(shè)是www-data):
groupadd www-data
useradd -g www-data www-data
配置nginx,不然無法識(shí)別PHP文件:
(根據(jù)你自己安裝nginx的目錄)
vim /usr/local/nginx/conf/nginx.conf
需要修改的幾個(gè)點(diǎn):
1 : root 路徑是否修改,如果有需要改下
2 : 啟動(dòng)文件 添加index.php的支持
3 : 開啟PHP配置, 如果需要https,在server里也要設(shè)置:
4 : 假設(shè)把網(wǎng)頁(yè)存放路徑設(shè)置為/home/www
5: 第一行用戶改下
6 : HTTPS server : 這塊根據(jù)需要https配置,否則https下打開PHP文件就是直接下載了
7 : fastcgi_param SCRIPT_FILENAME 后面修改為網(wǎng)頁(yè)根路徑
設(shè)置完成的nginx.conf 應(yīng)該像下面這樣:
user www-data;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/www;
index index.html index.php 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 /home/www;
}
# 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
#
location ~ \.php$ {
root /home/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name;
include fastcgi_params;
# include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl on;
ssl_certificate cert/1527654392270.pem;
ssl_certificate_key cert/1527654392270.key;
root /home/www;
# ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
location / {
root /home/www;
index index.html index.php index.htm;
}
location ~ .*\.(php|php7)?$ {
root /home/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#
fastcgi_param HTTPS on;
fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name;
include fastcgi_params;
}
}
}
配置完成以后:
啟動(dòng)php-fpm:
/etc/init.d/php-fpm start
如果已經(jīng)啟動(dòng),報(bào)錯(cuò)的話,需要?dú)⒌暨M(jìn)程再執(zhí)行:
unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
查看進(jìn)程():
netstat -nldp |grep 9000
返回信息:
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 20016/php-fpm: mast
殺掉進(jìn)程():
kill 20016
再次啟動(dòng)(成功返回done):
/etc/init.d/php-fpm start
添加啟動(dòng)項(xiàng):
chkconfig --add php-fpm
開啟3,4,5:
chkconfig php-fpm --level 345 on
重新啟動(dòng)php-fpm:
service php-fpm restart
重新啟動(dòng)nginx (如果失敗往下走):
service nginx restart
重新啟動(dòng)nginx
如果沒有配置的上面命令執(zhí)行會(huì)失敗,使用下面安裝路徑啟動(dòng):
/usr/local/nginx/sbin/nginx -s reload
到此差不多完成,最后一步:添加測(cè)試文件
用ftp在網(wǎng)站根路徑下添加test.php
/home/www/test.php
文件信息:
<?php
phpinfo();
?>
然后再網(wǎng)站打開鏈接:
http://xxxxxxx/test.php
或者
https://xxxxxxx/test.php