用的是lnmp 一鍵安裝的 php5.6版本網上百度Ubuntu安裝多版本PHP就行
參考文章原鏈接:http://blog.csdn.net/21aspnet/article/details/47658127 1.首先不用去修改原來的已經安裝好的php 2.先下載你要安裝的另外一個版本的php壓縮包 3.tar zxvf ...解壓壓縮包 4. 執行當前目錄下的configure文件 ./configure --prefix=/opt/modules/php5.4 --with-mysql -with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-ftp --enable-soap --enable-sockets --enable-zip --with-libdir=lib64 其中要注意的是安裝路徑.--prefix 這里以安裝php5.4為例,我們打算把它安裝到目錄 /opt/modules/php5.4,於是在php5.4目錄執行帶選項的腳本./configure --prefix=/opt/modules/php5.4,執行成功后再編譯、安裝(make,make install);安裝完成將自動生成目錄php5.4,而且該軟件所有的文件都被復制到這個目錄。為什么要指定這個安裝目錄?是為了以后的維護方便,如果沒有用這個選項,安裝過程結束后,該軟件所需的軟件被復制到不同的系統目錄下,很難弄清楚到底復制了那些文件、都復制到哪里去了—基本上是一塌糊塗。 用了—prefix選項的另一個好處是卸載軟件或移植軟件。當某個安裝的軟件不再需要時,只須簡單的刪除該安裝目錄,就可以把軟件卸載得干干凈凈;移植軟件只需拷貝整個目錄到另外一個機器即可(相同的操作系統)。 5.然后make makeinstall 6.將解壓包里的這三個文件分別復制到對應的文件目錄下: cp -R ./sapi/fpm/php-fpm.conf /opt/modules/php5.4/etc/php-fpm.conf cp php.ini-development /opt/modules/php5.4/lib/php.ini cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm5.4 7.修改php-fpm.conf的偵聽端口為9001(此處應該修改/opt/modules/php5.4/etc/php-fpm.conf),因為主版本5.2.17是偵聽9000。 8.啟動php-fpm /etc/init.d/php-fpm5.4 9.php安裝成功查看進程 ps aux|grep php 這樣就已經起好php-fpm了. 10.重啟nginx /usr/local/nginx/sbin/nginx -s reload 或者/etc/init.d/nginx restart 11.然后配置文件. 如果你的配置文件是用的nginx/vhosts下面的具體文件配置. server { listen 80; server_name newweb.my; root /home/wwwroot/papersvn/newci/web; index index.php index.shtml index.html index.htm; access_log /home/weblogs/jingpin.log for_cookie; error_log /home/weblogs/jingpinerror.log; location ~ \.php$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } location ~* /(css|js|img) { expires 12h; break; } if (!-f $request_filename) { rewrite ^/$ /index.php last; rewrite ^/(?!(index\.php|public|app|third_party|favicon\.ico|32-favicon\.ico))(.*)$ /index.php?$1$2 last; rewrite ^/index.php(.*)$ /index.php?$1 last; break; } } 其他配置項基本不變,需要把php配置fastcgi_pass改成127.0.0.1:9001,調用9001接口. 測試是否成功,查看phpinfo()
下面這里是對於lnmp的配置
lnmp的vhost php7的配置如下:
server { listen 80; #listen [::]:80; server_name wordpass.my wordpass; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/wordpass/wordpress; include other.conf; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php.conf; //這個里面配置了 php的啟動和一些配置路徑 PHP7用的是cgi的 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/wordpass.my.log; } ~
include enable-php.conf 如果使用php5.6的 htpp模式啟動
在/usr/local/nginx/conf/創建一個enable-php5.conf(自己命名)
配置如下:
PHP5.6--------
location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass 127.0.0.1:9001; //這里是PHP5.6的 http模式 fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; }
這里是php7的
location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } ~ ~
Vhost里面引用
server { listen 80; #listen [::]:80; server_name dede.my dedes; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/zhi/de/uploads; include other.conf; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php5.conf; //引用的5.6 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/dede.my.log; }