web + was + db가 1개의 서버에 같이 있음
--mariadb server 구성
--database WebTest
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| WebTest |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.002 sec)
MariaDB [(none)]> use WebTest;
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
MariaDB [WebTest]>
MariaDB [WebTest]> show tables;
+-------------------+
| Tables_in_WebTest |
+-------------------+
| board |
| member |
+-------------------+
2 rows in set (0.000 sec)
MariaDB [WebTest]> desc member;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| no | int(11) | NO | PRI | NULL | auto_increment |
| u_id | varchar(20) | NO | UNI | NULL | |
| u_pass | varchar(50) | NO | | NULL | |
| u_name | varchar(20) | NO | | NULL | |
| nickname | char(20) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| email | char(50) | YES | | NULL | |
| reg_date | datetime | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
8 rows in set (0.001 sec)
MariaDB [WebTest]> desc board
-> ;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| strNumber | int(11) | NO | PRI | NULL | auto_increment |
| strName | varchar(20) | NO | | NULL | |
| strPassword | varchar(20) | NO | | NULL | |
| strEmail | varchar(50) | YES | | NULL | |
| strSubject | varchar(100) | NO | | NULL | |
| strContent | text | NO | | NULL | |
| htmlTag | char(1) | NO | | NULL | |
| viewCount | int(11) | NO | | 0 | |
| filename | varchar(50) | YES | | NULL | |
| filesize | int(11) | YES | | NULL | |
| writeDate | datetime | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
11 rows in set (0.001 sec)
MariaDB [mysql]> select host,user,password from user;
+-----------+-------------+----------+
| Host | User | Password |
+-----------+-------------+----------+
| localhost | mariadb.sys | |
| localhost | root | invalid |
| localhost | mysql | invalid |
+-----------+-------------+----------+
3 rows in set (0.001 sec)
--password 자동으로 설정되었을때 invalid가 들어가므로 수동 설정
MariaDB [mysql]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("P@ssw0rd");
Query OK, 0 rows affected (0.001 sec)
MariaDB [mysql]>
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [mysql]> select host,user,password from user;
+-----------+-------------+-------------------------------------------+
| Host | User | Password |
+-----------+-------------+-------------------------------------------+
| localhost | mariadb.sys | |
| localhost | root | *8232A1298A49F710DBEE0B330C42EEC825D4190A |
| localhost | mysql | invalid |
+-----------+-------------+-------------------------------------------+
3 rows in set (0.001 sec)
db 설정 후에 snapshot 잡아주기
--webserver 구성
[root@realserver-02 ~]# dnf -y install httpd
[root@mariadbserver ~]# systemctl restart httpd
[root@mariadbserver ~]# vi /var/www/html/index.html
<html>
<head>
<title>200.200.200.148</title>
</head>
<body>
jiwon's mariadb server
</body>
</html>
--was 구성
[root@mariadbserver ~]# vi /etc/php-fpm.d/www.conf
391 ;security.limit_extensions = .php .php3 .php4 .php5 .php7
html , htm
<html>
</html>
<?php
;
?>
security.limit_extensions = .php .php3 .php4 .php5 .php7 .htm .html
<html>
<?php
;
?>
</html>
438 php_value[session.save_path] = /var/lib/php/session
[root@mariadbserver ~]# chmod 777 /var/lib/php/session/
[root@mariadbserver ~]# vi /etc/httpd/conf.d/php.conf
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
--관련 daemon
[root@mariadbserver ~]# systemctl start php-fpm.service
[root@mariadbserver ~]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; preset: disabled)
Active: active (running) since Mon 2024-03-25 09:47:48 KST; 1s ago
[root@mariadbserver ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.service.d
└─php-fpm.conf
Active: active (running) since Mon 2024-03-25 09:33:41 KST; 14min ago
[root@mariadbserver ~]# systemctl status mariadb.service
● mariadb.service - MariaDB 10.5 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Active: active (running) since Mon 2024-03-25 09:30:04 KST; 18min ago
[root@mariadbserver ~]# cd /var/www/html/
[root@mariadbserver html]# ls
index.html
[root@mariadbserver html]# vi info.php
<?php
phpinfo();
?>
[root@mariadbserver html]# systemctl restart httpd
<?php
//dbconn.php : 데이터베이스 접속용
//DB 접근 성공,실패 여부 확인
//mysqli_connect("호스트주소","사용자명","암호","DB명");
$conn = mysqli_connect("localhost","root","P@ssw0rd","WebTest");
if($conn){
echo"DB 연결 성공";
}
else{
echo"DB 연결 실패";
}
?>
--고의로 password 다르게 한 후에 test
<?php
//dbconn.php : 데이터베이스 접속용
//DB 접근 성공,실패 여부 확인
//mysqli_connect("호스트주소","사용자명","암호","DB명");
$conn = mysqli_connect("localhost","root","@ssw0rd","WebTest");
if($conn){
echo"DB 연결 성공";
}
else{
echo"DB 연결 실패";
}
?>
--외부에서 압축파일가져와서 /var/www/html/dkfodp vnfrl
[root@mariadbserver html]# ls
WebTest-php8-mariadb.tar.gz dbconn.php index.html info.php php_bool.php php_if.php
[root@mariadbserver html]# tar -xzvf WebTest-php8-mariadb.tar.gz
./
./index.html
./info.php
./board/
./board/board_write.php.bak
./board/upload/
./board/upload/.bash_history
./board/board_list.php
./board/board_view.php
./board/board_delete_ok.php
./board/board_file_download.php
./board/board_write.php
./board/board_write_ok.php
./member/
./member/member_nick_change.php
./member/member_login_check.php
./member/member_logout.php
./member/member_register.php
./member/member_register_ok.php
./member/member_info.php
./member/member_nick.php
./member/member_login.php
./member/member_info_change.php
./create_db.php
./db.sql
./dbconn.php.bak
./mysqli_query.php
./mysqli_query_insert.php
./mysqli_select_db.php
./test.php
./webtest_DB.sql
./index.php
./head.php
./style_contents.css
./style_head.css
./dbconn.php
./WebTest-php8-mariadb.tar.gz
[root@mariadbserver html]#
[root@mariadbserver html]# ls
WebTest-php8-mariadb.tar.gz dbconn.php.bak member php_if.php
board head.php mysqli_query.php style_contents.css
create_db.php index.html mysqli_query_insert.php style_head.css
db.sql index.php mysqli_select_db.php test.php
dbconn.php info.php php_bool.php webtest_DB.sql
--파일 자체를 index.php파일로 자동으로 연결되게 수정하는 방법과
--index.html 파일을 삭제하여 index.php를 인식하게 하는 방법
[root@mariadbserver html]# vi /etc/httpd/conf/httpd.conf
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
[root@mariadbserver html]# vi /etc/httpd/conf.d/php.conf
AddType text/html .php
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
--필자는 index.html 파일을 삭제함
[root@mariadbserver html]# rm -rf index.html
--database에 회원 정보 들어갔는지 확인
[root@mariadbserver html]# mysql -u root -pP@ssw0rd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.5.22-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)]> use WebTest;
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
MariaDB [WebTest]> select * from member;
+----+-----------+----------+-----------+----------+------+-------------------+---------------------+
| no | u_id | u_pass | u_name | nickname | age | email | reg_date |
+----+-----------+----------+-----------+----------+------+-------------------+---------------------+
| 1 | baejw0322 | P@ssw0rd | 배지원 | jiwonii | 24 | baejw03@naver.com | 2024-03-25 11:15:58 |
+----+-----------+----------+-----------+----------+------+-------------------+---------------------+
1 row in set (0.002 sec)
--게시판 내용 확인
[root@mariadbserver html]# mysql -u root -pP@ssw0rd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.5.22-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)]> use WebTest;
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
MariaDB [WebTest]> select * from board;
+-----------+-----------+-------------+-------------------+------------+------------+---------+-----------+----------+----------+---------------------+
| strNumber | strName | strPassword | strEmail | strSubject | strContent | htmlTag | viewCount | filename | filesize | writeDate |
+-----------+-----------+-------------+-------------------+------------+------------+---------+-----------+----------+----------+---------------------+
| 1 | 배지원 | P@ssw0rd | baejw03@naver.com | 1st | 1234 | T | 0 | | 0 | 2024-03-25 11:22:01 |
+-----------+-----------+-------------+-------------------+------------+------------+---------+-----------+----------+----------+---------------------+
1 row in set (0.000 sec)
--퍼미션 없으면 첨부파일 안들어감
[root@mariadbserver html]# ls -ld /var/www/html/board/upload/
drwxrwxrwx. 2 root root 27 3월 25 05:18 /var/www/html/board/upload/
--고의로 에러 낸 후 확인
session_start();
if (isset($_SESSION[nickname])) {
$nick = $_SESSION['nickname'];
echo $nick."님 ";
}
--원복
session_start();
if (isset($_SESSION['nickname'])) {
$nick = $_SESSION['nickname'];
echo $nick."님 ";
}
--주석 처리 후에 필요할 경우 주석 제거
//에러 확인용
//error_reporting(E_ALL);
//ini_set("display_errors",1);
[root@mariadbserver member]# vi member_login_check.php
$strSQL="select * from member where u_id='".$id."' and u_pass='".$pw."'";
'IaC Application > 3tier-service' 카테고리의 다른 글
2tier - service (0) | 2024.03.25 |
---|---|
DBMS 실습 (0) | 2024.03.22 |