タグ: PHP

  • PHPのバージョンアップしたら、Nginxが起動しなくなった

    Ubuntu 18.04で、PHPをPHP7.2からPHP7.4にアップデートしたところ、作業後にOSを再起動したら、Nginxが起動しなくなった。原因を調べて対処したので、メモを残す。

    Nginxのステータスを確認したところ。

    ubuntu@ip-10-0-0-122:/etc/nginx$ sudo service nginx status
    ● nginx.service - A high performance web server and a reverse proxy server
       Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Wed 2020-10-14 22:35:23 PDT; 5s ago
         Docs: man:nginx(8)
      Process: 1296 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
    Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: Starting A high performance web server and a reverse proxy server...
    Oct 14 22:35:23 ip-10-0-0-122 nginx[1296]: nginx: [emerg] "try_files" directive is duplicate in /etc/nginx/sites-enabled
    Oct 14 22:35:23 ip-10-0-0-122 nginx[1296]: nginx: configuration file /etc/nginx/nginx.conf test failed
    Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: nginx.service: Control process exited, code=exited status=1
    Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: nginx.service: Failed with result 'exit-code'.
    Oct 14 22:35:23 ip-10-0-0-122 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
    ubuntu@ip-10-0-0-122:/etc/nginx$
    

    PHP7.4にアップデートしたタイミングで、Apacheがインストールされて、これが自動起動しており、Nginxと、ポート80の使用が競合して、Nginxが落ちていた。apache2の自動起動を停止する。

    sudo systemctl disable apache2
    

    それでも、まだ、Nginxの起動でエラーになる。ログを見ると、コンフィグの問題のようなので、configtestを実施し、見事にエラーになる。

    ubuntu@ip-10-0-0-122:/etc/nginx/sites-available$ sudo service nginx configtest
     * Testing nginx configuration                                                                                   [fail]
    ubuntu@ip-10-0-0-122:/etc/nginx/sites-available$
    

    Nginxのコンフィグのdefaultで、php7.2-fpmの部分を、php7.4-fpmのsockに書き換え。

    その後、Nginxの起動を試すが失敗。Nginxのコンフィグチェックを行って、エラーになっている行を特定。

    sudo nginx -t
    nginx: [emerg] "try_files" directive is duplicate in /etc/nginx/sites-enabled/default:77
    nginx: configuration file /etc/nginx/nginx.conf test failed
    

    “try_files” がダブっているというので、場所を確認して、変更した。なぜ、急にエラーになったのか、はあるが、とりあえず、スルー。修正後は、Nginxが無事に起動した。

    最初のStatusのログをみると、最初から”try_files ”が問題って書いてあった。おちついて、見る必要あり。

  • UbuntuのPHPを7.2から、7.4にしてみた

    Ubuntu 18.04のPHPをPHP7.2からPHP7.4に上げた。PHPを使っているのは、Wordpress。そのメモ。でも、途中が消えてる気がする、というか消えてる。

    ubuntu@ip-10-0-0-122:~$ php -v
    PHP 7.2.24-0ubuntu0.18.04.7 (cli) (built: Oct  7 2020 15:24:25) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
        with Zend OPcache v7.2.24-0ubuntu0.18.04.7, Copyright (c) 1999-2018, by Zend Technologies
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ sudo apt install software-properties-common
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    software-properties-common is already the newest version (0.96.24.32.14).
    software-properties-common set to manually installed.
    The following packages were automatically installed and are no longer required:
      libdumbnet1 libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail
      libnginx-mod-stream linux-aws-5.3-headers-5.3.0-1017 linux-aws-5.3-headers-5.3.0-1019
      linux-aws-5.3-headers-5.3.0-1023 linux-aws-5.3-headers-5.3.0-1028 linux-aws-5.3-headers-5.3.0-1030
      linux-aws-5.3-headers-5.3.0-1032 linux-aws-5.3-headers-5.3.0-1033 linux-aws-5.3-headers-5.3.0-1034
      linux-aws-5.3-headers-5.3.0-1035 linux-aws-headers-4.15.0-1041 linux-aws-headers-4.15.0-1043
      linux-aws-headers-4.15.0-1044 linux-aws-headers-4.15.0-1045 linux-aws-headers-4.15.0-1047
      linux-aws-headers-4.15.0-1048 linux-aws-headers-4.15.0-1050 linux-aws-headers-4.15.0-1052
      linux-aws-headers-4.15.0-1054 linux-aws-headers-4.15.0-1056 linux-aws-headers-4.15.0-1057
      linux-aws-headers-4.15.0-1058 linux-aws-headers-4.15.0-1060 linux-aws-headers-4.15.0-1063
      linux-aws-headers-4.15.0-1065 linux-headers-5.3.0-1035-aws linux-image-5.3.0-1035-aws linux-modules-5.3.0-1035-aws
      nginx-common nginx-core
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ sudo add-apt-repository ppa:ondrej/php
     Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.
    Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa
    You can get more information about the packages at https://deb.sury.org
    IMPORTANT: The -backports is now required on older Ubuntu releases.
    BUGS&FEATURES: This PPA now has a issue tracker:
    https://deb.sury.org/#bug-reporting
    CAVEATS:
    1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
    2. If you are using apache2, you are advised to add ppa:ondrej/apache2
    3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
       or ppa:ondrej/nginx
    PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/
    WARNING: add-apt-repository is broken with non-UTF-8 locales, see
    https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:
    # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
     More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
    Press [ENTER] to continue or Ctrl-c to cancel adding it.
    Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
    Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
    Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
    Get:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease [20.8 kB]
    Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
    Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 Packages [71.9 kB]
    Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main Translation-en [29.5 kB]
    Fetched 374 kB in 1s (398 kB/s)
    Reading package lists... Done
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ sudo apt update
    Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
    Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
    Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
    Hit:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
    Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
    Fetched 163 kB in 0s (399 kB/s)
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    20 packages can be upgraded. Run 'apt list --upgradable' to see them.
    ubuntu@ip-10-0-0-122:~$
    ubuntu@ip-10-0-0-122:~$ php -v
    PHP 7.4.11 (cli) (built: Oct 10 2020 19:44:50) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
        with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
    ubuntu@ip-10-0-0-122:~$
    

    このあと、Nginxのコンフィグで、php7.2-fpmからphp7.4-fpmに指定を変更して、Nginxを再起動。

    WordPressにアクセスしたら、php7.4-mysqlが入っていないと言われ、使えず。aptでインストールする。

    sudo apt install php7.4-mysql

    そのあと、Wordpressのヘルスチェックを確認。gdもないというので、aptでインストール。

    sudo apt install php7.4-gd

    これでバージョンアップは終わり。

  • Moodleのgitリポジトリをクローンしたところ、拒否された

    Moodleをインストールするために、Gitリポジトリをクローンしようとしたしたところ、「git.moodle.org[0: 34.210.133.53]: errno=接続を拒否されました」と表示された。

    sudo git clone git://git.moodle.org/moodle.git
    Cloning into 'moodle'...
    fatal: unable to connect to git.moodle.org:
    git.moodle.org[0: 34.210.133.53]: errno=接続を拒否されました
    

    で、対処としては、github上のリポジトリから取得するようにした。これで、接続拒否のエラーは解消。

    sudo git clone https://github.com/moodle/moodle.git

    下記は、作業時のログ。

    zen@moodle:/opt$ sudo git clone git://git.moodle.org/moodle.git
    Cloning into 'moodle'...
    fatal: unable to connect to git.moodle.org:
    git.moodle.org[0: 34.210.133.53]: errno=接続を拒否されました
    
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$ ls
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$ git clone https://github.com/moodle/moodle.git
    fatal: could not create work tree dir 'moodle': 許可がありません
    zen@moodle:/opt$ sudo git clone https://github.com/moodle/moodle.git
    Cloning into 'moodle'...
    remote: Enumerating objects: 7, done.
    remote: Counting objects: 100% (7/7), done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 1163958 (delta 0), reused 0 (delta 0), pack-reused 1163951
    Receiving objects: 100% (1163958/1163958), 536.89 MiB | 22.33 MiB/s, done.
    Resolving deltas: 100% (812431/812431), done.
    Updating files: 100% (21140/21140), done.
    zen@moodle:/opt$ ls
    moodle
    zen@moodle:/opt$
    
    
    zen@moodle:/opt/moodle$ sudo git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/MOODLE_13_STABLE
      remotes/origin/MOODLE_14_STABLE
      remotes/origin/MOODLE_15_STABLE
      remotes/origin/MOODLE_16_STABLE
      remotes/origin/MOODLE_17_STABLE
      remotes/origin/MOODLE_18_STABLE
      remotes/origin/MOODLE_19_STABLE
      remotes/origin/MOODLE_20_STABLE
      remotes/origin/MOODLE_21_STABLE
      remotes/origin/MOODLE_22_STABLE
      remotes/origin/MOODLE_23_STABLE
      remotes/origin/MOODLE_24_STABLE
      remotes/origin/MOODLE_25_STABLE
      remotes/origin/MOODLE_26_STABLE
      remotes/origin/MOODLE_27_STABLE
      remotes/origin/MOODLE_28_STABLE
      remotes/origin/MOODLE_29_STABLE
      remotes/origin/MOODLE_30_STABLE
      remotes/origin/MOODLE_31_STABLE
      remotes/origin/MOODLE_32_STABLE
      remotes/origin/MOODLE_33_STABLE
      remotes/origin/MOODLE_34_STABLE
      remotes/origin/MOODLE_35_STABLE
      remotes/origin/MOODLE_36_STABLE
      remotes/origin/MOODLE_37_STABLE
      remotes/origin/MOODLE_38_STABLE
      remotes/origin/master
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$ sudo git branch --track MOODLE_38_STABLE origin/MOODLE_38_STABLE
    Branch 'MOODLE_38_STABLE' set up to track remote branch 'MOODLE_38_STABLE' from 'origin'.
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$ sudo git checkout MOODLE_38_STABLE
    Switched to branch 'MOODLE_38_STABLE'
    Your branch is up to date with 'origin/MOODLE_38_STABLE'.
    zen@moodle:/opt/moodle$
    

  • 2020年秋に、PHP8がリリースされる

    PHP5から、PHP7に乗り換えるときに、いろいろと動かなくなって苦労した記憶がある。今度は、今年の秋にPHP8がリリースされる。PHP7との互換性は、多少損なわれているそうなので、また、移行の苦しみがあるようだ。

    自分で、PHPを使ったプログラムは開発していないけれど、PHPのアプリケーションは使っているので、しばらくは対応待ち。そのあとで、移行がある。そして、また、微妙に動かない部分が出たり、忘れた頃に不具合が見つかったりするのだろう。PHP8が出たあとの移行は、すんなりと行くだろうか。

    https://forest.watch.impress.co.jp/docs/news/1261630.html

  • Moodleのgitリポジトリをクローンしたところ、拒否された

    Moodleをインストールするために、Gitリポジトリをクローンしようとしたしたところ、「git.moodle.org[0: 34.210.133.53]: errno=接続を拒否されました」と表示された。

    sudo git clone git://git.moodle.org/moodle.git
    Cloning into 'moodle'...
    fatal: unable to connect to git.moodle.org:
    git.moodle.org[0: 34.210.133.53]: errno=接続を拒否されました
    

    で、対処としては、github上のリポジトリから取得するようにした。これで、接続拒否のエラーは解消。

    sudo git clone https://github.com/moodle/moodle.git
    

    下記は、ログ。

    zen@moodle:/opt$ sudo git clone git://git.moodle.org/moodle.git
    Cloning into 'moodle'...
    fatal: unable to connect to git.moodle.org:
    git.moodle.org[0: 34.210.133.53]: errno=接続を拒否されました
    
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$ ls
    zen@moodle:/opt$
    zen@moodle:/opt$
    zen@moodle:/opt$ git clone https://github.com/moodle/moodle.git
    fatal: could not create work tree dir 'moodle': 許可がありません
    zen@moodle:/opt$ sudo git clone https://github.com/moodle/moodle.git
    Cloning into 'moodle'...
    remote: Enumerating objects: 7, done.
    remote: Counting objects: 100% (7/7), done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 1163958 (delta 0), reused 0 (delta 0), pack-reused 1163951
    Receiving objects: 100% (1163958/1163958), 536.89 MiB | 22.33 MiB/s, done.
    Resolving deltas: 100% (812431/812431), done.
    Updating files: 100% (21140/21140), done.
    zen@moodle:/opt$ ls
    moodle
    zen@moodle:/opt$
    
    
    zen@moodle:/opt/moodle$ sudo git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      remotes/origin/MOODLE_13_STABLE
      remotes/origin/MOODLE_14_STABLE
      remotes/origin/MOODLE_15_STABLE
      remotes/origin/MOODLE_16_STABLE
      remotes/origin/MOODLE_17_STABLE
      remotes/origin/MOODLE_18_STABLE
      remotes/origin/MOODLE_19_STABLE
      remotes/origin/MOODLE_20_STABLE
      remotes/origin/MOODLE_21_STABLE
      remotes/origin/MOODLE_22_STABLE
      remotes/origin/MOODLE_23_STABLE
      remotes/origin/MOODLE_24_STABLE
      remotes/origin/MOODLE_25_STABLE
      remotes/origin/MOODLE_26_STABLE
      remotes/origin/MOODLE_27_STABLE
      remotes/origin/MOODLE_28_STABLE
      remotes/origin/MOODLE_29_STABLE
      remotes/origin/MOODLE_30_STABLE
      remotes/origin/MOODLE_31_STABLE
      remotes/origin/MOODLE_32_STABLE
      remotes/origin/MOODLE_33_STABLE
      remotes/origin/MOODLE_34_STABLE
      remotes/origin/MOODLE_35_STABLE
      remotes/origin/MOODLE_36_STABLE
      remotes/origin/MOODLE_37_STABLE
      remotes/origin/MOODLE_38_STABLE
      remotes/origin/master
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$ sudo git branch --track MOODLE_38_STABLE origin/MOODLE_38_STABLE
    Branch 'MOODLE_38_STABLE' set up to track remote branch 'MOODLE_38_STABLE' from 'origin'.
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$
    zen@moodle:/opt/moodle$ sudo git checkout MOODLE_38_STABLE
    Switched to branch 'MOODLE_38_STABLE'
    Your branch is up to date with 'origin/MOODLE_38_STABLE'.
    zen@moodle:/opt/moodle$
    
  • pukiwikiで突然、pkwk_touch_fileのエラーが出た

    pukiwikiでページを更新したところ、画面が白くなり、何も表示されなくなった。ページを更新したところ、下記のエラーが表示された。更新したはずページは、中身が空っぽで表示されず。更新しても、下記のエラーが表示されるだけになった。

    pkwk_touch_file(): Invalid UID and (not writable for the directory or not a flie): recent.dat
    

    急に、これになったので、権限の問題ではない。単純に、ディスクがいっぱいでファイルの書き込みができなかったからだった。容量不足で書き込めていないので、”recent.dat”というファイルを探しても見つからない。

    ディスク上の不要なファイルを削除して、空き容量を作り、無事に書き込めるようになり、解決した。

  • WordPressのcocoonテーマでエラーが出る

    WordPressのcocoonテーマで、下記のエラーが表示される。

    /wp-content/themes/cocoon-master/lib/open-graph.php(356)
    

    調べると、curlを使った処理でエラーになっていた。PHPのモジュールでcurlが入っているかみたところ、インストールされていなかった。FreeBSDのパッケージからcurlのモジュールをインストールして、apacheを再起動した。これで、解決した。

     pkg install php73-curl
    
  • WordPressのアップデート時に「Maximum execution time」が発生する

    WordPressのアップデート時に、下記のエラーが発生する。

    Fatal error: Maximum execution time of 30 seconds exceeded in /usr/xxxxxx/xxxxxx/blog2/wp-content/plugins/ssh-sftp-updater-support/phpseclib/Crypt/Base.php(2554) : eval()'d code on line 563
    

    いろいろと調べたところ、実行時間の問題のようなので、PHPの最大時間を変更する。php.iniを編集し、「max_execution_time」の値を30から60に変更して、apacheを再起動。

    ;変更前
    ;max_execution_time = 30
    ;変更後
    max_execution_time = 60
    

    実行時間を最大30秒から60秒に増やしたが、それでもギリギリだった。PHP7にしたため、いろいろと重くなっているのかもしれない。

  • WordPressでアップデートするとhash_algos() がエラーになる

    PHPをPHP7.3に上げたところ、Wordpressのアップデートで、下記のエラーが表示された。

    Fatal error: Uncaught Error: Call to undefined function hash_algos() in /usr/xxxxxx/xxxxxx/wp-admin/includes/file.php:1166 Stack trace: #0 
    

    該当ファイルのエラーになったソースコードをみると下記のようになっていた。

            if ( ! function_exists( 'sodium_crypto_sign_verify_detached' ) || ! in_\
    array( 'sha384', array_map( 'strtolower', hash_algos() ) ) ) {
    

    「hash_alogs()」でエラーになっているようだ。調べてみたら、php73-hash-7.3.X がインストールされていなかった。FreeBSDでパッケージから、php73-hashをインストールして、apacheを再起動した。

    # pkg install php73-hash
    Updating FreeBSD repository catalogue...
    FreeBSD repository is up to date.
    All repositories are up to date.
    The following 1 package(s) will be affected (of 0 checked):
    
    New packages to be INSTALLED:
    	php73-hash: 7.3.8
    
    Number of packages to be installed: 1
    
    152 KiB to be downloaded.
    
    Proceed with this action? [y/N]: y
    [1/1] Fetching php73-hash-7.3.8.txz: 100%  152 KiB 155.8kB/s    00:01    
    Checking integrity... done (0 conflicting)
    [1/1] Installing php73-hash-7.3.8...
    [1/1] Extracting php73-hash-7.3.8: 100%
    Message from php73-hash-7.3.8:
    
    This file has been added to automatically load the installed extension:
    /usr/local/etc/php/ext-20-hash.ini
    

    すぐにWordpressのアップデートを試すと、「別の更新が進行中です。」と出てしまうことがある。これは、前のアップデートによるロックが発生しているため。15分経てば、DBのロックが解除されるので、時間が立ってから試す。

  • WordPressで、xml_parser_create()のエラーが発生した

    PHPをPHP5.6からPHP7.3に上げたところ、Wordpressで以下のエラーが発生した。

    Fatal error: Uncaught Error: Call to undefined function xml_parser_create()
    

    PHPのオプションで、xmlに関するモジュールがインストールされていないことが原因だった。FreeBSDでパッケージからインストールしているので、下記のようにpkgコマンドでインストール。その後、Apacheを再起動し、無事にエラーは解消。

    pkg install php73-xml-7.3.8