7. 오라클 클라우드에서 우분투 LEMP - Nginx 서버에 PHP7 설치하기

2020. 6. 2. 06:30Oracle Cloud

반응형

Contents

0. 오라클 클라우드에서 Ubuntu LEMP(Linux+Nginx+MariaDB+PHP7)에 WORDPRESS 설치하기
1. 오라클 클라우드 무료 가입 (Oracle Cloud Free Tier)하기
2. 오라클 클라우드에서 Ubuntu(우분투) 인스턴스 서버 생성하기 (네트워크 셋팅을 포함)
3. 오라클 클라우드 SSH 접속 및 SFTP 등 서버 접속 환경 설정하기
4. 오라클 클라우드 우분투 서버 환경 설정하기
5. Nginx 서버 설치하기
6. Linux 폴더 권한 설정 확인하기
7. Nginx 서버에 PHP7 설치하기
8. MariaDB 설치하기
9. phpMyAdmin 설치하기
10. 도메인 연결하기
11. sendmail 설치하기
12. HTTPS 적용을 위한 SSL 인증서 발급받기
13. DB 생성하기
14. Wordpress 설치하기
15. Wordpress 설치 후 서버 및 Wordpress 환경 설정하기

* 해당 내용은 오라클 제품을 다루고 있지만 이는 개인적인 테스트 결과이며, 오라클 공식 문서는 아님을 미리 밝힙니다.


우리가 설치할 워드프레스(WORDPRESS)는 php기반에서 동작합니다.

php는 여러 버전이 있는데 많이 사용하는 것은 php5버전과 php7버전으로 나누어 지는 듯 합니다. 워드프레스는 보안상 php7을 추천하고 있어 여기서는 php7을 기반으로 설치해 보겠습니다.

7-1. 현재 서버 상태를 확인합니다.

명령창에 sudo apt-cache policy php 라고 입력합니다.

ubuntu@wordpress:~$ sudo apt-cache policy php

서버 설치를 도와줄 apt 프로그램의 캐시 정책에 php부분을 확인해봅니다.

현재 인스톨은 되어 있지 않으며 7.2 버전에 대한 설치 정보를 가지고 있다고 합니다.

2020년 5월 30일 기준으로 최신 버전은 7.4 버전입니다.

php:
  Installed: (none)
  Candidate: 1:7.2+60ubuntu1
  Version table:
     1:7.2+60ubuntu1 500
        500 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

7-2. 그럼 최신 버전의 php를 설치하기 위하여 apt 정책을 최신으로업데이트 해 보겠습니다.

명령창에 sudo add-apt-repository ppa:ondrej/php 라고 입력합니다.

ubuntu@wordpress:~$ sudo add-apt-repository ppa:ondrej/php
 Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or Ctrl-c to cancel adding it.
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:3 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic InRelease
Get:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease [20.8 kB]
Get:5 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 Packages [52.1 kB]
Get:7 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:8 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [949 kB]
Get:9 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main Translation-en [24.9 kB]
Get:10 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1076 kB]
Fetched 2375 kB in 4s (550 kB/s)
Reading package lists... Done
ubuntu@wordpress:~$ sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:2 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
Hit:5 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:6 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done

중간에 Press [ENTER] to continue or Ctrl-c to cancel adding it. 라고 나오는데 docker 등 필수 패키지 정보를 설치하겠다는 겁니다. 여기서 ENTER를 누르시면 됩니다.

7-3. 그 다음 apt-get도 업데이트 합니다.

명령창에 sudo apt-get update 라고 입력합니다.

ubuntu@wordpress:~$ sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:2 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease
Hit:5 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:6 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done

7-4. 그 다음 서버의 php에 대한 apt 캐시 정책을 재확인합니다.

명령창에 다시 한번 sudo apt-cache policy php 라고 입력합니다.

ubuntu@wordpress:~$ sudo apt-cache policy php
php:
  Installed: (none)
  Candidate: 2:7.4+76+ubuntu18.04.1+deb.sury.org+9
  Version table:
     2:7.4+76+ubuntu18.04.1+deb.sury.org+9 500
        500 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 Packages
     1:7.2+60ubuntu1 500
        500 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

최신 버전이 7.4로 확인이 됩니다.

7-5. 저희는 최신 버전의 php7 (php7.4)을 설치해 보겠습니다.

명령창에 sudo apt-get install php7.4-fpm 라고 입력합니다.

혹시 기타 7.2나 7.0 버전을 설치하시고자 하시면 php7.2-fpm이나 php7.0-fpm으로 변경하여 입력하시면 됩니다.

중간에 After this operation, 18.7 MB of additional disk space will be used. 라고 물으며 이어서 할 것이냐고 묻습니다.
Do you want to continue? [Y/n]

여기서 Y를 하시면 됩니다.

그럼   libpcre2-8-0 libsodium23 php-common php7.4-cli php7.4-common php7.4-fpm php7.4-json php7.4-opcache php7.4-readline 가 설치됩니다.

ubuntu@wordpress:~$ sudo apt-get install php7.4-fpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  grub-pc-bin
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
  libpcre2-8-0 libsodium23 php-common php7.4-cli php7.4-common php7.4-json
  php7.4-opcache php7.4-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libpcre2-8-0 libsodium23 php-common php7.4-cli php7.4-common php7.4-fpm
  php7.4-json php7.4-opcache php7.4-readline
0 upgraded, 9 newly installed, 0 to remove and 7 not upgraded.
Need to get 4385 kB of archives.
After this operation, 18.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 libpcre2-8-0 amd64 10.34-7+ubuntu18.04.1+deb.sury.org+1 [196 kB]
Get:2 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 libsodium23 amd64 1.0.18-1+ubuntu18.04.1+deb.sury.org+1 [150 kB]
Get:3 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php-common all 2:76+ubuntu18.04.1+deb.sury.org+9 [15.7 kB]
Get:4 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-common amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [1000 kB]
Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-json amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [18.6 kB]
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-opcache amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [196 kB]
Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-readline amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [12.2 kB]
Get:8 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-cli amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [1393 kB]
Get:9 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-fpm amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [1404 kB]
Fetched 4385 kB in 28s (154 kB/s)
Selecting previously unselected package libpcre2-8-0:amd64.
(Reading database ... 101319 files and directories currently installed.)
Preparing to unpack .../0-libpcre2-8-0_10.34-7+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking libpcre2-8-0:amd64 (10.34-7+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package libsodium23:amd64.
Preparing to unpack .../1-libsodium23_1.0.18-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking libsodium23:amd64 (1.0.18-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php-common.
Preparing to unpack .../2-php-common_2%3a76+ubuntu18.04.1+deb.sury.org+9_all.deb ...
Unpacking php-common (2:76+ubuntu18.04.1+deb.sury.org+9) ...
Selecting previously unselected package php7.4-common.
Preparing to unpack .../3-php7.4-common_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.4-common (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-json.
Preparing to unpack .../4-php7.4-json_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.4-json (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-opcache.
Preparing to unpack .../5-php7.4-opcache_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.4-opcache (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-readline.
Preparing to unpack .../6-php7.4-readline_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.4-readline (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-cli.
Preparing to unpack .../7-php7.4-cli_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.4-cli (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-fpm.
Preparing to unpack .../8-php7.4-fpm_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php7.4-fpm (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Setting up libsodium23:amd64 (1.0.18-1+ubuntu18.04.1+deb.sury.org+1) ...
Setting up php-common (2:76+ubuntu18.04.1+deb.sury.org+9) ...
Created symlink /etc/systemd/system/timers.target.wants/phpsessionclean.timer → /lib/systemd/system/phpsessionclean.timer.
Setting up libpcre2-8-0:amd64 (10.34-7+ubuntu18.04.1+deb.sury.org+1) ...
Setting up php7.4-common (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/calendar.ini with new version

Creating config file /etc/php/7.4/mods-available/ctype.ini with new version

Creating config file /etc/php/7.4/mods-available/exif.ini with new version

Creating config file /etc/php/7.4/mods-available/fileinfo.ini with new version

Creating config file /etc/php/7.4/mods-available/ffi.ini with new version

Creating config file /etc/php/7.4/mods-available/ftp.ini with new version

Creating config file /etc/php/7.4/mods-available/gettext.ini with new version

Creating config file /etc/php/7.4/mods-available/iconv.ini with new version

Creating config file /etc/php/7.4/mods-available/pdo.ini with new version

Creating config file /etc/php/7.4/mods-available/phar.ini with new version

Creating config file /etc/php/7.4/mods-available/posix.ini with new version

Creating config file /etc/php/7.4/mods-available/shmop.ini with new version

Creating config file /etc/php/7.4/mods-available/sockets.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvmsg.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvsem.ini with new version

Creating config file /etc/php/7.4/mods-available/sysvshm.ini with new version

Creating config file /etc/php/7.4/mods-available/tokenizer.ini with new version
Setting up php7.4-opcache (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/opcache.ini with new version
Setting up php7.4-readline (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/readline.ini with new version
Setting up php7.4-json (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/json.ini with new version
Setting up php7.4-cli (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar7.4 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar7.4 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/7.4/cli/php.ini with new version
Setting up php7.4-fpm (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/fpm/php.ini with new version
Created symlink /etc/systemd/system/multi-user.target.wants/php7.4-fpm.service → /lib/systemd/system/php7.4-fpm.service.
Processing triggers for systemd (237-3ubuntu10.41) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for php7.4-cli (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Processing triggers for php7.4-fpm (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

7-6. 그 다음으로 그 외 자주 쓰이는 php 모듈을 설치해 보겠습니다.

명령창에 sudo apt-get install php7.4-curl php7.4-gd php7.4-mysql php7.4-mbstring php7.4-xml php7.4-zip php7.4-imagick php7.4-bcmath -y zip unzip 를 입력합니다.

여기서도 마찮가지로 After this operation, 3509 kB of additional disk space will be used. 라고 물으며 이어서 설치 할 것인지 묻습니다.
Do you want to continue? [Y/n] 이렇게 나오면 Y를 선택합니다.

* php7.4-xml php7.4-zip php7.4-imagick php7.4-bcmath -y 항목을 나중에 추가하여 아래 내용에는 나타나지 않습니다. 해당 부분을 포함하여 명령창에 입력하세요.!

ubuntu@wordpress:~$ sudo apt-get install php7.4-curl php7.4-gd php7.4-mysql php7.4-mbstring php7.4-xml php7.4-zip php7.4-imagick php7.4-bcmath -y zip unzip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  grub-pc-bin
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
  libonig4
The following NEW packages will be installed:
  libonig4 php7.4-curl php7.4-gd php7.4-mbstring php7.4-mysql unzip zip
0 upgraded, 7 newly installed, 0 to remove and 7 not upgraded.
Need to get 1027 kB of archives.
After this operation, 3509 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic/universe am                                d64 libonig4 amd64 6.7.0-1 [119 kB]
Get:2 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-curl a                                md64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [30.9 kB]
Get:3 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-gd amd                                64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [27.4 kB]
Get:4 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic/main amd64                                 unzip amd64 6.0-21ubuntu1 [167 kB]
Get:5 http://ap-seoul-1-ad-1.clouds.archive.ubuntu.com/ubuntu bionic/main amd64                                 zip amd64 3.0-11build1 [167 kB]
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-mbstri                                ng amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [397 kB]
Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 php7.4-mysql                                 amd64 7.4.6-1+ubuntu18.04.1+deb.sury.org+1 [118 kB]
Fetched 1027 kB in 6s (177 kB/s)
Selecting previously unselected package libonig4:amd64.
(Reading database ... 101478 files and directories currently installed.)
Preparing to unpack .../0-libonig4_6.7.0-1_amd64.deb ...
Unpacking libonig4:amd64 (6.7.0-1) ...
Selecting previously unselected package php7.4-curl.
Preparing to unpack .../1-php7.4-curl_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64                                .deb ...
Unpacking php7.4-curl (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-gd.
Preparing to unpack .../2-php7.4-gd_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd64.d                                eb ...
Unpacking php7.4-gd (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-mbstring.
Preparing to unpack .../3-php7.4-mbstring_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_a                                md64.deb ...
Unpacking php7.4-mbstring (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package php7.4-mysql.
Preparing to unpack .../4-php7.4-mysql_7.4.6-1+ubuntu18.04.1+deb.sury.org+1_amd6                                4.deb ...
Unpacking php7.4-mysql (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Selecting previously unselected package unzip.
Preparing to unpack .../5-unzip_6.0-21ubuntu1_amd64.deb ...
Unpacking unzip (6.0-21ubuntu1) ...
Selecting previously unselected package zip.
Preparing to unpack .../6-zip_3.0-11build1_amd64.deb ...
Unpacking zip (3.0-11build1) ...
Setting up libonig4:amd64 (6.7.0-1) ...
Setting up unzip (6.0-21ubuntu1) ...
Setting up php7.4-gd (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/gd.ini with new version
Setting up php7.4-mysql (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/mysqlnd.ini with new version

Creating config file /etc/php/7.4/mods-available/mysqli.ini with new version

Creating config file /etc/php/7.4/mods-available/pdo_mysql.ini with new version
Setting up zip (3.0-11build1) ...
Setting up php7.4-mbstring (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/mbstring.ini with new version
Setting up php7.4-curl (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

Creating config file /etc/php/7.4/mods-available/curl.ini with new version
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for php7.4-fpm (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...
Processing triggers for php7.4-cli (7.4.6-1+ubuntu18.04.1+deb.sury.org+1) ...

 

7-7. 이제 설치가 완료 되었습니다. php 버전을 확인해 보겠습니다.

명령어 창에서 php -v 를 입력합니다.

ubuntu@wordpress:~$ php -v
PHP 7.4.6 (cli) (built: May 14 2020 10:02:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

7.4.6 버전이 잘 설치되었다고 나타납니다.

그럼 php rpm을 시작해 주겠습니다.

명령어 창에서 sudo service php7.4-fpm start 를 입력합니다.

ubuntu@wordpress:~$ sudo service php7.4-fpm start

 

* php는 설치되었으나 php를 사실 읽지 못합니다. 해당 이유는 아래 내용을 더보기 하세요~ ^^

더보기

* php는 설치되었으나 php를 사실 읽지 못합니다.

EditPlus에서   <?php phpinfo(); ?> 를 입력해 보겠습니다.

저장 위치는 /var/www/html/ 입니다.

그리고 웹브라우저에서 접속을 해보겠습니다.

웹브라우저는 해당 페이지를 읽지 못하고 다운로드 시키려고 하고 있습니다.

이제 웹서버인 Nginx가 php를 읽을 수 있도록 수정을 해 보겠습니다.

7-8. 우선 Nginx의 사용권한을 확인해 보겠습니다.

지난 Linux 폴더 권한을 확인했던 것과 같이 여기서도 마찮가지로 확인해보겠습니다.

명령어 창에서 ls -l /etc/nginx/sites-available/를 입력합니다.

ubuntu@wordpress:~$ ls -l /etc/nginx/sites-available/
total 4
-rw-r--r-- 1 root root 2416 Apr  6  2018 default

소유권한도 root고 사용자그룹도 root입니다. 여기서는 사용만 하면 되니까 사용권한만 변경해 보겠습니다.

명령어창에서 sudo chgrp ubuntu /etc/nginx/sites-available/default 를 입력 사용자그룹권한을 ubuntu로 변경합니다.

또, 명령어창에서 sudo chmod 664 /etc/nginx/sites-available/default 를 입력하여 파일권한을 664 (또는 775도 괜찮습니다.)로 변경합니다.

ubuntu@wordpress:~$ sudo chgrp ubuntu /etc/nginx/sites-available/default
ubuntu@wordpress:~$ sudo chmod 664 /etc/nginx/sites-available/default
ubuntu@wordpress:~$ ls -l /etc/nginx/sites-available/
total 4
-rw-rw-r-- 1 root ubuntu 2416 Apr  6  2018 default

여기서 664는 소유자권한은 읽기와 쓰기를 그룹권한과 공개권한은 읽기만 가능한 것을 뜻합니다.
          755는 소유자 권한은 읽기와 쓰기 그리고 실행을 그룹권한과 공개권한은 읽기와 실행이 되도록 하는 것입니다.

이제 EditPlus에서 /etc/nginx/sites-available/ 에 위치한 default 파일을 수정할 수 있게 되었습니다. (SFTP에서도 수정할 수 있게 되었구요.)

7-9. default 파일에서 index.php를 추가해 보겠습니다.

# Add index.php to the list if you are using PHP 라며 설명되어 있는 곳 아래 그리고 server_name _; 위에 index index.html index.htm index.nginx-debian.html;라고 표시되어 있는 곳에 index.php라고 입력합니다.

위치를 index 바로 뒤에 저는 넣었습니다.

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/html;

	# Add index.php to the list if you are using PHP
	index index.php index.html index.htm index.nginx-debian.html;

	server_name _;

그 다음 # pass PHP scripts to FastCGI server 아래에 PHP 설정파일의 경로와 보안설정을 추가하였습니다. 

	# pass PHP scripts to FastCGI server
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.4-fpm.sock;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
		include fastcgi_params;
		fastcgi_read_timeout 300;
	}

	location ~ /\.ht {
	    deny all;
	}

향후 default는 도메인 및 HTTPS 추가 시 다시 내용을 추가 할 겁니다.

우선 PHP7이 제대로 작동되는지 확인을 위해서니까요. 이제 해당 내용이 정상적으로 동작하는지 확인해 보겠습니다.

7-10. 다시 nginx에 설정에 문제가 없는지 확인합니다.

명령어 창에서 sudo nginx -t 를 입력합니다.

/etc/nginx/nginx.conf syntax is ok         <- 에서 Nginx 설정의 문법이 문제 없다고 하면 됩니다.

/etc/nginx/nginx.conf test is successful  <- 에서 Nginx가 정상적으로 test 동작한다고 하면 도비니다.

 

ubuntu@wordpress:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

그럼 Nginx를 재구동 하겠습니다.

명령어 창에서 sudo systemctl reload nginx 를 입력합니다.

명령어 창에서 sudo service nginx restart 를 입력합니다.

ubuntu@wordpress:~$ sudo systemctl reload nginx
ubuntu@wordpress:~$ sudo service nginx restart

그럼 Nginx가 재구동 되었습니다.

7-11. 이제 php가 정상적으로 뜨는지 확인하겠습니다.

EditPlus에서 /var/www/html/에서 index.php를 만들어 봅니다.

파일들이 있는 곳(index.nginx-debian.html)에서 마우스 오른쪽을 눌러 새로 작성을 누릅니다.

그 후에 index.php를 입력합니다.

본문 안에 <?php phpinfo(); ?>를 입력하시면 됩니다. 저는 html틀에서 하셨는데 모두 지우구 <?php phpinfo(); ?> 만 입력하셔도 됩니다.

7-12. 이제 http://ipaddress/index.php 를 입력하시고 확인하시면 됩니다.

7-13. 시간대 설정 변경하기

현재 서버의 시간 설정대가 왠지 모르겠지만 평양으로 되어 있습니다.;;; (오라클 북한 진출설?)

국정원에 언제 잡혀갈지 모르니 ㅡ_ㅡ;; 빨리 변경하겠습니다.

php.ini를 수정해야 하는데 이걸 지난번 처럼 권한을 풀고 하기에는 보안상 문제가 있으므로 리눅스의 nano에디터를 사용해 수정해 보겠습니다.

명령어 창에서 sudo nano /etc/php/7.4/fpm/php.ini 를 입력합니다.

아래와 터미널의 화면이 나오면 CTRL + W를 누르면 검색창이 나오며 date.timezone 을 입력해 검색을 실행합니다.

CTRL + O를 누르면 검색창이 뜨고 여기서 date.timezone이라 입력합니다.

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =   # <- 이 부분을 수정합니다.

date.timezone = Asia/Seoul  # <- 이 부분에서 맨 앞의 ;를 삭제하고 뒤에 Asia/Seoul를 입력합니다.

여기서 ;date.timezone = 라고 되어 있는 부분이 검색되어 나오면

앞 부분의 ;를 삭제하고 date.timezone = 뒤에 Asia/Seoul 을 입력합니다.

그리고 저장하고 나올때는 CTRL + X를 누르고 Y를 누른 다음 파일명이 나오면 엔터를 눌러 저장합니다.

CTRL + X를 누르면 YES라고 입력합니다.
파일명이 나오면 엔터를 눌러 저장합니다.

이제 fpm/php.ini를 수정하셨으면 이번에는 cli/php.ini를 수정하셔야 합니다.

명령어 창에서 sudo nano /etc/php/7.4/cli/php.ini 를 입력합니다.

동일하게 검색하여 앞 부분의 ;를 삭제하고 date.timezone = 뒤에 Asia/Seoul 을 입력하면 됩니다.

그리고 나서 php7.4를 재시작해 줍니다.

명령어 창에서 sudo systemctl restart php7.4-fpm 를 입력합니다.

다시 index.php를 확인합니다.

이제 Default timezone이 AsiaSeoul로 변경된 것을 확인할 수 있습니다.

이제 PHP가 정상적으로 설치 되셨고 정상적으로 PHP를 운영하실 수 있게 되었습니다.

DB를 설치하기 전에 보안등을 위하여 /var/www/html 폴더에 있는 생성한 파일은 삭제를 추천합니다.

  • index.nginx-debian.html
  • index.php

두개의 파일은 Nginx 설치하며 자동으로 생성된 파일과 phpinfo 정보를 확인하기 위하여 만든 index.php파일입니다.

두 파일 모두 삭제하시는 것을 추천합니다.

모두 삭제하셨으면 403 Error가 나타납니다.

 

Contents

0. 오라클 클라우드에서 Ubuntu LEMP(Linux+Nginx+MariaDB+PHP7)에 WORDPRESS 설치하기
1. 오라클 클라우드 무료 가입 (Oracle Cloud Free Tier)하기
2. 오라클 클라우드에서 Ubuntu(우분투) 인스턴스 서버 생성하기 (네트워크 셋팅을 포함)
3. 오라클 클라우드 SSH 접속 및 SFTP 등 서버 접속 환경 설정하기
4. 오라클 클라우드 우분투 서버 환경 설정하기
5. Nginx 서버 설치하기
6. Linux 폴더 권한 설정 확인하기
7. Nginx 서버에 PHP7 설치하기
8. MariaDB 설치하기
9. phpMyAdmin 설치하기
10. 도메인 연결하기
11. sendmail 설치하기
12. HTTPS 적용을 위한 SSL 인증서 발급받기
13. DB 생성하기
14. Wordpress 설치하기
15. Wordpress 설치 후 서버 및 Wordpress 환경 설정하기

* 해당 내용은 오라클 제품을 다루고 있지만 이는 개인적인 테스트 결과이며, 오라클 공식 문서는 아님을 미리 밝힙니다.

반응형