我使用了 laravel-backup 來備份 悟禪小書童 檔案和資料,本地開發測試正常,更新到線上後,composer update
時報錯了,線上伺服器的PHP版本是 5.6
,但/laravel-backup
最新版要求 7.0+
,沒辦法,只好重新安裝PHP,並安裝對應的擴充套件。
安裝PHP7.0
-
移除舊版php及php擴充套件
$ yum remove php* php-common
-
安裝php7的yum源
$ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
實際安裝時報瞭如下錯誤:
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm Retrieving http://rpms.famillecollet.com/enterprise/remi-release-6.rpm warning: /var/tmp/rpm-tmp.yZ1q8y: Header V3 DSA/SHA1 Signature, key ID 00f97f56: NOKEY error: Failed dependencies: epel-release >= 6 is needed by remi-release-6.6-1.el6.remi.noarch
解決方式是先安裝
epel-release-6-8.noarch.rpm
,再安裝remi-release-6.rpm
。$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm $ rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
-
修改yum源
修改
/etc/yum.repos.d/remi.repo
檔案,將[remi]
段中的enabled=0
改為enabled=1
。$ vim /etc/yum.repos.d/remi.repo
... [remi] name=Remi's RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/6/remi/httpsmirror mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi ...
修改
/etc/yum.repos.d/remi-php70.repo
檔案,將[remi-php70]
段中的enabled=0
改為enabled=1
。$ vim /etc/yum.repos.d/remi-php70.repo
... [remi-php70] name=Remi's PHP 7.0 RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/php70/$basearch/ #mirrorlist=https://rpms.remirepo.net/enterprise/6/php70/httpsmirror mirrorlist=http://rpms.remirepo.net/enterprise/6/php70/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi ...
-
yum安裝php7及擴充套件
$ yum install php php-fpm php-cli php-pdo php-mysql php-gd php-bcmath php-xml php-mbstring php-mcrypt php-redis php-pear php-devel
記得一定要安裝
php-pear
和php-devel
,後續安裝zip
擴充套件要用到。安裝完成後檢測下
php版本
和php擴充套件
$ php -v PHP 7.0.17 (cli) (built: Mar 14 2017 15:23:16) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
$ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dom exif fileinfo filter ftp gd gettext hash iconv igbinary json libxml mbstring mcrypt mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite Phar posix readline redis Reflection session shmop SimpleXML sockets SPL sqlite3 standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlwriter xsl zlib [Zend Modules]
-
配置php並設定開機自啟
修改配置
$ vim /etc/php.ini
... date.timezone = Asia/Shanghai upload_max_filesize = 20M post_max_size = 20M display_errors = Off expose_php = Off ...
重啟php
$ service php-fpm restart
設定開機自啟
$ chkconfig php-fpm on
至此,PHP就成功升級到
7.0
了。
安裝ZIP擴充套件
使用 laravel-backup 備份資料庫時,報錯了:
Starting backup...
Dumping database blog...
Determining files to backup...
Zipping 1 files...
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'ZipArchive' not found
很明顯,錯誤原因時沒有安裝 zip
擴充套件,安裝即可。
-
下載
PHP7.0.17
的原始碼$ cd ~ $ wget http://php.net/get/php-7.0.17.tar.gz/from/this/mirror $ tar zxvf php-7.0.17.tar.gz $ cd php-7.0.17/ext/zip/
-
編譯安裝擴充套件
$ phpize $ ./configure $ make && make install
安裝成功後
zip.so
會儲存在/usr/lib64/php/modules/
目錄下。 -
啟用zip擴充套件
vim /etc/php.ini
Dynamic Extensions
部分增加extension=zip.so
:;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; ; If you wish to have an extension loaded automatically, use the following ; syntax: ; ; extension=modulename.extension ; ; For example, on Windows: ; ; extension=msql.dll ; ; ... or under UNIX: ; ; extension=msql.so ; ; ... or with a path: ; ; extension=/path/to/extension/msql.so ; ; If you only provide the name of the extension, PHP will look for it in its ; default extension directory. extension=zip.so
-
重啟apache
/etc/init.d/httpd restart
至此,zip擴充套件就安裝好了,用 php -m
檢測下,可以看到已經有了 zip
。
$ php -m
[PHP Modules]
...
xsl
zip
zlib
[Zend Modules]
接下來重新測試備份資料庫,可以看到已經備份成功。
$ php artisan backup:run --only-db
Starting backup...
Dumping database blog...
Determining files to backup...
Zipping 1 files...
Created zip containing 1 files. Size is 41.62 KB
Copying zip to disk named local...
Successfully copied zip to disk named local.
Copying zip to disk named qiniu...
Successfully copied zip to disk named qiniu.
Backup completed!
本作品採用《CC 協議》,轉載必須註明作者和本文連結