CS/Linux
[VMware] 12-1. WORDPRESS(워드프레스)
나의 개발자
2025. 1. 31. 17:52
WORDPRESS(워드프레스)
- 동적인 웹 서버로, 프로그래밍 언어로 구성
- DB와 통신을 통해, DB의 있는 값을 입출력하여 요청에 대한 결과물이 변동되는 서버
- 정적 웹 서버인 httpd는 DB에 접근해서 데이터를 처리할 수 없기 때문
백엔드 언어(php)로 요청을 보냄 ➡️ php가 connector를 통해 DB에 접근 - wordpress를 설치하면, httpd 패키지도 설치됨
- Linux 서버에 존재하는 것인지, MariaDB 서버에 존재하는 것인지 위치를 아는 것이 중요
실습
1. 서버 생성 & 초기 설정
- Spec
- 2 core / 2GB / 20GB
- IP : 211.183.3.33
- 방화벽 해제
[root@db ~]# systemctl stop firewalld
[root@db ~]# systemctl enable firewalld
- SELINUX 해제
[root@db ~]# sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
- 레포지토리 설정
cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
2. MariaDB 데몬 패키지 설치
[root@db ~]# yum install -y mariadb-server
[root@db ~]# systemctl restart mariadb
[root@db ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# 서비스 확인
[root@db ~]# ss -tnlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1288,fd=13))
LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=8487,fd=14))
LISTEN 0 128 *:22 *:* users:(("sshd",pid=992,fd=3))
LISTEN 0 100 [::1]:25 [::]:* users:(("master",pid=1288,fd=14))
LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=992,fd=4))
3. MariaDB 접속 & root 암호 설정 및 기타 보안 설정
- MariaDB 접속
[root@db ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-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.
# Linux의 localhost에 존재하는 DB 서버(데몬)에 접속
MariaDB [(none)]>
- root 암호 설정 및 보안 설정
[root@db ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
# root 비밀번호 설정 전이라서 'enter' 치면 됨
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
# root 비밀번호 설정
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
# 기존 사용자 삭제?
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
# 외부 root 접속 허용 : n
# 외부 root 접속 허용X : Y
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
# 기본 DB 삭제 여부
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# 권한 테이블 삭제 여부
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
- MariaDB 암호로 접속 확인
- Linux 서버에서 원격으로 root에 접속 불가능 ➡️ 암호 필요
- 대소문자 구분🌟
# Linux 서버(localhost)에서 원격으로 root 접속 불가능
# -> 비밀번호 작성해야 접속 가능
[root@db ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
# -u : 사용자
# -p : 비밀번호 / 비밀번호는 옵션과 붙여서 작성(띄어쓰기X)
# -P : 포트 번호 / 포트는 띄어쓰기 O
# -h : IP 주소
[root@db ~]# mysql -u root -p1234
4. 데이터베이스 생성
- 데이터베이스 확인
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
- 데이터베이스 생성
- 데이터베이스 대소문자 구분
MariaDB [(none)]> create database wp_DB;
Query OK, 1 row affected (0.00 sec)
# 데이터베이스 생성 확인
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wp_DB |
+--------------------+
4 rows in set (0.00 sec)
5. 사용자 생성 & 권한 부여
- 다른 모든 서버에서 wpuser라는 사용자와 '1234'라는 암호로 접근 시, wp_DB라는 이름을 갖는 DB에 대한 모든 권한 부여
# grant : 권한 부여 / all privileges : 모든 권한
# wp_DB : DB명 / * : 모든 테이블
# wpuser : 사용자 생성 및 권한 부여
# % : 어디서? => 모든 주소(localhost 제외) / identified by : 암호
MariaDB [(none)]> grant all privileges on wp_DB.* to wpuser@'%' identified by '1234';
Query OK, 0 rows affected (0.00 sec)
- wpuser 접근
[root@db ~]# mysql -u wpuser -p1234
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 5.5.68-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.
# WP_DB 존재 확인
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp_DB |
+--------------------+
2 rows in set (0.00 sec)
6. wordpress 패키지 설치 - CentOS에 설치할 때, 과정이 복잡함
- epel-release 패키지 설치
- 리눅스 패키지 저장소
[root@db ~]# yum install -y epel-release
- remi 레포지토리 설치
- 레포지토리 목록
[root@db ~]# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
- yum-utils 패키지 설치
- 다운로드한 레포지토리 목록에 대한 반영
- yum-config-manager라는 명령어 사용 가능
[root@db ~]# yum install -y yum-utils
- remi 리포의 php7.3 버전 정보 등록
[root@db ~]# yum-config-manager --enable remi-php73
- php 설치
[root@db ~]#yum install -y php
- php 버전 확인
- 5.xxx 버전 설치 ➡️ 설치 오류
- 7.3 버전 설치 ➡️ 정상 설치
[root@db ~]# php -v
PHP 7.3.33 (cli) (built: Jun 5 2024 05:42:20) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies
7. php-mysql & wget & unzip 패키지 설치
- 모든 백엔드 언어( php, python, java 등)는 DB에 접근하기 위해서 connector가 필요 = php-mysql
[root@db ~]# yum install -y php-mysql
# wordpress를 다운받고 zip 풀기 위해서 설치
[root@db ~]# yum install -y wget unzip
[root@db ~]# wget https://wordpress.org/latest.zip
# latest.zip 다운로드 확인
[root@db ~]# ls
anaconda-ks.cfg latest.zip
# -d 디렉토리 지정해서 압축 해제
[root@db ~]# unzip latest.zip -d /var/www/html
✅ 주의사항
- 해당 프로세스가 yum을 점유하고 있어서 작업이 안 끝남
➡️ 해당 프로세스를 죽여야 함
8. wordpress 설정
- wp-config.php 파일 생성
1) wordpress 경로로 이동
[root@db ~]# cd /var/www/html/wordpress
# wp-config.php : 설정 관련 파일
# DB와 연동시키는 부분만 수정할 예정
[root@db wordpress]# ls
index.php wp-admin wp-content wp-load.php wp-signup.php
license.txt wp-blog-header.php wp-cron.php wp-login.php wp-trackback.php
readme.html wp-comments-post.php wp-includes wp-mail.php xmlrpc.php
wp-activate.php wp-config-sample.php wp-links-opml.php wp-settings.php
#2) wp-config-sample의 내용을 wp-config로 이동
[root@db wordpress]# mv wp-config-sample.php wp-config.php
#3) wp-config.php 설정
[root@db wordpress]# vi wp-config.php
[수정 내용]
# DB 이름, DB 사용자, DB 암호, DB 주소 내용 수정
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wp_DB' );
/** Database username */
define( 'DB_USER', 'wpuser' );
/** Database password */
define( 'DB_PASSWORD', '1234' );
/** Database hostname */
define( 'DB_HOST', '211.183.3.33' );
[root@db wordpress]# systemctl restart httpd
[원본 서식]
21 // ** Database settings - You can get this info from your web host ** //
22 /** The name of the database for WordPress */
23 define( 'DB_NAME', 'database_name_here' );
24
25 /** Database username */
26 define( 'DB_USER', 'username_here' );
27
28 /** Database password */
29 define( 'DB_PASSWORD', 'password_here' );
30
31 /** Database hostname */
32 define( 'DB_HOST', 'localhost' );
33
34 /** Database charset to use in creating database tables. */
35 define( 'DB_CHARSET', 'utf8' );
36
37 /** The database collate type. Don't change this if in doubt. */
38 define( 'DB_COLLATE', '' );
💡DB 서버 접근 필요 정보
1) DB 이름 : wp_DB
2) DB 주소 : 211.183.3.33
3) DB 사용자 : wpuser
4) DB 암호 : wpuser 사용자의 암호 = '1234'
➕ 포트 변경 시, 포트 정보 고려
9. wordpress 확인
- 접속 & root 설정
- 댓글 작성
10. MariaDB에서 확인
[root@db wordpress]# mysql -u wpuser -p1234
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 57
Server version: 5.5.68-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp_DB |
+--------------------+
2 rows in set (0.00 sec)
# DB 선택
MariaDB [(none)]> use wp_DB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
# 테이블 확인
# wordpress 프로그램이 php를 통해 생성한 테이블
MariaDB [wp_DB]> show tables;
+-----------------------+
| Tables_in_wp_DB |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+-----------------------+
12 rows in set (0.00 sec)
# 모든 내용 확인
MariaDB [wp_DB]> select * from wp_comments;
# comment_content에 대한 내용 확인
# 아까 남긴 코멘트 확인 가능
MariaDB [wp_DB]> select comment_content from wp_comments;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| comment_content |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from <a href="https://gravatar.com/">Gravatar</a>. |
| aws8 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
✅ Wordpress 연동 안 되는 경우 - Database connection 오류
- Client에서 (mysql 설치해서) DB에 접속이 가능한지 파악 필요
- Client에서 접속 가능 ➡️ 설정파일 확인 필요
- Client에서 접속 불가능 ➡️ 방화벽 & 셀리눅스 확인 필요
실습
[ wordpress 서버 ]
hostname : hwwp
IP : 211.183.3.180
[ DataBase 서버 ]
hostname : hwdb
IP : 211.183.3.6
DB : hwdb
DB user : hwuser
hwuser 암호 : 1234
🌟 yum install -y mysql : 클라이언트(mysql 명령)가 설치됨
Wordpresss Server
더보기
1. 초기 설정 - 방화벽 & SELINUX & 레포지토리 설정
systemctl stop firewalld
systemctl enable firewalld
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
2. 패키지 설치
yum install -y mysql
yum install -y mariadb-server
yum install -y wget unzip
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum-config-manager --enable remi-php73
yum install -y php
php -v
yum install -y php-mysql
3. wordpress 설치
wget https://wordpress.org/latest.zip
ls
unzip latest.zip -d /var/www/html
cd /var/www/html/wordpress
ls
mv wp-config-sample.php wp-config.php
vi wp-config.php
systemctl restart httpd
mysql -u wpuser -p1234 -h 211.183.3.6
DataBase Server
더보기
1. 초기 설정 - 방화벽 & SELINUX & 레포지토리 설정
systemctl stop firewalld
systemctl enable firewalld
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
2. mariadb-server 패키지 설치
yum install -y mariadb-server
systemctl restart mariadb
systemctl enable mariadb
ss -tnlp
3. root(mysql) 보안 설정
mysql_secure_installation
mysql -u wpuser -p1234