0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】KaliLinuxにphpをインストール

Last updated at Posted at 2023-11-06

こんにちは、なつきです。
やられサイト自作への道 KaliLinuxにphpを導入編です!

目次

1. はじめに
2. 実施内容
3. 前提条件
4. phpのインストール
5. nginxの設定変更
6. ブラウザで表示確認
7. 最後に
8. 参考資料

1. はじめに

やられサイト自作にあたり、php8.2をインストールしていこうと思います。

2. 実施内容

php8.2のインストール~nginxの設定変更、ブラウザでphpファイルを表示するまで

3. 前提条件

TODO

4. phpのインストール

  1. パッケージリストの更新をする

    sudo apt-get update
    
  2. php、php-fpmのインストール

    sudo apt install php
    sudo apt install php-fpm
    
  3. phpのインストール確認

    # php -v
    PHP 8.2.10 (cli) (built: Sep  5 2023 05:43:15) (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.2.10, Copyright (c) Zend Technologies
        with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies
    

5. nginxの設定変更

※nginxのインストール実施時の記事↓
【備忘録】KaliLinuxにnginxでWebサーバを構築

※PHPアプリケーションサーバ構築の前提知識
・PHP-FPM(FastCGI Process Manager):PHPサーバ、HTTPサーバは別に独立して動作するプロセス。HTTPサーバと分離することにより、PHPを実行する権限をより厳密にできる。

5-1. nginx.confの設定を変更

httpコンテキストの中にserverディレクティブを追記

/etc/nginx/nginx.conf
##
# www.zeizyaku.com
##
server {
  # バーチャルサーバが使用するアドレス、ポートを指定
  listen 8080;

  # ホスト名の指定
  server_name www.zeizyaku.com;

 # 公開するディレクティブ
  root /var/www/zeizyaku;

  access_log /var/www/zeizyaku/nginx/www.zeizyaku.com_access.log;
  error_log /var/www/zeizyaku/nginx/www.zeizyaku.com_error.log;

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  # URIごとの設定
  location ~* \.php {
    include ./snippets/fastcgi-php.conf;

    # HTTPのリクエストをFastCGIプロトコルでプロキシ
    # PHP-FPMがリッスンしているUNIXドメインソケットファイルを指定している
    fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
  }
}

5-2. その他の設定

  1. 設定ファイルに設定した資産を配置する

  2. server_nameディレクティブにホスト名を指定した場合、hostsファイルに情報を追記しておく

  3. php-fpmとnginxサービスの起動

    # systemctl restart php8.2-fpm.service
    # systemctl restart nginx
    

6. ブラウザで表示確認

image.png

7. 最後に

  • LPICでnginxの学習はしていたがこれまでの現場はApacheを採用している現場が多く、なかなか触れる機会がなかったので、今回触れられてよかった。おそらく情報が古いだろうが、以下の本はとても参考になるので、別記事でnginxについて掘り下げた記事を投稿したい
    nginx実践入門

  • https化に挑戦したい

8. 参考資料

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?