리눅스/실습

워드프레스 LEMP 서버 구축하기-2

dbswjdahr 2025. 11. 8. 17:23

이제 maridb에 워드프레스를 붙게 하기 위해 설정을 해줘야 함
mariadb 전용 파티션을 만들고 디렉터리를 따로 마운트해 사용하기 때문에 아래와 같은 오류가 난다. 
마리아DB 서버 설정 파일은 바꿔줬는데 클라이언트를 안 바꿔줘서 그렇다.

[root@Alma ~]# mariadb
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

클라이언트 설정도 바꿔주면 된다. 시스템 대몬 실행 시 소켓이 /mnt/db에 생기니 소켓 경로도 지정해주면 됨
client부분에 아래처럼 추가
그러면 dbms 사용 가능

[root@Alma ~]# vi /etc/my.cnf.d/client.cnf
[client]
socket=/mnt/db/mysql.sock

[root@Alma ~]# mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.29-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

이제 워드프레스용 데이터베이스랑 유저를 만들어주면 됨. 데이터베이스와 유저명, 비밀번호는 알아서 정하면 됨
여기서는 한 VM 안에 웹이랑 DB가 붙는 거니 호스트는 로컬호스트로 하면 됨

MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.009 sec)

MariaDB [(none)]> create user 'wpuser'@'localhost' IDENTIFIED BY 'passwd';
Query OK, 0 rows affected (0.012 sec)

MariaDB [(none)]> grant all privileges on wpdb.* to 'wpuser'@'localhost';
Query OK, 0 rows affected (0.032 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.002 sec)

이런 식으로 설정하면 된다. 만약, 웹이랑 db를 따로 떨어트려 구축하는 클라우드 환경 같은 경우에는 로컬 호스트하면 당연히 안 붙음.
이러면 db쪽에서 웹서버를 호스트로 지정해줘야 함.

워드프레스 사용 유저 입력

/mnt/web으로 옮기면서 파일들이 죄다 root 소유권으로 변해서 db 옮길 때 mysql로 변경한 거람 마찬가지로 해야 함
chown -R nginx:nginx /mnt/web 해주면 자동으로 wp-config.php 파일이 생긴다. 
그리고 php-fpm 설정 파일도 맞춰주면 됨.
이러면 마운트하면서 엇나간? 설정들이 다시 맞춰진다

[root@Alma ~]# vi /etc/php-fpm.d/www.conf
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[root@Alma ~]# vi /etc/php.ini
[mysqli]
mysqli.default_socket = /mnt/db/mysql.sock

[pdo_mysql]
pdo_mysql.default_socket = /mnt/db/mysql.sock

DB가 붙으면 이렇게 나옴
사용자명에 한글 썼다가 거부됨...

여기서 사용자명이랑 비밀번호가 ID, PW가 되니 막 정하지 말고 기억하면 됨

처음에 뜨는 로그인 창
워드프레스 로그인 완료!

이러면 성공적으로 LEMP(Linux, Nginx, MariaDB, PHP) 구축이 완료되었다!