PHP7.1からPHP8.1に、Phalcon3.2からPhalcon5.2にアップグレード。
アップグレード前の環境
- PHP7.1
- Phalcon3.2
- Zephir0.10
- CentOS
- Nginx
アップグレード後の環境
- PHP8.1
- Phalcon5.2
- Zephir0.17
- CentOS
- Nginx
現バージョンの確認
# phpの現パージョン確認 $ php -v PHP 7.1.33 (cli) (built: Sep 29 2020 09:53:22) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies # phalconの現バージョン確認 $ php -r "echo Phalcon\Version::get();" 3.2.2
PHP7からPHP8へアップグレード
PHP設定ファイルのバックアップ
# php.iniのバックアップ $ cp /etc/php.ini /etc/php.ini.yyyymmdd # php-fpm.d/www.confのバックアップ $ cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.yyyymmdd
現在のPHPのパッケージ確認
phpアップデートするときに同じの入れるのでメモっておく。
$ yum list installed php* Loaded plugins: fastestmirror, langpacks http://yum.mariadb.org/10.1/centos7-amd64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found Trying other mirror. To address this issue please refer to the below knowledge base article https://access.redhat.com/articles/1320623 If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/ Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.riken.jp * epel-debuginfo: ftp.riken.jp * epel-source: ftp.riken.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp Installed Packages php-cli.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-common.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-devel.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-fpm.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-json.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-mbstring.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-mcrypt.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-mysqlnd.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-opcache.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-pdo.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-pgsql.x86_64 7.1.33-10.el7.remi @remi-php71-repo php-xml.x86_64 7.1.33-10.el7.remi @remi-php71-repo
PHP8を導入
updateできるphpのバージョン確認
$ ls /etc/yum.repos.d/ | grep remi-php remi-php70-repo.repo remi-php71-repo.repo
php8がないので導入
$ yum update epel-release
上記でphp8がない場合は以下を実行
$ yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm [/bash: php8がインストールできるか確認 $ ls /etc/yum.repos.d/ | grep remi-php remi-php54.repo remi-php70.repo remi-php70-repo.repo remi-php71.repo remi-php71-repo.repo remi-php72.repo remi-php73.repo remi-php74.repo remi-php80.repo remi-php81.repo remi-php82.repo
remi-php80.repo,remi-php81.repo,remi-php82.repoがあるのでOK。
phpの最新バージョン確認(どのバージョンにアップグレードするか確認のため)
https://www.php.net/downloads
PhalconがPHP8.2以降はまだ対応できていないようで、Phalcon V6以降で対応予定(PHP8.1も公式で対応していると発表がないかも)。
8.1にバージョンアップ。
PHPアップグレード
既存のphp削除
$ yum remove "php*"
phpアップデート
$ yum -y install --enablerepo=epel,remi,remi-php81 php php-cli php-common php-devel php-fpm php-json php-mcrypt php-mysqlnd php-opcache php-pdo php-pgsql php-xml php-mbstring php-gmp php-zip php-gd php-pecl-apcu php-sodium
アップデート確認
$ php -v PHP Warning: PHP Startup: Unable to load dynamic library 'phalcon.so' (tried: /usr/lib64/php/modules/phalcon.so (/usr/lib64/php/modules/phalcon.so: undefined symbol: _zval_ptr_dtor), /usr/lib64/php/modules/phalcon.so.so (/usr/lib64/php/modules/phalcon.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'zephir_parser.so' (tried: /usr/lib64/php/modules/zephir_parser.so (/usr/lib64/php/modules/zephir_parser.so: undefined symbol: _zval_ptr_dtor), /usr/lib64/php/modules/zephir_parser.so.so (/usr/lib64/php/modules/zephir_parser.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP 8.1.20 (cli) (built: Jun 6 2023 23:02:31) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.1.20, Copyright (c) Zend Technologies with Zend OPcache v8.1.20, Copyright (c), by Zend Technologies
php8.1にアップデートできたがphalconとzephirでエラーが出ている。
zephirを最新にする
php-zephir-parserの最新化
php-zephir-parserのディレクトリに移動。
$ cd /{path}/php-zephir-parser
php-zephir-parserを最新にする。
$ git pull $ make distclean $ ./configure $ make $ make install
エラーが解消しているか確認。
$ php -v PHP Warning: PHP Startup: Unable to load dynamic library 'phalcon.so' (tried: /usr/lib64/php/modules/phalcon.so (/usr/lib64/php/modules/phalcon.so: undefined symbol: _zval_ptr_dtor), /usr/lib64/php/modules/phalcon.so.so (/usr/lib64/php/modules/phalcon.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 PHP 8.1.20 (cli) (built: Jun 6 2023 23:02:31) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.1.20, Copyright (c) Zend Technologies with Zend OPcache v8.1.20, Copyright (c), by Zend Technologies
zephirのエラーは解消。
zephirコマンドが使えるか確認。
$ zephir PHP Deprecated: Return type of Zephir\Commands\Manager::attach($object, $data = null) should either be compatible with SplObjectStorage::attach(object $object, mixed $info = null): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Commands/Manager.php on line 126 Deprecated: Return type of Zephir\Commands\Manager::attach($object, $data = null) should either be compatible with SplObjectStorage::attach(object $object, mixed $info = null): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Commands/Manager.php on line 126 PHP Deprecated: Return type of Zephir\Commands\Manager::detach($object) should either be compatible with SplObjectStorage::detach(object $object): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Commands/Manager.php on line 143 Deprecated: Return type of Zephir\Commands\Manager::detach($object) should either be compatible with SplObjectStorage::detach(object $object): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Commands/Manager.php on line 143 PHP Deprecated: Return type of Zephir\Commands\Manager::getHash($object) should either be compatible with SplObjectStorage::getHash(object $object): string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Commands/Manager.php on line 102 Deprecated: Return type of Zephir\Commands\Manager::getHash($object) should either be compatible with SplObjectStorage::getHash(object $object): string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Commands/Manager.php on line 102 PHP Deprecated: Return type of Zephir\Config::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 188 Deprecated: Return type of Zephir\Config::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 188 PHP Deprecated: Return type of Zephir\Config::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 199 Deprecated: Return type of Zephir\Config::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 199 PHP Deprecated: Return type of Zephir\Config::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 225 Deprecated: Return type of Zephir\Config::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 225 PHP Deprecated: Return type of Zephir\Config::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 249 Deprecated: Return type of Zephir\Config::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 249 PHP Deprecated: Return type of Zephir\Config::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 305 Deprecated: Return type of Zephir\Config::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /web/lib/zephir/Library/Config.php on line 305 _____ __ _ /__ / ___ ____ / /_ (_)____ / / / _ \/ __ \/ __ \/ / ___/ / /__/ __/ /_/ / / / / / / /____/\___/ .___/_/ /_/_/_/ /_/ Zephir version 0.10.16-6826149172 Usage: command [options] Available commands: api Generates a HTML API based on the classes exposed in the extension build Generates/Builds/Installs a Zephir extension builddev Generates/Builds/Installs a Zephir extension in development mode clean Cleans any object files created by the extension compile Compile a Zephir extension fullclean Cleans any object files created by the extension (including files generated by phpize) generate Generates C code from the Zephir code without compiling it help Displays this help and exit init Initializes a Zephir extension install Installs the extension in the extension directory (may require root password) stubs Generates stubs that can be used in a PHP IDE version Shows the Zephir version Options: --help|-h Displays command help and exit -f([a-z0-9\-]+) Enables compiler optimizations -fno-([a-z0-9\-]+) Disables compiler optimizations -w([a-z0-9\-]+) Turns a warning on -W([a-z0-9\-]+) Turns a warning off
Deprecatedが出てるのでzephirを最新化する。
zephirを最新化
zephirのディレクトリに移動。
$ cd /{path}/zephir
リポジトリ最新化。
$ git pull
tagsの情報確認。
$ git tag
今回は0.17.0のtagsのバージョンにする。
0.17.0のバージョンを確認。
$ git show 0.17.0 commit 9f99da6da419a6f243a85645ae500e4ac76b7225 Merge: 5099f34 11ed29f Author: Anton Vasiliev <Jeckerson@users.noreply.github.com> Date: Sat Feb 11 20:14:50 2023 +0000 Merge pull request #2400 from zephir-lang/development 0.17.0
最新にアップデート。
$ git checkout -b 0.17.0 0.17.0 $ composer install
今までのzephirは別の場所に置いていたので、最新のzephirが参照されるようにする。
別の場所に置いてない場合はこの作業はスキップ。
今回は今までのzephirを削除して、最新のzephirを参照されるようにしたが、今までのzephirを最新のzephirでコピーして上書きしてもよかったかも。
古いzephirを削除し、最新のzephirにpathを通す。
$ rm -rf /root/bin/zephir $ export PATH=$PATH:/web/lib/zephir
サーバー再起動でもpathが適用されるようにbash_profileにも追記。
$ vi ~/.bash_profile # 末尾に以下を追加 export PATH=$PATH:/web/lib/zephir
zephirのアップデートができたか確認
$ zephir _____ __ _ /__ / ___ ____ / /_ (_)____ / / / _ \/ __ \/ __ \/ / ___/ / /__/ __/ /_/ / / / / / / /____/\___/ .___/_/ /_/_/_/ /_/ Zephir 0.17.0 by Andres Gutierrez and Serghei Iakovlev (source) Usage: command [options] [arguments] Options: --dumpversion Print the version of the compiler and don't do anything else (also works with a single hyphen) -h, --help Print this help message --no-ansi Disable ANSI output -v, --verbose Displays more detail in error messages from exceptions generated by commands (can also disable with -V) --vernum Print the version of the compiler as integer --version Print compiler version information and quit Available commands: api Generates a HTML API based on the classes exposed in the extension build Generates/Compiles/Installs a Zephir extension clean Cleans any object files created by the extension compile Compile a Zephir extension fullclean Cleans any object files created by the extension (including files generated by phpize) generate Generates C code from the Zephir code without compiling it help Display help for a command init Initializes a Zephir extension install Installs the extension in the extension directory (may require root password) stubs Generates stubs that can be used in a PHP IDE
zephir OK!
phalconのアップグレード
phalcon5.2にアップグレード。
必要なパッケージをインストール。
$ yum install php-devel pcre-devel gcc make re2c
cphalconのディレクトリに移動。
$ cd /{path}/cphalcon
phalcon.iniのファイル名を変更して、いったんextension=phalcon.soの読み込みを停止。
$ mv /etc/php.d/phalcon.ini /etc/php.d/phalcon.ini.yyyymmdd
git pullできなかったので、cloneURL変更し、pull。
$ vi .git/config -url = git://github.com/phalcon/cphalcon.git +url = https://github.com/phalcon/cphalcon.git $ git pull
タグの一覧から最新のタグ確認。
$ git tag
アップグレード対象のタグの情報を確認。
$ git show v5.2.1 commit fc183e11e8b96c43daf7d893244846206dc2aa73 Merge: 35431ac b5e7a64 Author: Anton Vasiliev <Jeckerson@users.noreply.github.com> Date: Tue Feb 28 16:45:15 2023 +0000 Merge pull request #16298 from phalcon/5.0.x 5.2.1 Release
checkoutして、アップグレード。
$ git checkout -b v5.2.1 v5.2.1 $ zephir fullclean $ zephir build PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 135168 bytes) in /web/lib/zephir/Library/CodePrinter.php on line 96
memoryが足りないみたいなのでphp.iniでmemoryをアップ。
# memory_limitを128Mから256Mに変更 $ vi /etc/php.ini -memory_limit = 128M +memory_limit = 256M # php-fpm再起動 $ /bin/systemctl restart php-fpm
再度アップグレード。
$ zephir fullclean $ zephir build
extension=phalcon.soの読み込みを再開し、php-fpmを再起動。
$ mv /etc/php.d/phalcon.ini.yyyymmdd /etc/php.d/phalcon.ini $ /bin/systemctl restart php-fpm
phalconインストールチェック。
phalconが表示されればOK!
$ php -m | grep phalcon phalcon
phalconのバージョン確認。
$ php -r "echo (new Phalcon\Support\Version())->get();" 5.2.1
php.iniの差分を確認し、必要な修正をする。
$ diff /etc/php.ini /etc/php.ini.yyyymmdd
php-fpm.d/www.confの差分を確認し、必要な修正をする。
$ diff /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.yyyymmdd
ini、confを修正した場合は、php-fpmを再起動。
$ /bin/systemctl restart php-fpm
php-fpmの自動起動設定。
$ systemctl enable php-fpm.service
以上でアップグレード作業完了です。
アップグレード後のコード修正
マニュアルを参考に修正。
参考:アップグレードガイド
https://docs.phalcon.io/4.0/ja-jp/upgrade
https://docs.phalcon.io/5.0/ja-jp/upgrade
以下、アップグレードで発生したエラー対応。