우분투18에 nginx16 + PHP7.4-FPM 설치

1 개요[ | ]

우분투18에 nginx16 + PHP7.4-FPM 설치

2 설치[ | ]

provision.sh
apt update
apt install -y curl gnupg2 ca-certificates lsb-release software-properties-common
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
apt update
add-apt-repository ppa:ondrej/php -y
apt update
apt install -y nginx php7.4-fpm php7.4-cli php7.4-bcmath php7.4-dev php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.4-mbstring php7.4-curl php7.4-gd php7.4-mysql php7.4-zip php7.4-intl php7.4-xml php-pear

cat <<EOF > /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts\$fastcgi_script_name;
        include        fastcgi_params;
    }
}
EOF

usermod -a -G www-data nginx
systemctl restart php7.4-fpm
systemctl restart nginx

mkdir -p /scripts
cat <<EOF > /scripts/info.php
<?php
phpinfo();
EOF
→ /scripts/info.php 는 테스트용이므로 설치 확인 후 삭제하자.

3 확인[ | ]

root@localhost:~# curl -s localhost/info.php | grep 'PHP Version' | tail -1
<tr><td class="e">PHP Version </td><td class="v">7.4.1 </td></tr>
root@localhost:~# apt list nginx php7.4-fpm
Listing... Done
nginx/stable,now 1.16.1-1~bionic amd64 [installed]
php7.4-fpm/bionic,now 7.4.1-1+ubuntu18.04.1+deb.sury.org+1 amd64 [installed]
root@localhost:~# ps -ef | egrep 'php|nginx' | grep -v grep
root     22935  3126  0 16:31 pts/0    00:00:00 tail -f /var/log/nginx/error.log
root     22943     1  0 16:31 ?        00:00:00 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
www-data 22965 22943  0 16:31 ?        00:00:00 php-fpm: pool www
www-data 22966 22943  0 16:31 ?        00:00:00 php-fpm: pool www
root     22981     1  0 16:31 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx    22982 22981  0 16:31 ?        00:00:00 nginx: worker process
root@localhost:~# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22981/nginx: master 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      668/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1044/sshd           
tcp6       0      0 :::22                   :::*                    LISTEN      1044/sshd
root@localhost:~# cat /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }
}
root@localhost:~# cat /etc/php/7.4/fpm/pool.d/www.conf | grep -v \; | grep -v ^$
[www]
user = www-data
group = www-data
listen = /run/php/php7.4-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}