Article sections

    https://hihighlinux.tistory.com/13

    MySQL DB 연동

    사용한OS – CentOS 7,  Windows7

    #CentOS7 설정
    1. yum -y install libjpeg* libpng* freetype* gd-* gcc gcc-c++ gdbm-devel libtermcap-devel
    2. yum -y install httpd
    3. MariaDB Yum 저장소 생성
    vi /etc/yum.repos.d/MariaDB.repo

    #MariaDB.repo 내용

    4. MariaDB 설치
    yum -y install mariadb-server
    5. PHP7 최신 버전을 설치하기 위한 yum 저장소 생성
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    6. PHP7 최신 버전 설치
    yum -y install php70w
    7. PHP7자주 사용하는 패키지
    yum -y install php70w-mysql php70w-pdo php70w-pgsql php70w-odbc php70w-mbstring php70w-mcrypt php70w-gd
    yum -y install php70w-pear php70w-pdo_dblib php70w-pecl-imagick php70w-pecl-imagick-devel php70w-xml php70w-xmlrpc
    8. 설정 파일 편집
    vi /etc/httpd/conf/httpd.conf

    66,67 번째 줄에  nobody추가

    96번째 줄  서버

    위 사진 양식에 맞게 주소 또는 아이피:80 포트번호 추가
    279

    275줄 AddType application/x-httpd-php .php .html .htm .inc
    AddType application/x-httpd-php-source .phps

    vi /etc/php.ini
    202 줄 short_open_tag=On으로 변경

    9 서비스 재시작
    systemctl restart httpd  ,  mariadb 서비스 재시작

    10 Mysql 설정
    mysql_secure_installation
    enter 누르고  비밀번호설정후 모든 질문에 default값으로 설정(y입력)
    11. database 및 table 생성
    mysql -u root -p // 접속

    create database 데이터베이스이름 default character set utf8;   //DB생성
    alter database hospital default character set utf8 collate utf8_general_ci; // DB변경
    grant all privileges on 데이터베이스이름.* to 아이디@’%’ identified by ‘비밀번호’; // 모든 원격지에서 접속 권한 추가(%)
    grant all privileges on 데이터베이스이름.* to 아이디@localhost identified by ‘비밀번호’;

    use 데이터베이스이름 //db 이동

    +++++
    create table board (               // table 생성
    num int(11) unsigned not null,
    thread int(11) not null,
    depth int(11) not null default 0,
    name varchar(20) not null,
    email varchar(30) not null,
    pass varchar(20) not null,
    title varchar(70) not null,
    content text not null,
    wdate datetime not null,
    ipaddr varchar(15) not null,
    wcount int(11) not null
    )engine=innoDB default charset=utf8;

    alter table board add constraint board_pk primary key (num);
    alter table board modify column num int(11) not null auto_increment;
    +++++

    12. 방화벽 설정
    firewall-cmd –permanent –add-service=http
    firewall-cmd –permanent –add-port=3306/tcp
    firewall-cmd –permanent –add-port=3306/udp
    firewall-cmd –reload

    13. php 연동 확인
    vi /var/www/html/phpinfo.php // phpinfo 확인 페이지 생성

    phpinfo.php 안의 내용

    브라우저에서 localhost/phpinfo.php or 127.0.0.1/phpinfo.php  로 접속

    vi /var/www/html/dbconn.php  -> 데이터베이스 연동 페이지 생성

    <?php
    $db_host = “localhost”;
    $db_user = “아이디”;
    $db_pw = “비밀번호”;
    $db_name = “데이터베이스이름”;
    $board = “생성한보드”;
    $conn = mysqli_connect($db_host, $db_user, $db_pw, $db_name);

    if(mysqli_connect_errno($conn))
    {
    echo “Database connect error :” ,mysqli_connect_errno();
    echo “<br>”;
    }
    else
    {
    echo “연결 완료!!!<br>”;
    }
    ?>

    브라우저로 확인

    in Server Doc