IT/리눅스(Linux)

우분투(Ubuntu) 서버 / Nginx, PHP, MariaDB 설치하고 설정하기

MirDaTe 2021. 7. 2. 15:28
728x90

※ Nginx 설치

 

① Nginx를 설치합니다.

apt-get install nginx

 

② 만약 방화벽을 사용하고 있다면 포트를 Open해 줍니다.

ufw allow 'Nginx Full'

 

③ 서버 IP로 접속해 Nginx가 잘 동작하는지 확인합니다.

 

※ Nginx 시작, 정지 명령어 

 

① Nginx 시작

systemctl start nginx

 

② Nginx 정지

systemctl stop nginx

 

③ Nginx 재시작

systemctl restart nginx

 

④ Nginx 리로드

systemctl reload nginx

 

⑤ 시스템 부팅시 Nginx 자동 시작

systemctl enable nginx

 

⑥ 시스템 부팅시 Nginx 자동 시작 해제

systemctl disable nginx

 

※ PHP 설치 

 

① php-fpm을 설치합니다.

apt-get install php-fpm

 

② /etc/nginx/sites-available/default 수정 

#location ~ \.php$ {

# include snippets/fastcgi-php.conf;

#

# # With php-fpm (or other unix sockets):

# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

# # With php-cgi (or other tcp sockets):

# fastcgi_pass 127.0.0.1:9000;

 

#}

 

를 아래와 같이 수정 

 

location ~ \.php$ { 

  include snippets/fastcgi-php.conf;

#

# # With php-fpm (or other unix sockets):

  fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

# # With php-cgi (or other tcp sockets):

# fastcgi_pass 127.0.0.1:9000;

}

 

또한 index.php를 자동 인식하게 하려면

index index.html index.htm index.nginx-debian.html;

 

를 아래와 같이 수정

 

index index.html index.htm index.nginx-debian.html index.php;

 

③ php 정상동작 테스트

/var/www/html 내에 phpinfo.php를 만들고 아래코드를 입력하고 저장

 

<?php phpinfo(); ?>

 

웹브라우저로 서버IP/phpinfo.php 로 접속해 보면 정상동작 확인가능

 

※ MariaDB 설치 

 

① MariaDB와 php-mysql, php-gd을 설치합니다.

apt install mariadb-server php-mysql php-gd

 

② 설정

다음과 같이 명령하여 root 계정 비밀번호 등 몇 가지를 설정합니다.

mysql_secure_installation

 

③ 웹에서 root 계정 사용

웹에서 root 계정을 사용할 수 있게 하려면 수정해야 합니다. MariaDB에 접속합니다.

mysql -u root -p

 

다음을 차례대로 입력합니다.

 

use mysql;

update user set plugin='' where user='root';

flush privileges;

quit;