Linux

Linux_Nginx + wordpress + mysql 연결

우당탕탕인생기 2023. 9. 1. 17:35

이전 포스팅에는 nginx가 아닌 apache http로 연결했는데, 이번에는 nginx을 통해서 해보도록 하겠다.

http 보다 설정해야 할 것들이 좀 더 많다.

 

이 때 php 버전은 7.4 이상으로 설정해야 한다.


 

  • Nginx 설치
dnf isntall -y nginx

 

  • php  설치

우선, 여기서 차이점이 하나 발생한다. php-fpm이라는 패키지를 추가로 설치해줘야 한다.

 

dnf install -y php php-cli php-common php-curl php-opcache php-gd php-mysqlnd php-fpm

 

  • wordpress 설치

wordpress 설치는 이전과 동일 하니 따로 작성하지 않겠다.

 

 

  • php-fpm.conf 파일 수정

위 파일에서 유저나 그룹이 apache 로 되어 있을 것을 nginx로 변경해줘야 한다. 

 

 

vi /etc/php-fpm.conf.d/www.conf

#### 편집모드 접속

---중략

; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx   # nginx로 변경
; RPM: Keep a group allowed to write in log dir.
group = nginx  # nginx로 변경

----중략
listen = /run/php-fpm/www.sock # 해당 경로가 잘못되어 있으면 위 경로로 변경

listen.owner = nginx
listen.group = nginx

 

 

  • nginx.conf 설정파일 변경

경로는 /etc/nginx/nginx.conf 이다.

 

아래 내용을 추가로 작성해줘야 한다.

 

        location ~ \.php$ {
             try_files $uri =404;
             fastcgi_pass unix:/run/php-fpm/www.sock;
             fastcgi_index      index.php;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include fastcgi_params;
        }
    }

vi /etc/nginx/nginx.conf

################## 편집모드


--중략

     38     server {
     39         listen       80;
     40         listen       [::]:80;
     41         server_name  _;
     42         root         /usr/share/nginx/html;
     43         index   index.php                    # index는 index.php을 읽도록 설정
     44         # Load configuration files for the default server block.
     45         include /etc/nginx/default.d/*.conf;
     46 
     47         error_page 404 /404.html;
     48         location = /404.html {
     49         }
     50 
     51         error_page 500 502 503 504 /50x.html;
     52         location = /50x.html {
     53         }
     54         location ~ \.php$ {               #### 이부분을 추가로 작성해줘야한다.
     55              try_files $uri =404;
     56              fastcgi_pass unix:/run/php-fpm/www.sock;
     57              fastcgi_index      index.php;
     58              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     59              include fastcgi_params;
     60         }
     61     }

 

 

  • 80 포트 오픈 후 시스템 시작
firewall-cmd --add-port=80/tcp
systemctl start nginx

 

 

이렇게 하면 이후에는 wordpress 세팅과 mysql 연결은 http와 동일하다.

https://jbseo.tistory.com/42

 

Linux_ wordpress , mysql(8.0) , php(8.0) 연동

이번에는 2Tier 구성인 worpress와 php 그리고 db인 mysql과 연동하는 방법에 대해 기록해보도록 하겠다. 시뮬레이션은 아래와 같다고 가정하고 해보겠다. 1번 server 2번 server Mysql-client 8.0 Mysql-server 8.0 wo

jbseo.tistory.com

다른점은 http는 경로가 /var/www/html 이었다면

nginx는 /usr/share/nginx/html 이다.