본문 바로가기

서버작업

4. Php, Laravel 설치 및 Laravel - nginx 연결

현재 설치하고자 하는 스펙

-centOS 7

-php 7.2

-laravel 6.2

 

1. php 설치

 

wget 패키지 install

yum -y install wget

*wget은 비 상호작용 네트워크 다운로더 (즉, 다운로드 명령어)

 

**wget 설치 확인 which wget

 

 

remi's RPM repository 설정

/centOS 기본 php 버전이 5.6이라서 remi repo로 설치

 

1) remirepo 설정

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm

 

명령어 실행 후 생기는 파일

 

wget  다운로드
rpm  설치파일 (~~~~.rpm : 설치)

 

 

 

2) remi-php 72 repository 활성화

 

yum-utils 패키지 설치

yum install yum-utils
yum-config-manager --enable remi-php72

 

 

 

3. php 설치

 

모듈은 필요한 것만 설치하면 됨

yum install -y php-common php-fpm php-cli php-redis php-brotli php-intl php-gd php-gmp php-imap php-bcmath php-interbase php-json php-mbstring php-mysqlnd php-odbc php-opcache php-memcached php-tidy php-pdo php-pdo-dblib php-pear php-pgsql php-process php-pecl-apcu php-pecl-geoip php-pecl-gmagick php-pecl-hrtime php-pecl-json php-pecl-memcache php-pecl-rar php-pecl-pq php-pecl-yaml php-pecl-zip php-curl php-xml
yum list php-mcrypt
yum install php-mcrypt

**라라벨 필수 패키지: fpm, mysql, zip, gd, mcrypt, mbstring, xml

 

 

4. 설치 확인

# 둘 중 하나로 확인
php -v  
rpm -qa php

 

 

5. laravel 설치

 

composer 설치를 위해 json을 설치

yum install php71u-json

 

composer 글로벌 설치

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

 

laravel 설치

 

프로젝트 만들 위치로 이동 후,

composer create-project laravel/laravel laravel_p01 "6.*"    // 5.6.* = 버전

 

6. laravel-nginx 연결

 

1) php.ini 설정 변경

 

php.ini 

cgi.fix_pathinfo=0

cgi.fix_pathinfo을 0으로 설정

 

 

 

2) php-fpm.sock; 만들기

 

www.conf 파일 만들기

vi /etc/php-fpm.d/www.conf
(수정전) 
;listen = 127.0.0.1:9000

(수정후) 
listen = /var/run/php-fpm/php-fpm.sock

 

수정 후, php-fpm 재시작

systemctl restart php-fpm

 

php-fpm.sock 파일 확인

cd /var/run/php-fpm/

 

 

3) www.conf 파일 수정

 

;listen.owner = nobody 변경

listen.owner = nginx

;listen.group = nobody 변경

listen.group = nginx

;listen.mode = 0660 변경

listen.mode = 0660

;user = apache 변경

user = nginx

;group = apache 변경

group = nginx

 

전체 수정 후, php-fpm 재시작

systemctl restart php-fpm

 

 

 

4) 프로젝트 파일 권한 변경

 

라라벨 프로젝트 내에서 아래 명령어 실행

chmod 755 storage (x)
chmod 755 bootstrap/cache
sudo chmod -R 777 storage/logs (x)
mkdir -p bootstrap/cache
sudo chown -R nginx:nginx bootstrap/cache
mkdir -p storage/logs
mkdir -p storage/framework/cache
mkdir -p storage/framework/sessions
mkdir -p storage/framework/views
sudo chown -R nginx:nginx storage

 

5)conf 파일 변경

cd /etc/nginx/conf.d/
vi 파일명.conf

: 이때 파일명은 알아보기 쉽게 project 명으로 하면 구분이 쉬움

 

 

server {
    listen       80;
    server_name  www.nyang.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

        root   /home/project/nyang/public;
        index  index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 

listen 80; http 기본포트 (https 기본포트 = 443)
server_name   연결 도메인 주소 (ex. cafe 24에서 등록 후 연결)
root    연결 할 프로젝트 기본 위치 (php는 public 이므로 전체주소 작성)

 

 

 

7. ngin, php-fpm 재시작

systemctl restart nginx
systemctl restart php-fpm

 

반응형