오늘은 CentOS 7 WordPress 설치 방법을 알아 보도록 하겠습니다. (2018.02.28 수정)
이포스트를 진행전에 CentOS 7 설치  MariaDB, PHP7.1, Nginx 설치  2가지 포스트를 먼저 진행하시기 바랍니다.

1. DB 생성

mysql -u root -p

DB에 root 권한으로 접속 합니다.


CREATE USER 계정이름@localhost IDENTIFIED BY "비밀번호";

계정을 생성 합니다.
예) 계정 이름 : kr, 비밀번호 : word1234
CREATE USER kr@localhost IDENTIFIED BY “word1234”;


create database 디비이름;

DB를 생성 합니다.
예) DB 이름 : krhome
create database krhome;


GRANT ALL ON 디비이름.* TO 계정이름@localhost;

우리가 생성한 디비에 대한 권한을 줍니다.
예) kr 계정에게 krhome 권한 주기.
GRANT ALL ON krhome.* TO kr@localhost;


FLUSH PRIVILEGES;

권한을 적용 합니다.


exit

DB 설정을 나갑니다. 

2. WordPress 설치

cd ~
wget https://ko.wordpress.org/wordpress-4.9.8-ko_KR.tar.gz

wordpress 4.9.8 한글 버전을 다운로드 합니다.


tar zxvf wordpress-4.9.8-ko_KR.tar.gz wordpress

다운받은 워드프레스 파일을 압축을 풉니다. 


mv wordpress/* /var/www/html

WordPress 디렉토리를 /var/www/html 로 이동합니다.


rm -rf wordpress-4.9.8-ko_KR.tar.gz

다운 받은 압축 파일을 삭제 합니다.


mkdir /var/www/html/wp-content/uploads
mkdir /var/www/html/wp-content/upgrade

uploads, upgrade 디렉토리를 생성 합니다.


cd /var/www/html/
mv wp-config-sample.php ../wp-config.php

웹서버 폴더로 이동 후 wp-config-sample.php 파일을 상위 디렉토리로 이동합니다.

 

2. Web Server 디렉토리 권한 변경

chown -R nginx:nginx /var/www/html
chmod -R 711 /var/www/html
chcon -R -t httpd_sys_content_t /var/www/html
chcon -R -t httpd_sys_content_t /var/www/wp-config.php
chcon -R -t httpd_sys_rw_content_t /var/www/html/wp-content

web server 디렉토리 (/var/www/html) 사용자를 root에서 nginx로 변경 합니다.

 

3. NGINX 설정 변경

vim /etc/nginx/conf.d/default.conf

nginx default.conf 를 open 합니다.


server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

위에 내용을 아래와 같이 수정합니다.

server {
    listen       80;
    server_name  웹사이트 Url이나 ip입력;
#    location / {
        root   /var/www/html;
        index  index.html index.htm;
#    }
     location / {
        try_files $uri $uri/ /index.php?$args;
        index  index.php index.html;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass   unix:/run/php-fpm/www.sock;
    }
}

 

server_name 192.168.0.2

상단 server_name 에 CentOS7 IP나 URL을 입력 합니다


 #location / { 
        root /var/www/html;
        index index.html index.htm;
 #}

조금 내려오면 root가 보이는데 /var/www/html 위에서 설정한 웹서버 디렉토리를 설정 합니다.
“locaion / {” 와  “}”앞에 #으로 표기 합니다.


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

위에 내용을  추가 합니다.

:wq 를 입력하여 저장후 나옵니다. 


systemctl restart nginx.service

nginx를 재시작 합니다.

 

4. WordPress DB 설정

vim /var/www/wp-config.php

wp-config.php Open 합니다.


define('DB_NAME', '디비이름');

디비 이름을 위에서 설정한 대로 수정 합니다.
예 : 디비이름이 krhome 일경우
define(‘DB_NAME’, ‘krhome’);


define('DB_USER', '계정이름');

계정이름을 위에서 설정한 대로 수정 합니다.
예 : 계정이름이 kr 일 경우
define(‘DB_USER’, ‘kr’);


define('DB_PASSWORD', '계정비번');

계정비번을 위에서 설정한 대로 수정 합니다.
예 : word1234 일 경우
define(‘DB_PASSWORD’, ‘word1234’);


define('NONCE_SALT',       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~``');
define('FS_METHOD','direct');

NONCE_SALT 밑에 define(‘FS_METHOD’,‘direct’); 추가 합니다.

 

5. CentOS 7 wordpress 접속

웹브라우져에 CentOS 7 IP 나 Url을 입력하면 Wordpress 초기 설정화면을 볼수 있을것 입니다.
워드프레스 초기 설정은 Synology WordPress 이용한 웹서버 구축 3번 항목부터 보시면 됩니다.

그럼이것으로 CentOS7 에 WordPress 설치 하는방법을 알아 보았습니다.