OS

클라우드 VPS에 LAMP 구축(feat. vultr.com)

옥수수빵 2026. 8. 27. 16:53
728x90

클라우드 VPS를 신청해서 간단하게 Apache(Nginx도 됨), Mariadb(MySQL도 됨), PHP까지 설치하는 걸 진행해 보겠습니다.

저 같은 경우는 어차피 스터디 목적이면서 최대한 다른 곳과 거의 동일하게 하기 위해서 Laravel, Docker는 쓰지 않겠습니다.

 

1. Create Instance

사양이 여러 가지가 있겠지만 위에서도 언급했듯이 스터디 목적이기에 최대한 방해가 되지 않는 최소 사양으로 진행하겠습니다.

  • CPU : 1 vCPU(앞에서 언급했듯이 스터디 목적이기 때문에 굳이 비싼 금액을 낼 필요가 없어서 Shared CPU를 선택했습니다. 참고로 CPU 앞에 붙는 "v"는 Virtual(가상)의 약자로, 물리 CPU 코어 하나를 여러 사용자가 가상으로 나눠 쓴다는 의미입니다. 과거 고시원을 떠올리시면 편할 겁니다. 방 하나를 두 개로 쪼개서 마치 방이 두 개인 것처럼... 그래서 한 명이 과도하게 CPU 자원을 쓴다면 쫓겨날 수도 있습니다.
  • RAM : 1024MB
  • Storage : 25GB(SSD)
  • OS : Ubuntu 24.04 LTS x64

2. 웹 서버 설치하기

Nginx도 있지만 저는 Apache를 설치하도록 하겠습니다. 이유는 딱 한 가지입니다. 현재 계정에 설치하려는 빌더가 .htaccess를 사용하는 Codeigniter4이기 때문입니다. Nginx도 당연히 유사한 기능이 있지만 그러기 위해서는 해당 빌더를 수정해야 하기에 그런 수고스러움을 굳이 감수하지 않겠습니다! 무엇보다 실제로 클라이언트가 구매해 놓은 환경과 동일하게 설치를 해야 합니다.

root@test-server:~# apt update
Hit:1 http://ubuntu.mirror.constant.com noble InRelease
Get:2 http://ubuntu.mirror.constant.com noble-updates InRelease [126 kB]
Get:3 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
... 생략 ...
Get:24 http://security.ubuntu.com/ubuntu noble-security/universe amd64 Components [76.3 kB]
Get:25 http://security.ubuntu.com/ubuntu noble-security/multiverse Translation-en [11.1 kB]
Fetched 10.8 MB in 5s (2,364 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
32 packages can be upgraded. Run 'apt list --upgradable' to see them.

ssh로 접속을 해서 apt update 명령어를 입력해서 현재 어떤 패키지들이 어떤 버전으로 있는지를 확인합니다.

이 명령어를 입력한다 해서 실제 패키지를 업데이트를 하는 건 아닙니다.

쇼핑하기 전에 카탈로그를 보면서 현재 이 매장에 어떤 최신 상품이 있는지 눈으로 먼저 보는 거라 생각하시면 편할 것 같네요. 아! 그게 뭐가 중요하냐고 할 수도 있는데 중요합니다. 왜냐하면 이 명령어를 입력하는 순간 과거 목록은 사라지고 가장 최신 목록으로 받는다고 보시면 됩니다. 브라우저로 치면 Ctrl + F5(강력 새로 고침)와 같다고 생각하시면 됩니다.

root@test-server:~# apt install -y apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
           apache2-bin apache2-data libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.4-0 ssl-cert
Suggested packages:
           apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
The following NEW packages will be installed:
           apache2 apache2-bin apache2-data libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.4-0 ssl-cert
0 upgraded, 7 newly installed, 0 to remove and 32 not upgraded.
Need to get 1,796 kB of archives.
After this operation, 7,219 kB of additional disk space will be used.
... 생략 ...
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.

이제 apt install -y apache2 명령어를 입력해서 Apache를 설치합니다.

Apache가 정상적으로 설치가 되었는지 봅니다.

root@test-server:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
         Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
           Active: active (running) since Thu 2026-08-27 08:09:39 UTC; 6min ago
             Docs: https://httpd.apache.org/docs/2.4/
      Main PID: 2517 (apache2)
            Tasks: 55 (limit: 1011)
        Memory: 5.7M (peak: 5.9M)
             CPU: 77ms
        CGroup: /system.slice/apache2.service
                     ├─2517 /usr/sbin/apache2 -k start
                     ├─2522 /usr/sbin/apache2 -k start
                     └─2524 /usr/sbin/apache2 -k start
Aug 27 08:09:38 test-server systemd[1]: Starting apache2.service - The Apache HTTP Server...
Aug 27 08:09:39 test-server apachectl[2502]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this m>
Aug 27 08:09:39 test-server systemd[1]: Started apache2.service - The Apache HTTP Server.
lines 1-16/16 (END)

systemctl status apache2 명령어를 입력하면 위와 같은 화면이 나옵니다.

4번째 줄을 보면 active (running)이라고 나옵니다.

정상적으로 실행 중입니다.

그래도 아직 브라우저에 해당 서버의 아이피를 입력해도 접속이 안 될 겁니다.

root@test-server:~# ufw status
Status: active

To                  Action             From
--                   ------               ----
22/tcp            ALLOW         Anywhere
22/tcp (v6)     ALLOW         Anywhere (v6)

ufw status 명령어를 입력해서 확인해 보니 80번 포트가 없습니다.

root@test-server:~# ufw allow 80/tcp
Rule added
Rule added (v6)
root@test-server:~# ufw status
Status: active
To                  Action             From
--                   ------               ----
22/tcp            ALLOW         Anywhere
80/tcp            ALLOW         Anywhere
22/tcp (v6)     ALLOW         Anywhere (v6)
80/tcp (v6)     ALLOW         Anywhere (v6)

ufw allow 80/tcp 명령어로 80번 포트도 추가해 주고 다시 한 번 ufw status 명령어로 정상적으로 추가가 되었는지 확인해 보면 됩니다.

이제 "http://자신의아이피"를 브라우저 주소창에 입력했을 때 유명한 "It works"가 뜬다면 Apache는 정상적으로 설치가 되었다는 의미입니다.

3. DB(MariaDB) 설치하기

root@test-server:~# apt install -y mariadb-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
... 생략 ...
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.

Apache처럼 작동 중인지 확인하는 명령어는 systemctl status mariadb입니다.

결과는 위 Apache와 모양이 대동소이하므로 생략하겠습니다.

4. DB 보안 설정(MySQL, MariaDB 포함)

root@test-server:~# mysql_secure_installation
... 생략 ...
Enter current password for root (enter for none): Enter
Switch to unix_socket authentication [Y/n] Enter
Change the root password? [Y/n] Enter
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Enter
Disallow root login remotely? [Y/n] Enter
Remove test database and access to it? [Y/n] Enter
Reload privilege tables now? [Y/n] Enter
  • Enter current password for root (enter for none): 여기에서는 Enter를 치면 됩니다. 다른 문자를 치는 순간 Access denied 뜨니까 그냥 Enter 치세요.
  • Switch to unix_socket authentication [Y/n] Enter를 치면 됩니다. 이게 뭘 의미하는 거냐면 콘솔에서 mysql에 접속하려면 원래는 mysql -uroot -p패스워드 이렇게 입력해야 하는데 이미 ssh root@host를 입력해서 리눅스를 접속했으니 재인증 안 하겠다는 의미입니다. 쉽게 말해 mysql만 입력하면 mysql에 접속이 되는 겁니다.
  • Change the root password? [Y/n] 패스워드를 설정하는 겁니다. Enter를 치시면 됩니다.
  • New password: MySQL 접속 시 쓸 패스워드를 입력하시면 됩니다.
  • Re-enter new password: 다시 한 번 입력!
  • Remove anonymous users? [Y/n] MySQL(MariaDB 포함)를 설치하면 기본적으로 사용자명이 빈 문자열("")인 계정이 생성됩니다. 테스트 목적으로 생성이 된다고 하지만 이건 보안에 엄청난 구멍이므로 삭제해야 합니다. 참고로 mysql -u babo라고 입력해도 접속이 됩니다. babo라는 유저는 없지만 익명 계정 규칙에 의해서 로그인이 딱! Enter를 쳐서 삭제!
  • Disallow root login remotely? [Y/n] 이것도 기본적으로 외부에서 접근이 가능한데 그걸 막겠냐는 것입니다. 다른 콘솔에서 접속해서 mysql -h서버의아이피 -uroot -p 이런 식으로 입력 자체를 아예 막는다는 것입니다. 참고로 이건 프로그래밍(PHP 예로)에서 mysqli_connect('서버의 아이피' <-- 이 부분까지도 막습니다. 당연히 Enter
  • Remove test database and access to it? [Y/n] test 데이터베이스를 삭제하겠냐는 것입니다. 보통 처음 설치를 하면 test라는 데이터베이스가 같이 생성이 됩니다. 써 본 적도 없고 사실 있어도 쓰겠다는 생각도 안 듭니다. Enter
  • Reload privilege tables now? [Y/n] 보통 계정을 생성해서 권한을 주고 그런 후에 "새로 고침" 같은 걸 해야 합니다. FLUSH PRIVILEGES; 그 명령어가 이건데 여기에서 Enter를 치시면 같은 역할을 하게 됩니다.

5. PHP 설치하기

root@test-server:~# apt install -y software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
software-properties-common is already the newest version (0.99.49.4).
software-properties-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.

apt install -y software-properties-common 명령어를 입력하세요.
이게 뭘 하는 명령어냐면 이거 다음에 할 apt update 명령어를 치면 나오는 목록에 php7.4를 추가할 수 있게 하는 패키지라 보시면 됩니다. 우분투 공식 저장소(ubuntu.mirror.constant.com)에 있는 건 우분투가 아직 자기네들 공간(?)에 올려도 괜찮다 싶은 소프트웨어만 있습니다.

제가 다운로드 하려는 php7.4의 경우는 EOL이 끝나도 한참 전에 끝났습니다.

당연히 공식 저장소엔 없겠지요. 그래서 이런 소프트웨어들을 개인 혹은 커뮤니티에서 관리해 주는 외부 저장소(PPA)가 있는데 그 중 하나가 ondrej/php입니다.
이 글 상단에 2. 웹 서버 설치하기 부분에 보시면 apt update 명령어를 입력한 후 밑에 주르륵 나오는 것들에 끼워 넣는 작업을 하는 패키지를 설치하는 게 이번 순서라 보시면 됩니다. 사실 몰라도 됩니다.

root@test-server:~# add-apt-repository ppa:ondrej/php
PPA publishes dbgsym, you may need to include 'main/debug' component
Repository: 'Types: deb
URIs: https://ppa.launchpadcontent.net/ondrej/php/ubuntu/
Suites: noble
Components: main
'
Description:
This repository is in process of being merged into https://packages.sury.org/php/;

For Ubuntu Resolute, https://packages.sury.org/php/ is the canonical way of getting PHP packages, for previous releases, I will provide a simple way how to migrate to the new repositories in upcoming weeks, you can still use this repository for Ubuntu Jammy and Ubuntu Noble.
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
Hit:1 http://ubuntu.mirror.constant.com noble InRelease
Hit:2 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:3 http://ubuntu.mirror.constant.com noble-updates InRelease
Hit:4 http://ubuntu.mirror.constant.com noble-backports InRelease
Get:5 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble InRelease [24.3 kB]
Get:6 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages [179 kB]
Get:7 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main Translation-en [43.7 kB]
Fetched 247 kB in 3s (78.1 kB/s)
Reading package lists... Done

add-apt-repository ppa:ondrej/php 명령어를 입력합니다.

설치해야 할 목록에 끼워 넣어 줍니다.

root@test-server:~# apt update
Hit:1 http://ubuntu.mirror.constant.com noble InRelease
Hit:2 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:3 http://ubuntu.mirror.constant.com noble-updates InRelease
Hit:4 http://ubuntu.mirror.constant.com noble-backports InRelease
Get:5 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble InRelease [24.3 kB]
Fetched 24.3 kB in 2s (13.2 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
20 packages can be upgraded. Run 'apt list --upgradable' to see them.

apt update 명령어를 입력해서 카탈로그를 강력하게 새로 고침을 합니다.

root@test-server:~# apt install -y php7.4 php7.4-mysqli php7.4-mbstring php7.4-curl php7.4-xml php7.4-zip libapache2-mod-php7.4
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
... 생략 ...
User sessions running outdated binaries:
 root @ session #121: sshd[8489]
 root @ user manager service: systemd[8494]

No VM guests are running outdated hypervisor (qemu) binaries on this host.

apt install -y php7.4 php7.4-mysqli php7.4-mbstring php7.4-curl php7.4-xml php7.4-zip libapache2-mod-php7.4 명령어를 입력합니다. 제가 설치해야 할 php7.4 버전에 맞는 패키지들도 같이 설치를 해 줍니다.

root@test-server:~# php -v
PHP 7.4.33 (cli) (built: Jul  3 2026 06:09:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
root@test-server:~# apache2ctl -M | grep php
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
 php7_module (shared)

php -v, apache2ctl -M | grep php 명령어를 각각 입력해서  정확히 해당 버전이 설치가 되었는지, Apache가 PHP 모듈을 제대로 인식하고 있는지를 확인해 봅니다.

반응형