Linux版 php5.4 升級php7

開篇

本操做是在VirtualBox裏面進行的,因此開篇先說下,本地如何操做VB裏面的Linuxphp

1.secureCRT登錄虛擬機ubuntu

直接鏈接虛擬機的ip (ifconfig)會提示拒絕訪問,是由於未安裝ssh,ssh是telnet的升級,telnet的密碼和信息是不加密的,而ssh是加密。html

安裝sshmysql

sudo apt-get install openssh-server openssh-client

啓動ssh-servernginx

ssh restart

查看ssh-server是否啓動web

netstat -tlp

顯示一下表示成功啓動sql

tcp        0      0 *:ssh                   *:*                     LISTEN      821/sshd        
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      821/sshd 

2.刪除軟件

由於以前安裝過測試的php 因此先卸載掉mongodb

sudo apt autoremove php7.0

3. 獲取root權限

這個是一個謹慎的操做,由於任何管理員均可以使用 sudo root 來獲取root的權限,但有寫入權限或-p 建立目錄,啓動服務等會出問題。ubuntu

獲取root權限:api

sudo passwd
[sudo] currentUser 的密碼: 
輸入新的 UNIX 密碼: 
從新輸入新的 UNIX 密碼: 
passwd:已成功更新密碼

而後:php7

su root

 

下載測試安裝環境

方便期間,咱們使用lnmp快速安裝,(先安裝php5.4)

下載地址:http://soft.vpser.net/lnmp/lnmp1.3-full.tar.gz

tar xzvf lnmp1.3-full.tar.gz
cd lnmp1.3-full
./install.sh

下一步……

完成!

訪問ip查看lnmp環境是否安裝ok

 

升級php至php7

下載最新版php7 (2017-03-16)

下載地址:http://cn2.php.net/distributions/php-7.0.17.tar.gz

 別急!

上一步咱們查看那了phpinfo,首先先複製Configure Command 等一會編譯的時候要用

'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--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' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-intl' '--with-xsl'

先停掉php-fpm

service php-fpm stop

備份下老的php版本

cd /usr/local
mv php php5.4

ok,如今能夠安裝php7了

tar xzvf php-7.0.17.tar.gz
cd php-7.0.17

帶上剛纔複製的Configure Command

關於Linux configure 參數解釋參考: http://blog.chinaunix.net/uid-20568163-id-1632905.html

'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--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' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-intl' '--with-xsl'
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.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

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/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 commands
configure: WARNING: unrecognized options: --with-mysql
root@aaa-VirtualBox:/home/wwwroot/tools/php-7.0.17# 

提示:configure: WARNING: unrecognized options: --with-mysql 是由於php7已經不在用--with-mysql 支持mysql模塊鏈接了,取而代之的是--with-mysqli 、--with-pdo-mysql,去掉--with-mysql=mysqlnd 即可。

若是提示:

checking if we should use cURL for url streams... no checking for cURL in default path... not found

configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/

執行: 

apt-get install curl
apt-get install libcurl4-gnutls-dev

修改configure 參數:增長參數--with-curl=/usr/local/curl

 

接着make && make install  

問題又來了

collect2: error: ld returned 1 exit status
Makefile:294: recipe for target 'sapi/cli/php' failed
make: *** [sapi/cli/php] Error 1

查看報錯的內容:

 In function `convert’:
 encodings.c:73: undefined reference to `libiconv_open’
 encodings.c:81: undefined reference to `libiconv’
 encodings.c:101: undefined reference to `libiconv_close’

libiconv模塊錯誤,but libiconv是安裝的,不知爲什麼提示錯誤,解決辦法 make時加了一個參數, 參考:http://lynnteng0.blog.51cto.com/2145094/1257910       https://fukun.org/archives/10102487.html

make ZEND_EXTRA_LIBS='-liconv'

啓動php-fpm

service php-fpm start

提示: 無一下提示可忽略

Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details. 使用systemctl status php-fpm.service 查看詳情

 ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
 ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
 ERROR: FPM initialization failed
 php-fpm.service: Control process exited, code=exited status=1
 Failed to start LSB: starts php-fpm.

修改/usr/local/php/etc/php-fpm.conf.default 爲 php-fpm.conf (mv)
並將/usr/local/php/etc/php-fpm.d中 www.conf.default的文件mv爲www.conf文件

而後在啓動php-fpm 、重新加載nginx

service php-fpm start
service nginx reload 

訪問IP地址或域名

502 bad gateway

這個說明php-fpm 已經運行,但php-fpm的配置有問題  參考:http://www.111cn.net/phper/31/93675.htm

關於php-fpm的配置參數參考: http://www.jb51.net/article/37749.htm

使用LNMP配置出來的php-fpm.conf文件 (LNMP可正常啓動)

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

如今單獨安裝php7.0.17 生成的conf在 /usr/local/php/etc/php-f/php-fpm.d/www.conf中 (php-fpm.conf中include進來的)

修改www.conf

listen = 127.0.0.1:9000 

改成

listen = /tmp/php-cgi.sock

listen.owner = www
listen.group = www
listen.mode = 0666

三行最前面的 ‘;’ 去掉,重啓服務。

到此,php已經從php5.4升級爲php7了。

 

擴展安裝

 安裝擴展,可參考:

Yii2中mongodb使用ActiveRecord的數據操做

 

 

 

 

Deepin下 使用apt get install 安裝nginx和php-fpm

Deepin Linux桌面版沒有辦法安裝php的集成環境,不管是Lanmps、Lnmp、phpstudy,安裝的時候就會卸載Deepin15.1的應用,包括dde桌面

那麼只能手動安裝php環境

1. 安裝nginx

apt-get install nginx

訪問localhost

 

默認的web目錄在/var/www/html, 默認的conf在/etc/nginx/nginx.conf, 執行文件在/usr/sbin/nginx

 

2.安裝php7.1

apt-get install php7.1-fpm

 

3.配置nginx支持php

gedit /etc/nginx/site-available/default

添加php 默認頁面

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

支持.php 文件解析

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
    #    # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
    #    # With php-cgi (or other tcp sockets):
    #    fastcgi_pass 127.0.0.1:9000;
    }

從新加載nginx

service nginx reload

設置/var/www/html/index.php 內容

<?php

phpinfo();

?>

4.對mysql的支持

安裝mysql

apt-get install mysql-server mysql-client

 

php鏈接mysql

apt-get install php7.1-mysql

重啓服務:

service php7.1-fpm reload
service nginx reload

 

支持memcached

# memcached服務端
apt-get install memcached
#memcached -d -m 256 -p 11211 -u root

php-memcahced插件

# 找不到源
apt-get install  php7.1-memcached

apt 安裝不了,只能編譯安裝

編譯安裝的時候必需要指定phpize才能知道掛載的擴展

啓用phpize:

apt-get install php7.1-dev

安裝完php7.1-dev 後phpize的目錄在 /usr/bin/phpize

下載php-memcahced 擴展

wget http://pecl.php.net/get/memcached-3.0.3.tgz
tar xzvf memcached-3.0.3.tgz
cd memcached-3.0.3

/usr/bin/phpize

當configure 的時候提示 not find libmemcached

安裝libmemcached-dev

apt-get install libmemcached  # 不存在
apt-get install libmemcached-dev
./configure
make
&& make install

在php.ini 中添加memcahced.so

相關文章
相關標籤/搜索