Notice
Recent Posts
Recent Comments
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

ITFragile

[Ansible] 07. php 활성화 본문

Project

[Ansible] 07. php 활성화

경요 2023. 3. 16. 17:24

 

 

1. DB와 WEB을 연결해주기 위해 main 플레이북 하단에 새 파일 연결

# main.yaml

- name: DB WEB Connection
  hosts: web
  tasks:
  	- import_tasks: php.yaml

 

2. php 설치 및 index.php 전달

# php.yaml

- name: yum install python
  apt:
    name:
      - python3-pymysql
      - php
      - php-mysql
    state: latest
- name: copy index.php 
  template: # 템플릿 파일을 지정된 이름으로 원격 서버에 복사
    src: index.php
    dest: /var/www/html
- name: restart apache2
  service:
    name: apache2
    state: restarted

3. index.php 작성

# index.php

<?php
$server_addr = "192.168.56.104"; #DB-m01 ip 주소
$user_name = "web_user";
$password = "12345";
$db_name = "webdb";
$connection = mysqli_connect($server_addr, $user_name, $password, $db_name);
$query = "SELECT * FROM web_tb";
$rst = mysqli_query($connection, $query);

if (mysqli_num_rows($rst) > 0) {
  while($i = mysqli_fetch_assoc($rst)) {
    echo "id : "  .  $i["id"]  .  " | name : "  .  $i["name"]  .   "<br>" ;
  }
}
mysqli_close($connection);
?>

 

4. 앤서블 실행

 

5. 접속 확인

#  web-01
cat /var/www/html/index.php

성공적으로 db 출력됨

 

'Project' 카테고리의 다른 글

[Kubernetes] 01. 작업 환경 구성  (0) 2023.03.20
[Ansible] 08. DB 로드밸런싱  (0) 2023.03.16
[Ansible] 06. mysql 구성하기  (0) 2023.03.16
[Ansible] 05. DB 이중화  (0) 2023.03.16
[Ansible] 04. WEB 로드밸런싱  (0) 2023.03.16