[서버설치] How to Install PHP 7, NGINX, MySQL on CentOS/RHEL 7.6

KT Cloud CentOS 7.6을 선택하여 만들어진 클라우드 서버에 설치하는 방법입니다.

외국 사이트에 있는 내용 그대로 입력하니 동작을 잘 하네요. ^.^

==> https://tecadmin.net/install-php-7-nginx-mysql-5-on-centos/

를 참고하세요.

Step 1 – Setup Yum Repository

In the first step install all the required yum repositories in your system used in the remaining tutorial for various installations. You are adding REMI, EPEL, Webtatic & MySQL community server repositories in your system.

CentOS / RHEL 7

yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

CentOS / RHEL 6

yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

Step 2 – Install PHP 7

Now install PHP 7 packages from remi-php72 rpm repository using the following command.

yum --enablerepo=remi-php72 install php

Now install required php modules. Use following command to list available modules in yum repositories.

yum --enablerepo=remi-php72 search php

Now check all listed modules in above command and install required modules like below.

yum --enablerepo=remi-php72 install php-mysql php-xml \
php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

Step 3 – Install NGINX

NGINX is the popular web server used on Linux systems. Let’s install the Nginx web server using the following command on your system.

yum install nginx

Now start nginx service and enable to start on boot using below commands.

systemctl enable nginx.service
systemctl start nginx.service

Step 4 – Install MySQL 5.6

In step 1 we already have installed required yum repository in your system. Lets use following command to install MySQL server on your system.

yum install mysql-server

You need to execute mysql_secure_installation once after installation of MySQL server using following command. First it will prompt to set a password for root account, after that ask few questions, I suggest to say yes ( y ) for all.

systemctl start mysqld.service
mysql_secure_installation
**** mysql_secure_installation로 검색하면 다른 게시물에 설정한 내용이 있음.

Now restart MySQL service and enable to start on system boot.

systemctl restart mysqld.service
systemctl enable mysqld.service

Step 5 – Setup PHP-FPM

Now use following command to install php7 fpm package using following command.

yum --enablerepo=remi-php72 install php-fpm

Step 6 – Create Nginx VirtualHost

Finally do the configuration of Nginx VirtualHost. For this example we are editing default configuration file.

sudo vi /etc/nginx/conf.d/example.conf

and make changes as below.

server {
        listen   80;

        root /var/www;
        index index.php index.html index.htm;
        server_name  example.com www.example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        location ~ .php$ {
                try_files $uri =404;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

You have to do the same changes in all Virtual Hosts configured.

Step 7 – Restart Services

After installing all services on your system, start all required services.

systemctl restart nginx.service
systemctl restart php-fpm.service

Step 8. Open Port in Firewall

Finally open firewall ports for HTTP (80) and https (443) services using the following command.

firewall-cmd --permanent --zone=public --add-service=httpfirewall-cmd --permanent --zone=public --add-service=httpsfirewall-cmd --reload

Step 9. Verify Setup

Let’s check the installed versions of packages on system using following commands one by one.

# php -v

PHP 7.2.0 (cli) (built: Nov 28 2017 20:22:21) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
# nginx -v

nginx version: nginx/1.12.2

Finally, verify the installation of PHP 7 with NGINX. Let’s create a file index.php on website document root using the following content.

Now browse this file in a web browser. It will so all the details about versions and installation.

Install PHP 7, NGINX & MySQL 5.6

0
0
이 글을 페이스북으로 퍼가기 이 글을 트위터로 퍼가기 이 글을 카카오스토리로 퍼가기 이 글을 밴드로 퍼가기
captcha
자동등록방지 숫자입력

웹개발

번호 제목 글쓴이 날짜 조회수
62 [Linux] CentOS postfix 메일서버 설치 및 설정(sendmail 설정) 최고관리자 12-23 1,433
61 [Ubuntu] 인터넷 연결이 안될 때 최고관리자 12-07 1,239
60 [Apache SSL] Ubuntu 인증서(전자서명) 최고관리자 11-24 1,349
59 [Ubuntu] ssl 임시 인증서 준비 및 발급받기 최고관리자 11-23 1,730
58 [Ubuntu] apache2 환경설정 생성기 최고관리자 11-23 2,950
57 [Ubuntu] apache2 설치 최고관리자 11-23 1,249
56 [vi 편집기] 단축키 최고관리자 11-23 1,174
55 [유용한 블로그] ^^.^^ 최고관리자 11-19 1,181
54 [JS] TimelineJS - 시간의 흐름을 네비게이션화 최고관리자 11-19 1,249
53 [JS] 스크롤을 감지하여 사이트의 헤더를 보이거나 숨기기 최고관리자 11-19 1,380
52 [Linux] NAS Mount 최고관리자 11-12 1,191
51 [React] React활용 최고관리자 11-10 1,228
50 [PHP] exec 실행에 대한 응답코드 최고관리자 11-02 1,576
49 [Linux] Shell Script 최고관리자 10-26 1,480
48 [폰트] 폰트 찾기 사이트 최고관리자 10-21 1,285
47 [통신] Socket packet test Program 최고관리자 10-20 1,768
46 [통신] 맥용 Socket Test Program 최고관리자 10-20 1,551
45 [통신] Mac에서 TCP Socket통신 테스트 하기 최고관리자 10-20 2,821
44 [NginX] 504 Gateway Time-out 에러와 해결방법 +1 최고관리자 10-16 24,485
43 [NginX] 설정 최고관리자 10-13 1,487