LINUX

[LINUX] NGINX + PHP7.0 + PHP-FPM 설치방법

chsr 2023. 8. 3. 17:40
728x90
반응형

■ NGINX + PHP7.0 + PHP-FPM 설치방법


■ 설치 및 업데이트

1.1. 업데이트

sudo yum update

1.2. NGINX 설치

sudo yum install nginx -y

1.3. PHP 7.0 설치 (+php-fpm, mysql 등)

sudo yum install php70 php70-fpm php70-mcrypt php70-xml php70-mcrypt php70-zip php70-xmlrpc php70-gd php70-curl php70-pdo php70-mysqlnd php70-mbstring php70-gmp

1.4. NGINX + PHP 재시작

sudo service nginx restart
sudo service php-fpm restart

1.5. NGINX + PHP 상태 체크

sudo service nginx status
sudo service php-fpm status

■ 구성

2.1. php-fpm

sudo vi /etc/php-fpm.d/www.conf

처음에 ; 추가 또는 주석 해제하기

[global]
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10s

[www]
listen = /var/run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0664
user = nginx
group = nginx

pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 200

php_admin_value[memory_limit] = 128M

php-fpm 재시작

sudo service php-fpm restart

2.2. nginx

sudo vi /etc/nginx/conf.d/virtual.conf

파일 구성 추가

server {
    listen 80;
    server_name mydomain.com;
    location / {
        root   /var/www/html/mydomain/public;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        root /var/www/html/mydomain/public;
        fastcgi_pass   unix:/var/run/php-fpm/www.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

nginx 재시작

sudo service nginx restart

■ 자주 발생하는 에러 체크

502 Bad Gateway NGINX or 502 Service Temporarily Overloaded

소유자 권한 확인

/var/run/php-fpm/www.sock

sudo chown -R nginx /var/run/php-fpm/www.sock

■ 추가 선택적 설치

1.1. composer 설치

cd ~
sudo curl -sS https://getcomposer.org/installer | sudo php
sudo mv composer.phar /usr/local/bin/composer

1.2. git 설치

sudo yum install git

 

 

참고

 

How to install NGINX + PHP7.1 + PHP-FPM in Amazon AMI EC2 for LARAVEL 5.x

No blah blah blah, let’s go to the point…

medium.com

 

728x90
반응형