2020年 04月 12日
SUSE Linux 15(openSUSE15.1 Leap) で php7 on nginx
SUSE15 で動かす nginx HTTP, インストール
次の文書が役に立ちました。
Install LEMP – Nginx, PHP, MariaDB and PhpMyAdmin in OpenSUSEInstall LEMP stack (Nginx, MariaDB, PHP) on OpenSUSE Leap 42.1https://www.linuxbabe.com/linux-server/install-lemp-stack-nginx-mariadb-php-opensuse-leap-42-1
YaST/YaST2 >Software Management で "php7-fpm" を検索/チェックしてインストールします。 自動的に追加のパッケージもインストールされます。
opensuse151:~ # cat /srv/www/htdocs/index.php<?phpphpinfo();?>opensuse151:~ #opensuse151:~ # ls /srv/www/htdocs/50x.html index.phpopensuse151:~ #
opensuse151:~ # gedit /etc/php7/fpm/php-fpm.conf &php-fpm.log の書き込み先を指定するため、error_log のコメントアウトを外します。/var/log/php-fpm.log に書き込まれます。
opensuse151:~ # cp /etc/php7/fpm/php-fpm.d/www.conf.default /etc/php7/fpm/php-fpm.d/www.confopensuse151:~ #opensuse151:~ # gedit /etc/php7/fpm/php-fpm.d/www.conf &デフォルトユーザ、グループのコメントを外して nginx を設定します。
不要説もあるようですが php.ini の cgi.fix_pathinfo に0(無効) をセットします。php の古いバージョンではセキュリティリスクだったようです。過去の互換性の問題もあるようなで、別に有効にしておく必要もないようなのですから、教科書通り無効 (0) にしておくのが良いでしょう。
opensuse151:~ # gedit /etc/php7/cli/php.ini &opensuse151:~ #cgi.fix_pathinfo=0
cgi.fix_pathinfo boolean

/etc/mginx/nginx.conf にディレクトリ指定された時にデフォルトで開かれるファイル index.php を先頭に追加しておきます。
深く突っ込まれても困るのですが、 /etc/mginx/nginx.conf の "location...." のセクションはコメントを外し次の様に設定しました。location ~ \.php$ {root /srv/www/htdocs/;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}--fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
の行を
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;に変えます。これでドキュメントルートのスクリプトを見つけるようです。
FastCGI Paramshttps://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
YaST > Service Manager から、nginx と php-fpm を自動起動(On Boot)をセット、Start (アクテブ) にします。「コマンドライン命」であれば、 systemctrl コマンドで enable/start させます。 opensuse151:/srv/www/htdocs # systemctl restart nginxopensuse151:/srv/www/htdocs # systemctl status nginx● nginx.service - The nginx HTTP and reverse proxy serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)Active: active (running) since Fri 2020-04-10 14:34:46 JST; 7s agoProcess: 3475 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)Main PID: 3476 (nginx)Tasks: 2 (limit: 4915)CGroup: /system.slice/nginx.service├─3476 nginx: master process /usr/sbin/nginx -g daemon off;└─3479 nginx: worker processApr 10 14:34:46 opensuse151 systemd[1]: Stopped The nginx HTTP and reverse proxy server.Apr 10 14:34:46 opensuse151 systemd[1]: Starting The nginx HTTP and reverse proxy server...Apr 10 14:34:46 opensuse151 nginx[3475]: nginx: the configuration file /etc/nginx/nginx.conf sy>Apr 10 14:34:46 opensuse151 nginx[3475]: nginx: configuration file /etc/nginx/nginx.conf test i>Apr 10 14:34:46 opensuse151 systemd[1]: Started The nginx HTTP and reverse proxy server.opensuse151:/srv/www/htdocs #
と思ったらブラウザの VPN のエクステンションが有効になっていました。これにハマって二時間の無駄....
