php_modが非推奨になったのね

昔のバージョンのphp環境でphpバージョンを上げるという対応中。 apache + PHP8のインスタンスを構築してドキュメントルートまで到達を確認。 対応する人にドキュメントルートまで到達するからプロジェクトのファイルを置いてバージョンアップのエラーを確認してもらうため依頼しましたが HTTP 503 Service Unavailable のエラーが出ているとのこと。 HTMLファイルはアクセスできているからPHPの実行ができていないと思い調べると Apache HTTP サーバーで使用するために PHP に提供されている mod_php モジュールが非推奨になりました。 php-fpmをインストールして起動し、リクエストを流してphp-fmpでphpを実行するようにして解決。 しばらくPHPを触っていなかったのでモジュールが非推奨になったことに気づかずでした。

nginxをソースからインストールする

nginxをソースからインストールして

パッケージと入れ替える

インストール環境
amazon linux

前回はLet's Encyptで証明書を発行してSSLの公開サイトを作る準備をしたんですが
mainline versionを入れたかったのがLet's Encyptでcertbotを使って自動でnginxの設定変更や起動スクリプトなど設定ファイルの場所が違うなどでエラーが出てしまい、時間もなかったのでパッケージからインストールしてしまいました。
ですので今回はソースからインストールしたもので差し替えたいと思います。

まずはダウンロード
こちらから現時点のMainline versionのnginx-1.13.10をダウンロードします。
場所は/usr/local/src/として進めます。※root権限で実行していってしまいます。
# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.13.10.tar.gz
# tar xvzf nginx-1.13.10.tar.gz
# cd nginx-1.13.10

インストールディレクトリを/usr/local/配下としてインストール作業をします
# ./configure --prefix=/usr/local/nginx-1.13.10

そうするともろもろ足りないパッケージがありエラーが出ました。
まずは以下のエラー
checking for OS
 + Linux 4.9.81-35.56.amzn1.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

Cのコンパイラがないということなので
# yum install gcc

再びconfigureを実行するとエラーが出ました
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

PCREがないということでインストール
# yum install pcre-devel

またconfigureを実行します。
またエラーが出ました。今度はzlibが足りないということです。
他のをインストールーする時によく見るエラーなのでこれはエラーを記録しとくのを忘れました。。
# yum install zlib-devel

では改めて
# ./configure --prefix=/usr/local/nginx-1.13.10

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx-1.13.10"
  nginx binary file: "/usr/local/nginx-1.13.10/sbin/nginx"
  nginx modules path: "/usr/local/nginx-1.13.10/modules"
  nginx configuration prefix: "/usr/local/nginx-1.13.10/conf"
  nginx configuration file: "/usr/local/nginx-1.13.10/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.13.10/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.13.10/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.13.10/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

これでやっと通りました。ではmakeしていきます。
# make && make install

インストールはできましたがnginxの起動やら設定やらをパッケージの方からソースインストールのバージョンになるように諸々対応していきます。

まずはパッケージの設定ファイルをバックアップしてリンクを張ります。
# mv /etc/nginx /root/
# cd /etc/
# ln -s /usr/local/nginx-1.13.10/conf nginx

先ほどのバックアップでcertbotで設定してもらっているnginx.confを上書きしちゃいます。
(差分をみて何を変更されたか確認はあとで学んでいきます)
バックアップ
# /usr/local/nginx-1.13.10/conf/nginx.conf /root/nginx.conf_1.13.10
yumインストールのバックアップした設定をコピー
※これはcertbotで証明書設定をしているためでやっているだけです。
# cp /root/nginx/nginx.conf /usr/local/nginx-1.13.10/conf/

起動スクリプトを書き換えます。
# vim /etc/init.d/nginx
nginxのパスを書きかえる。
#nginx="/usr/sbin/nginx"
nginx="/usr/local/nginx-1.13.10/sbin/nginx"

ここでnginxを起動したんですが以下エラーが出ました。
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx-1.13.10/conf/nginx.conf:86

モジュールがないので再度makeしてsslモジュールを読み込むようにします。
# ./configure --with-http_ssl_module --prefix=/usr/local/nginx-1.13.10

nginxを起動してSSLでアクセスできるようになりました。

あとは実行コマンドもバックアップしてこちらもリンクしていきます。
# cd /usr/sbin
# mv nginx /root/sbin_nginx
# ln -s /usr/local/nginx-1.13.10/sbin/nginx nginx
バージョンを確認します。
# nginx -v
# nginx version: nginx/1.13.10
1.13.10にバージョンがなりました。

インスタンス起動時にnginxがスタートするようにしておきます。
# chkconfig --list
パッケージインストルでnginx自体は追加されていますのでONするだけです
# chkconfig nginx on

これでソースからインストールしたnginxでインスタンス起動時にサービスをスタートさせることができました。
こちらで証明書設定したものでパッケージに入っている安定版のnginx1.12.1から切り替えることができました。
細かいnginxの設定はこれから学んでいきたいと思います。

コメント

このブログの人気の投稿

nginxで画像が表示されない。。

AWSのS3バケットをマウントするs3fsでマウントが外れた件

CakePHP3でHTTPSにする