rokkonet

PC・Androidソフトウェア・アプリの開発・使い方に関するメモ

ubuntu + nginx + mysql + php インストール

2020 Aug. 12.
2018 Sep. 15.
2018 Sep. 13.

Nginx PHP インストール
 
nginxインストール
# apt install nginx
 
上記参照元にしたがって、/etc/nginx/nginx.conf の http { }に client_max_body_size 32M; を書き込んだ。

 

http {

##
# Basic Settings
##

client_max_body_size 32M;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

 

 

nginx再起動

# systemctl restart nginx.service

 
phpインストール
# apt install php-fpm
# apt install php-mysql php-mbstring php-xml php-gd php-curl php-bcmath php-ldap mlocate
 
 
/etc/php/7.4/fpm/php.ini を参照元にしたがって編集した。
max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
post_max_size = 32M
max_input_time = 300
 
 
/etc/nginx/sites-available/default の server{ }を参照元にしたがって編集した。
 編集した行
  index index.php index.html index.htm index.nginx-debian.html;
 
 追加した行
  location ~ .php$ {
  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/var/run/php/php-fpm.sock;
  }
 
 次のmodsecurity行は よくわからないので記述せず。
  modsecurity on;
  modsecurity_rules_file /etc/nginx/modsec/main.conf;
 
全体

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
#index index.html index.htm index.nginx-debian.html;
index index.php index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

 

設定ファイル正誤確認

# nginx -t

 

php-fpm ( FastCGI Process Manager )を再起動する

# systemctl restart php7.4-fpm.service

 

nginxを再起動する

# service nginx restart
 

ファイアウォール設定

# ufw allow proto tcp from 192.168.1.0/255.255.255.0 to any port 80
# ufw allow proto tcp from 192.168.1.0/255.255.255.0 to any port 443
# ufw reload
 
 
下記のphpファイルを公開ディレクトリに置き、httpアクセスして表示を確認する。
<?php
phpinfo();
?>
 
 
(以下、旧文)
https://beautifulajax.dip.jp/?p=1825 より

関連ソフトインストール

# apt install nginx mysql-server
# systemctl start nginx
# apt install php php-fpm php-mysql php-gettext php-common php-mbstring php-mbstring

php設定

/etc/php/7.2/fpm/php.ini を編集する

  cgi.fix_pathinfo=0

/etc/php/7.2/fpm/pool.d/www.conf を編集する
  php_admin_value[memory_limit] = 128M

# service php7.2-fpm restart

nginx設定

 /etc/nginx/sites-available/default を編集する
  server {
  }
  の中に、下記を書き込む。

   # ディレクトリ内のファイル一覧を表示する場合
   autoindex on;

   location ~ \.php$ {
          try_files $uri =404;
          fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
   }



confファイルを編集する
 fastcgi_param PHP_VALUE "memory_limit = 128M";

 次の1行の内容の/var/www/html/phpinfo.phpファイルを作成する
  <?php phpinfo(); ?>
 

nginx起動

# systemctl restart nginx

http://NGINX-SERVER/xxx
"xxx" にでたらめな文字列を入れてhttp://NGINX-SERVERにアクセスし、nginxから404 Not Foundが送られてくることを確認する


404 Not Found


nginx/1.14.0 (Ubuntu)


http://NGINX-SERVER/phpinfo.php にアクセスしてphpinfo画面が表示されることを確認する 


mysqlインストール