0
2

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 3 years have passed since last update.

CentOS7にnginx・PHP7・php-fpmをインストールするコマンド

Posted at

パッケージのアップデート

$ sudo yum update

wgetのインストール

$ sudo yum -y install wget

epel,remiレポジトリの登録

$ sudo yum -y install epel-release
$ wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
$ sudo rpm -ivh remi-release-7.rpm

タイムゾーンを日本時間にする

$ sudo timedatectl set-timezone Asia/Tokyo
# 確認
$ date

nginxをインストールする

$ sudo yum --enablerepo=epel install nginx

nginx設定ファイルを作成する

$ sudo vi /etc/nginx/conf.d/default.conf
default.conf
server {
  listen 80;
  server_name centos7;
  root /var/www;
  index index.php index.html index.htm;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
  }
}

nginx設定ファイルの最低限設定

sudo vi /etc/nginx/nginx.conf
nginx.conf
user  nginx;
worker_processes  auto;
worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  2048;
    multi_accept on;
    use epoll;
}


http {
    server_tokens off;
    include       /etc/nginx/mime.types;
    default_type  text/html;
    charset UTF-8;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile       off;
    tcp_nopush     on;
    tcp_nodelay    on;


    keepalive_timeout 10;
    client_header_timeout 10;
    client_body_timeout 10;
    reset_timedout_connection on;
    send_timeout 10;

    limit_conn_zone $binary_remote_addr zone=addr:5m;
    limit_conn addr 100;

    gzip on;
    gzip_http_version 1.0;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
    open_file_cache off;

    client_max_body_size 20m;
    server_names_hash_bucket_size 64;
    include /etc/nginx/conf.d/*.conf;
}

nginx設定ファイルの設定内容を確認する

$ nginx -t

nginxをサービス有効化する

$ sudo systemctl enable nginx

nginxを起動する

$ sudo systemctl start nginx

nginxの起動状態を確認する

$ sudo systemctl status nginx

PHP7をインストールする(php-fpmも併せてインストール)

$ sudo yum install --enablerepo=epel,remi-php72 php php-mbstring php-fpm php-mcrypt php-mysql php-pdo php-json php-xml

PHPのパスが通っていない場合、パスを通すこと

PHPのバージョン確認

$ php -v

php-fpmの設定

sudo vi /etc/php-fpm.d/www.conf
www.conf
user = nginx
group = nginx

listen = /var/run/php-fpm.sock
listen.owner = nginx
listen.group = nginx

php-fpmのサービス有効化

sudo systemctl enable php-fpm

php-fpmの起動

sudo systemctl start php-fpm

php-fpmの起動状態を確認する

sudo systemctl status php-fpm

WEBフォルダにphpinfo.phpを入れてPHPの動作を確認してください。

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?