공부하기싫어
article thumbnail

 

1. 11.30 7:49 pm

 

저번에 개 ㅈㄹ 해도 안되서

천천히 다시 처음부터 해봤다

 

docker run

<bash />
docker run -it --name apache-server -d -p 8080:80 -v /home/ubuntu/html:/var/www/html php:7.3.3-apache

 

로컬 파일을 볼륨으로 마운트 해주는 부분을 추가해줬다

 

exec

 

이후 컨테이너 안에 들어가서

 

<bash />
apt-get update && apt-get upgrade -y apt-get install vim -y docker-php-ext-install mysqli

apt 업데이트 해주고

vim 편집기도 필요할 수 있으니까 설치해주고

mysqli 확장도 설치해줬다

 

<html />
root@1bd9b36c99af:/var/www/html# cat sample.html <!DOCTYPE html> <html> <body> <h1> PHP 페이지를 만들어 봅니다.</h1> <?php echo "Hello World!\n"; //mysql 접속 계정 정보 설정 $mysql_host = [mysql 컨테이너 ip:port]; $mysql_user = 'root'; $mysql_password = [비밀번호]; $mysql_db = 'blackpink'; /* //connect 설정(host,user,password) $conn = @mysqli_connect($mysql_host,$mysql_user,$mysql_password); //db 연결 $dbconn = mysql_select_db($mysql_db,$conn); //charset UTF8 mysql_query("set names utf8"); //쿼리문 작성 $query = "select * from blackpink_img_data where DB_MONTH >= 9"; //쿼리보내고 결과를 변수에 저장 $result = mysql_query($query); while($row = mysql_fetch_array($result)){ echo "<div class='col-4'><span class='image fit'><img src='".$row[DB_S3URL]."' alt='' /></span></div>"; } */ $conn = new mysqli($mysql_host, $mysql_user, $mysql_password, $mysql_db); if($conn -> connect_error){ echo 'connection failed' . $conn -> connect_error; } echo 'Sucessfully connected to MYSQL'; ?> </body> </html>

 

간단하게 mysql 컨테이너에 연결한 후 결과를 출력하는 것만 해보려고 했는데

 

?

뭐 어쩌란건지 ㅋㅋ

 

찾아보니 인코딩 문제라고 함

<html />
<!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <body> <h1> PHP 페이지를 만들어 봅니다.</h1> <?php header('Content-Type: text/html; charset=utf-8');

 

위처럼 html 에는 meta 태그를 붙여줬고

php 에는 header 함수를 추가해줬는데

 

html 코드 중간이 그대로 출력되버리는데..

저기 주석 안의 내용인데 왜...?

 

 

 

11.30 8:36 pm

mod_mime.c

addtype 해주고 여기에 html 이랑 htm 까지 넣어줬다

두개 언어 문법을 혼용해서 쓸때 생기는 에러라고 한다

 

그랬더니

 

ㅋㅋ

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/sample.html:1) in /var/www/html/sample.html on line 7
Hello World!
Warning: mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /var/www/html/sample.html on line 17

Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /var/www/html/sample.html on line 17
connection failedThe server requested authentication method unknown to the clientSucessfully connected to MYSQL

 

mysql 이랑 연결이 뭐 어떻게 잘못된거같은데

흠..

 

찾아보니 mysql 8버전 이상에서는 caching_sha2_password 플러그인을 사용한 mysql_native_password 인증 방법을 사용한다고 함

php7 버전은 이 방식을 지원하지 않나봄

 

그래서 mysql 인증 플러그인 유형을 변경해줌

 

<shell />
ubuntu@blackpinkinyourarea:~$ docker exec -it mysql-db bash bash-4.4# bash-4.4# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 38 Server version: 8.0.31 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '비밀번호'; Query OK, 0 rows affected (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)

2.  

 

3. 12.01 9:15 am

위의 dml 에서 처음엔 'root'@'localhost' 로 입력해서 안되가지고 좀 찾아봤는데

localhost 대신 % 로 해야 외부 접속에 대해서 mysql_native_password 접속 방식? 을 사용할 수 있나보다

 

남은 에러

자 이제 이것만 남았다

뒤에 successfully connected to mysql 이라고 뜬거 보니까 mysql 접속에는 성공한듯

 

저 에러 해결해볼려고 했는데 어차피 php utf-8 인코딩이 특별히 필요한건 아니라서 주석처리해줬다

 

이후 index.html 코드에 반영해봤는데

<php />
<?php //mysql 접속 계정 정보 설정 $mysql_host = HOST_IP:PORT; $mysql_user = 'root'; $mysql_password = PASSWORD; $mysql_db = 'blackpink'; //connect 설정(host,user,password) $conn = new mysqli($mysql_host, $mysql_user, $mysql_password, $mysql_db); //charset UTF8 //mysqli_query("set names utf8"); //쿼리문 작성 $query = "select * from blackpink_img_data where DB_MONTH >= 9"; //쿼리보내고 결과를 변수에 저장 $result = mysqli_query($conn, $query); if ($result) { while($row = mysqli_fetch_array($result)){ echo "<div class='col-4'><span class='image fit'><img src='".$row[DB_S3URL]."' alt='' /></span></div>"; }//while end mysqli_free_result($result); //메모리에서 result 삭제 }//if end else { echo "Error : ".mysqli_error($conn); } mysqli_close($conn) ?>

이렇게 해주고 실행해봤는데

 

흠...

 

Warning: Use of undefined constant DB_S3URL - assumed 'DB_S3URL' (this will throw an Error in a future version of PHP) in/var/www/html/index.htmlon line99

 

이라고 나온다

 

php 대괄호 안에 '' 를 해주면 된다고 함

 

^^

12장이 모두 불러와진 모습이다.

 

index.html 안의 코드

<php />
<?php //mysql 접속 계정 정보 설정 $mysql_host = HOSTIP:PORT; $mysql_user = 'root'; $mysql_password = PASSWORD; $mysql_db = 'blackpink'; //connect 설정(host,user,password) $conn = new mysqli($mysql_host, $mysql_user, $mysql_password, $mysql_db); //charset UTF8 //mysqli_query("set names utf8"); //쿼리문 작성 $query = "select * from blackpink_img_data where DB_MONTH >= 9 limit 12"; //쿼리보내고 결과를 변수에 저장 $result = mysqli_query($conn, $query); if ($result) { while($row = mysqli_fetch_array($result)){ echo "<div class='col-4'><span class='image fit'><img src='".$row['DB_S3URL']."' alt='' /></span></div>"; }//while end mysqli_free_result($result); //메모리에서 result 삭제 }//if end else { echo "Error : ".mysqli_error($conn); } mysqli_close($conn) ?>

 

이따가 학교가서 python 으로 mysql 에 데이터를 넣는

def insert_data_to_mysql(row_list)

이 함수를 완성시켜봐야겠다.

 

 

그리고

구름 쿠버네티스 과정에서 했었던 CICD 실습을 한번 적용해봐야겠다.

내 ip 나 비밀번호가 담긴 파일은 따로 빼서 구성해야할듯 하다

public 에 올릴꺼라

 

https://crispyblog.kr/development/common/10

 

Crispy's Blog

 

crispyblog.kr

 

 

 

 

4. 참고

apache, php docker-compose
https://blog.leedoing.com/186

docker volume
https://conanglog.tistory.com/71

php/html 한글 인코딩
https://blog.naver.com/PostView.nhn?blogId=vnemftnsska2&logNo=221497907063&parentCategoryNo=&categoryNo=34&viewDate=&isShowPopularPosts=true&from=search

addtype application
https://www.codingfactory.net/11810

mysql authentication
https://www.skynats.com/blog/mysql-error-the-server-requested-authentication-method-unknown-to-the-client/