Ubuntu 18.04 Server / Nginx, PHP, MariaDB 설치하고 설정하기

Nginx

설치

Nginx를 설치합니다.

# apt install nginx

만약 방화벽을 사용하고 있다면 포트를 열어줍니다.

# ufw allow 'Nginx Full'

서버 주소로 접속했을 때 다음과 같이 나오면 제대로 된 것입니다.

시작, 정지 등

Nginx를 시작합니다.

# systemctl start nginx

Nginx를 멈춥니다.

# systemctl stop nginx

Nginx를 재시작합니다.

# systemctl restart nginx

Nginx를 다시 로드합니다.

# systemctl reload nginx

Nginx를 설치하면 부팅 시 자동으로 시작하게 설정됩니다. 만약 자동 시작을 해제하고 싶다면 다음과 같이 명령합니다.

# systemctl disable nginx

자동 시작하도록 하려면 다음과 같이 명령합니다.

# systemctl enable nginx

PHP

설치

php-fpm을 설치합니다.

# apt 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.php를 추가합니다.

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

Nginx를 다시 로드 해야 적용됩니다.

# service nginx reload

테스트

/var/www/html/ 디렉토리에 phpinfo.php를 만들고 다음 코드를 입력하고 저장합니다.

<?php phpinfo(); ?>

웹브라우저로 server-ip/phpinfo.php로 접속했을 때 다음과 같이 나오면 제대로 된 것입니다.

MariaDB

설치

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

# apt install mariadb-server php-mysql

설정

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

# mysql_secure_installation

웹에서 root 계정 사용

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

# mysql -uroot -p

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

use mysql;
update user set plugin='' where user='root';
flush privileges;
quit;
같은 카테고리의 다른 글

Ubuntu 20.04 Server / 고정 IP 설정하는 방법

네트워크 설정 파일은 /etc/netplan 디렉토리 안에 있는 yaml 파일이다. DHCP로 설치했다면, 설정 파일 내용은 다음과 비슷하게 되어 있다. # This is the network config written by 'subiquity' network: ethernets: enp0s3: dhcp4: true version: 2 다음과 같이 수정하고 저장한다. IP 등은 네트워크 환경에 맞게 적절히 ...

Ubuntu Server / do-release-upgrade / 버전 업그레이드 명령어

Ubuntu 새 버전이 나오면 어떻게 업그레이드를 할까? 새로 설치하고 다시 설정하는 게 제일 좋지만, 설정할 게 많다면 바로 업그레이드를 할 수도 있다. 업그레이드는 do-release-upgrade 명령어로 한다. do-release-upgrade -h Usage: do-release-upgrade Options: -h, --help show this help message and exit -V, ...

Ubuntu 20.04 Desktop / 설치하기

Ubuntu 20.04 Desktop / 설치하기

다음은 Ubuntu 20.04 Desktop을 설치하는 과정입니다. Windows를 설치하는 것만큼 쉽고, 시간도 오래 걸리지 않습니다. Ubuntu Desktop을 다운로드하고 설치용 CD 또는 USB를 만듭니다. Rufus를 사용하면 편합니다. 컴퓨터에 설치용 미디어를 장착하고 부팅합니다. 잠시 기다리면... GUI로 설치를 시작합니다. 언어를 한국어로 정하고 를 클릭합니다. 키보드 레이아웃을 정하고 를 클릭합니다. 일반 설치와 최소 설치 중 하나를 선택합니다. 최소 설치를 하고 나중에 ...

Ubuntu Server / 22.04 / 네트워크 세팅에 이더넷(Wired) 보이지 않을 때 해결 방법

Ubuntu Server / 22.04 / 네트워크 세팅에 이더넷(Wired) 보이지 않을 때 해결 방법

우분투 설정의 네트워크에 Wired가 보이지 않는다. 그것이 보여야 GUI로 IP 설정이 가능한데 말이다. 이를 보이게 하는 방법이 여러 가지가 있는 거 같은데, 내가 성공한 방법은... /etc/netplan/00-installer-config.yaml의 내용은 다음처럼 생겼을 것이다. # This is the network config written by 'subiquity' network: ethernets: eth0: dhcp4: true ...

Ubuntu 16.04 / Apache / javascript 폴더 접근이 안되는 문제 해결하는 방법

javascript 폴더 접근 불가 우분투(Ubuntu)에서 아파치(Apache)로 웹서버를 운영할 때 이상한 문제가 하나 발생합니다. 사이트 경로에 javascript가 있으면 forbidden 에러가 나는 것입니다. Forbidden You don't have permission to access /javascript/ on this server. 이 문제가 발생하는 이유는 자바스크립트 설정 때문입니다. /etc/apache2/conf-available/javascript-common.conf에 다음과 같은 코드가 있습니다. Alias /javascript /usr/share/javascript/ javascript로 접속하면 /usr/share/javascript/로 연결시키라는 뜻입니다. 사이트 접속자는 /usr/share/javascript/에 접속 권한이 없으므로 forbidden 에러가 ...

Ubuntu 18.04 Server / phpMyAdmin 설치하는 방법

Ubuntu 18.04 Server / phpMyAdmin 설치하는 방법

phpMyAdmin은 MySQL, MariaDB를 웹브라우저에서 관리할 수 있게 해주는 소프트웨어입니다. Ubuntu 18.04에 phpMyAdmin을 설치하고 설정하는 방법을 알아보겠습니다. 설치 apt install phpmyadmin 설치하는 과정에서 몇 가지 질문을 합니다. 사용하는 웹서버를 선택합니다. 비밀번호를 정하고... 다시 한 번 입력합니다. Yes를 선택하고 진행하면 설치가 끝납니다. 접속 웹브라우저로 서버 주소에 phpmyadmin을 붙여서 접속합니다. MySQL 또는 MariaDB의 사용자명과 암호를 입력해서 로그인하는데... root 계정으로 접속이 불가능할 수도 있습니다. 만약 root으로 ...

Ubuntu 20.04 Server / GUI 설치하는 방법

Ubuntu 20.04 Server / GUI 설치하는 방법

Ubuntu Server는 CLI(Command Line Interface) 환경으로 설치된다. 그런데 어떤 작업은 GUI(Graphical Uer Interface) 환경에서 하는 것이 편하다. 만약 GUI 환경이 필요하다면 설치하여 사용할 수 있다. GUI 패키지에는 kubuntu-desktop lubuntu-desktop ubuntu-desktop ubuntu-desktop-minimal xubuntu-desktop 등이 있다. 주로 ubuntu-desktop 또는 ubuntu-desktop-minimal을 사용하는 듯 하다. 예를 들어 ubuntu-desktop-minimal을 설치한다면, 다음과 같이 명령하면 된다. # apt install ubuntu-desktop-minimal Minimal임에도 불구하고 꽤 많은 저장소 공간이 필요하다. After ...

Ubuntu Server 22.04 / vsftpd로 FTP 서버 구축하기

vsftpd vsftpd(Very Secure FTP Daemon)는 유닉스와 리눅스에서 사용할 수 있는 가벼운 FTP 서버입니다. 주요 특징은 다음과 같습니다. Virtual IP configurations Virtual users Standalone or inetd operation Powerful per-user configurability Bandwidth throttling Per-source-IP configurability Per-source-IP limits IPv6 Encryption support through SSL integration 설치 vsftpd는 우분투 패키지에 포함되어 있으므로 다음과 같이 명령하여 설치할 수 있습니다. # apt install vsftpd 방화벽을 사용 중이라면 다음과 같이 명령하여 포트를 ...

Ubuntu 18.04 / 메모

SSH 설정 설정 파일 /etc/ssh/sshd_config 포트 변경하기 다음 코드를 #Port 22 다음처럼 바꾼다. Port 1234 포트 번호는 자신이 원하는 것으로... root 계정 로그인 가능하게 만들기 다음 코드를 #PermitRootLogin prohibit-password 다음처럼 만든다. PermitRootLogin yes 설정 변경 적용하기 service ssh restart

Ubuntu 18.04 Server / 시간대(time zone) 설정하는 방법

Ubuntu 18.04 Server / 시간대(time zone) 설정하는 방법

현재 서버의 시간대 확인 현재 서버에 설정된 시간대는 date 명령어로 확인할 수 있다. # date 시간대 설정 방법 1 - dpkg-reconfigure tzdata 시간대를 설정하고 싶다면 다음과 같이 명령한다. # dpkg-reconfigure tzdata 한국이라면 Asia를 선택하고 Seoul을 선택합니다. 시간대 설정 방법 2 - tzselect tzselect 명령으로 설정할 수 있다. 번호를 입력하여 시간대를 정한다. # tzselect Please identify a location so that time ...