"CentOS APM 설치 (yum)"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight ))
6번째 줄: 6번째 줄:
==설치 전 확인==
==설치 전 확인==
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
rpm -qa | egrep "^(httpd|php|mysql)"
rpm -qa | egrep "^(httpd|php|mysql)"
</source>
</source>


;실행 예시
;실행 예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# rpm -qa | egrep "^(httpd|php|mysql)"
[root@zetawiki ~]# rpm -qa | egrep "^(httpd|php|mysql)"
mysql-libs-5.1.61-4.el6.x86_64
mysql-libs-5.1.61-4.el6.x86_64
20번째 줄: 20번째 줄:
여기서는 '''[[Daum repo]]'''를 사용한다.
여기서는 '''[[Daum repo]]'''를 사용한다.
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
yum install httpd mysql mysql-server php php-mysql
yum install httpd mysql mysql-server php php-mysql
</source>
</source>


;실행결과
;실행결과
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# yum install httpd mysql mysql-server php php-mysql
[root@zetawiki ~]# yum install httpd mysql mysql-server php php-mysql
... (생략)
... (생략)
59번째 줄: 59번째 줄:
Is this ok [y/N]: y
Is this ok [y/N]: y
</source>
</source>
<source lang='console'>
<syntaxhighlight lang='console'>
... (생략)
... (생략)
Installed:
Installed:
79번째 줄: 79번째 줄:


==설치 후 확인==
==설치 후 확인==
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# rpm -qa | egrep "^(httpd|php|mysql)" | sort -n
[root@zetawiki ~]# rpm -qa | egrep "^(httpd|php|mysql)" | sort -n
httpd-2.2.15-26.el6.centos.x86_64
httpd-2.2.15-26.el6.centos.x86_64
95번째 줄: 95번째 줄:
==서비스 등록 확인==
==서비스 등록 확인==
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
service httpd status
service httpd status
service mysqld status
service mysqld status
102번째 줄: 102번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service httpd status
[root@zetawiki ~]# service httpd status
httpd is stopped
httpd is stopped
</source>
</source>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service mysqld status
[root@zetawiki ~]# service mysqld status
mysqld is stopped
mysqld is stopped
</source>
</source>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# php -v
[root@zetawiki ~]# php -v
PHP 5.3.3 (cli) (built: Feb 22 2013 02:51:11)  
PHP 5.3.3 (cli) (built: Feb 22 2013 02:51:11)  
120번째 줄: 120번째 줄:
==httpd 시작 및 설정 ==
==httpd 시작 및 설정 ==
{{참고|httpd: Could not reliably determine the server's fully qualified domain name}}
{{참고|httpd: Could not reliably determine the server's fully qualified domain name}}
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service httpd start
[root@zetawiki ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 111.222.33.44 for ServerName
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 111.222.33.44 for ServerName
128번째 줄: 128번째 줄:


;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
sed -i 's/\#ServerName www.example.com:80/ServerName www.example.com:80/g' /etc/httpd/conf/httpd.conf
sed -i 's/\#ServerName www.example.com:80/ServerName www.example.com:80/g' /etc/httpd/conf/httpd.conf
136번째 줄: 136번째 줄:


;실행예시 (jmnote)
;실행예시 (jmnote)
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
[root@zetawiki ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
[root@zetawiki ~]# sed -i 's/\#ServerName www.example.com:80/ServerName www.jmnote.com:80/g' /etc/httpd/conf/httpd.conf
[root@zetawiki ~]# sed -i 's/\#ServerName www.example.com:80/ServerName www.jmnote.com:80/g' /etc/httpd/conf/httpd.conf
147번째 줄: 147번째 줄:


이제 httpd를 다시 시작해보면...
이제 httpd를 다시 시작해보면...
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service httpd restart
[root@zetawiki ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Stopping httpd:                                            [  OK  ]
155번째 줄: 155번째 줄:


==mysqld 시작 테스트==
==mysqld 시작 테스트==
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service mysqld start
[root@zetawiki ~]# service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
Initializing MySQL database:  Installing MySQL system tables...
196번째 줄: 196번째 줄:
MySQL 패스워드를 지정하고 테스트해보자.
MySQL 패스워드를 지정하고 테스트해보자.
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
/usr/bin/mysqladmin -u root password 'P@ssw0rd'
/usr/bin/mysqladmin -u root password 'P@ssw0rd'
mysql -u root -p
mysql -u root -p
203번째 줄: 203번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# /usr/bin/mysqladmin -u root password 'P@ssw0rd'
[root@zetawiki ~]# /usr/bin/mysqladmin -u root password 'P@ssw0rd'
[root@zetawiki ~]# mysql -u root -p
[root@zetawiki ~]# mysql -u root -p
209번째 줄: 209번째 줄:
</source>
</source>
:→ 지정한 패스워드 입력 후 {{Enter}}
:→ 지정한 패스워드 입력 후 {{Enter}}
<source lang='console'>
<syntaxhighlight lang='console'>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Your MySQL connection id is 4
223번째 줄: 223번째 줄:
</source>
</source>
:→ <code>show databases;</code> 입력 후 {{Enter}}
:→ <code>show databases;</code> 입력 후 {{Enter}}
<source lang='console'>
<syntaxhighlight lang='console'>
mysql> show databases;
mysql> show databases;
+--------------------+
+--------------------+
237번째 줄: 237번째 줄:
</source>
</source>
:→ <code>quit</code> 입력 후 {{Enter}}
:→ <code>quit</code> 입력 후 {{Enter}}
<source lang='console'>
<syntaxhighlight lang='console'>
mysql> quit
mysql> quit
Bye
Bye
244번째 줄: 244번째 줄:
==재부팅시 자동시작 설정==
==재부팅시 자동시작 설정==
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
chkconfig --list | egrep "mysqld|httpd"
chkconfig --list | egrep "mysqld|httpd"
chkconfig mysqld on
chkconfig mysqld on
252번째 줄: 252번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# chkconfig --list | egrep "mysqld|httpd"
[root@zetawiki ~]# chkconfig --list | egrep "mysqld|httpd"
httpd          0:off 1:off 2:off 3:off 4:off 5:off 6:off
httpd          0:off 1:off 2:off 3:off 4:off 5:off 6:off
258번째 줄: 258번째 줄:
</source>
</source>
:→ 서버 재부팅시 아파치와 MySQL이 자동으로 시작되지 않는다.
:→ 서버 재부팅시 아파치와 MySQL이 자동으로 시작되지 않는다.
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# chkconfig mysqld on
[root@zetawiki ~]# chkconfig mysqld on
[root@zetawiki ~]# chkconfig httpd on
[root@zetawiki ~]# chkconfig httpd on
266번째 줄: 266번째 줄:
</source>
</source>
:→ 런레벨 3~5일 때 데몬을 자동시작하도록 설정되었다.
:→ 런레벨 3~5일 때 데몬을 자동시작하도록 설정되었다.
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# reboot
[root@zetawiki ~]# reboot
</source>
</source>
:→ 실제로 재부팅하여 자동시작되는지 확인해보자.
:→ 실제로 재부팅하여 자동시작되는지 확인해보자.
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service httpd status
[root@zetawiki ~]# service httpd status
httpd (pid  1278) is running...
httpd (pid  1278) is running...
</source>
</source>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# service mysqld status
[root@zetawiki ~]# service mysqld status
mysqld (pid  1174) is running...
mysqld (pid  1174) is running...
283번째 줄: 283번째 줄:
외부에서 접근할수 있도록 80포트를 연다.
외부에서 접근할수 있도록 80포트를 연다.
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables save
290번째 줄: 290번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@zetawiki ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@zetawiki ~]# /etc/init.d/iptables save
[root@zetawiki ~]# /etc/init.d/iptables save
303번째 줄: 303번째 줄:
==PHP 동작 확인==
==PHP 동작 확인==
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
php -r 'echo "Hello World\n";'
php -r 'echo "Hello World\n";'
</source>
</source>


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# php -r 'echo "Hello World\n";'
[root@zetawiki ~]# php -r 'echo "Hello World\n";'
Hello World
Hello World
315번째 줄: 315번째 줄:
==브라우저 확인 (1)==
==브라우저 확인 (1)==
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
echo "<?php echo 'Hello';?>" > /var/www/html/hello.php
echo "<?php echo 'Hello';?>" > /var/www/html/hello.php
cat /var/www/html/hello.php
cat /var/www/html/hello.php
321번째 줄: 321번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@jmntote ~]# echo "<?php echo 'Hello';?>" > /var/www/html/hello.php
[root@jmntote ~]# echo "<?php echo 'Hello';?>" > /var/www/html/hello.php
[root@jmntote ~]# cat /var/www/html/hello.php
[root@jmntote ~]# cat /var/www/html/hello.php
332번째 줄: 332번째 줄:
오류가 있는 PHP 코드를 넣어보자.
오류가 있는 PHP 코드를 넣어보자.
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
echo "<?php Hello ?>" > /var/www/html/hello_err.php
echo "<?php Hello ?>" > /var/www/html/hello_err.php
cat /var/www/html/hello_err.php
cat /var/www/html/hello_err.php
338번째 줄: 338번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# echo "<?php Hello ?>" > /var/www/html/hello_err.php
[root@zetawiki ~]# echo "<?php Hello ?>" > /var/www/html/hello_err.php
[root@zetawiki ~]# cat /var/www/html/hello_err.php
[root@zetawiki ~]# cat /var/www/html/hello_err.php
348번째 줄: 348번째 줄:


;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
cp /etc/php.ini /etc/php.ini.default
cp /etc/php.ini /etc/php.ini.default
sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini
sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini
356번째 줄: 356번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cp /etc/php.ini /etc/php.ini.default
[root@zetawiki ~]# cp /etc/php.ini /etc/php.ini.default
[root@zetawiki ~]# sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini
[root@zetawiki ~]# sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini
369번째 줄: 369번째 줄:
</source>
</source>
다시 브라우저에서 http://서버IP/hello_err.php 에 접속해보자. 이번에는 아래와 같이 오류 메시지가 나타날 것이다.
다시 브라우저에서 http://서버IP/hello_err.php 에 접속해보자. 이번에는 아래와 같이 오류 메시지가 나타날 것이다.
<source lang='text'>
<syntaxhighlight lang='text'>
Notice: Use of undefined constant Hello - assumed 'Hello' in /var/www/html/hello_err.php on line 1
Notice: Use of undefined constant Hello - assumed 'Hello' in /var/www/html/hello_err.php on line 1
</source>
</source>
375번째 줄: 375번째 줄:
==PHP-MySQL 연동 확인==
==PHP-MySQL 연동 확인==
;명령어
;명령어
<source lang='bash'>
<syntaxhighlight lang='bash'>
echo '<?php
echo '<?php
$db = new mysqli("localhost", "root", "P@ssw0rd", "test");
$db = new mysqli("localhost", "root", "P@ssw0rd", "test");
391번째 줄: 391번째 줄:


;실행예시
;실행예시
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# echo '<?php
[root@zetawiki ~]# echo '<?php
> $db = new mysqli("localhost", "root", "P@ssw0rd", "test");
> $db = new mysqli("localhost", "root", "P@ssw0rd", "test");
403번째 줄: 403번째 줄:
> ?>' > /var/www/html/hello_db.php
> ?>' > /var/www/html/hello_db.php
</source>
</source>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cat /var/www/html/hello_db.php
[root@zetawiki ~]# cat /var/www/html/hello_db.php
<?php
<?php
419번째 줄: 419번째 줄:
;브라우저 결과
;브라우저 결과
브라우저에서 http://서버IP/hello_db.php 에 접속해보자.
브라우저에서 http://서버IP/hello_db.php 에 접속해보자.
<source lang='text'>
<syntaxhighlight lang='text'>
stdClass Object
stdClass Object
(
(

2020년 11월 2일 (월) 00:40 판

리눅스 APM 설치
리눅스 Apache, PHP, MySQL 설치
리눅스 httpd, php, mysqld 설치

1 설치 전 확인

명령어

<syntaxhighlight lang='bash'> rpm -qa | egrep "^(httpd|php|mysql)" </source>

실행 예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# rpm -qa | egrep "^(httpd|php|mysql)" mysql-libs-5.1.61-4.el6.x86_64 </source>

→ 설치되지 않았다.[1]

2 설치

여기서는 Daum repo를 사용한다.

명령어

<syntaxhighlight lang='bash'> yum install httpd mysql mysql-server php php-mysql </source>

실행결과

<syntaxhighlight lang='console'> [root@zetawiki ~]# yum install httpd mysql mysql-server php php-mysql ... (생략)

2.1 ================================================================================================
Package                     Arch                Version                            Repository         Size
2.2 ================================================================================================

Installing:

httpd                       x86_64              2.2.15-26.el6.centos               base              821 k
mysql                       x86_64              5.1.66-2.el6_3                     base              885 k
mysql-server                x86_64              5.1.66-2.el6_3                     base              8.6 M
php                         x86_64              5.3.3-22.el6                       base              1.1 M
php-mysql                   x86_64              5.3.3-22.el6                       base               81 k

Installing for dependencies:

apr                         x86_64              1.3.9-5.el6_2                      base              123 k
apr-util                    x86_64              1.3.9-3.el6_0.1                    base               87 k
apr-util-ldap               x86_64              1.3.9-3.el6_0.1                    base               15 k
httpd-tools                 x86_64              2.2.15-26.el6.centos               base               72 k
mailcap                     noarch              2.1.31-2.el6                       base               27 k
perl-DBD-MySQL              x86_64              4.013-3.el6                        base              134 k
perl-DBI                    x86_64              1.609-4.el6                        base              705 k
php-cli                     x86_64              5.3.3-22.el6                       base              2.2 M
php-common                  x86_64              5.3.3-22.el6                       base              524 k
php-pdo                     x86_64              5.3.3-22.el6                       base               75 k

Updating for dependencies:

mysql-libs                  x86_64              5.1.66-2.el6_3                     base              1.2 M

Transaction Summary

2.3 ================================================================================================

Install 15 Package(s) Upgrade 1 Package(s)

Total download size: 17 M Is this ok [y/N]: y </source> <syntaxhighlight lang='console'> ... (생략) Installed:

 httpd.x86_64 0:2.2.15-26.el6.centos mysql.x86_64 0:5.1.66-2.el6_3   mysql-server.x86_64 0:5.1.66-2.el6_3
 php.x86_64 0:5.3.3-22.el6           php-mysql.x86_64 0:5.3.3-22.el6

Dependency Installed:

 apr.x86_64 0:1.3.9-5.el6_2                          apr-util.x86_64 0:1.3.9-3.el6_0.1                     
 apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1              httpd-tools.x86_64 0:2.2.15-26.el6.centos             
 mailcap.noarch 0:2.1.31-2.el6                       perl-DBD-MySQL.x86_64 0:4.013-3.el6                   
 perl-DBI.x86_64 0:1.609-4.el6                       php-cli.x86_64 0:5.3.3-22.el6                         
 php-common.x86_64 0:5.3.3-22.el6                    php-pdo.x86_64 0:5.3.3-22.el6                         

Dependency Updated:

 mysql-libs.x86_64 0:5.1.66-2.el6_3                                                                        

Complete! </source>

3 설치 후 확인

<syntaxhighlight lang='console'> [root@zetawiki ~]# rpm -qa | egrep "^(httpd|php|mysql)" | sort -n httpd-2.2.15-26.el6.centos.x86_64 httpd-tools-2.2.15-26.el6.centos.x86_64 mysql-5.1.66-2.el6_3.x86_64 mysql-libs-5.1.66-2.el6_3.x86_64 mysql-server-5.1.66-2.el6_3.x86_64 php-5.3.3-22.el6.x86_64 php-cli-5.3.3-22.el6.x86_64 php-common-5.3.3-22.el6.x86_64 php-mysql-5.3.3-22.el6.x86_64 php-pdo-5.3.3-22.el6.x86_64 </source>

4 서비스 등록 확인

명령어

<syntaxhighlight lang='bash'> service httpd status service mysqld status php -v </source>

실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# service httpd status httpd is stopped </source> <syntaxhighlight lang='console'> [root@zetawiki ~]# service mysqld status mysqld is stopped </source> <syntaxhighlight lang='console'> [root@zetawiki ~]# php -v PHP 5.3.3 (cli) (built: Feb 22 2013 02:51:11) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies </source>

→ 아파치와 MySQL이 서비스에 등록되어 있다. PHP를 쉘에서 사용할 수 있다.

5 httpd 시작 및 설정

<syntaxhighlight lang='console'> [root@zetawiki ~]# service httpd start Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 111.222.33.44 for ServerName

                                                          [  OK  ]

</source>

→ 정상이지만, 경고 메시지를 없애고 싶다.
명령어

<syntaxhighlight lang='bash'> cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default sed -i 's/\#ServerName www.example.com:80/ServerName www.example.com:80/g' /etc/httpd/conf/httpd.conf diff /etc/httpd/conf/httpd.conf.default /etc/httpd/conf/httpd.conf </source>

→ "www.example.com" 대신 자신의 도메인을 기입한다. 도메인이 없다면 그대로 두어도 무방하다.
실행예시 (jmnote)

<syntaxhighlight lang='console'> [root@zetawiki ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default [root@zetawiki ~]# sed -i 's/\#ServerName www.example.com:80/ServerName www.jmnote.com:80/g' /etc/httpd/conf/httpd.conf [root@zetawiki ~]# diff /etc/httpd/conf/httpd.conf.default /etc/httpd/conf/httpd.conf 276c276 < #ServerName www.example.com:80 --- > ServerName www.jmnote.com:80 </source>

이제 httpd를 다시 시작해보면... <syntaxhighlight lang='console'> [root@zetawiki ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] </source>

→ 경고 메시지가 사라졌다.

6 mysqld 시작 테스트

<syntaxhighlight lang='console'> [root@zetawiki ~]# service mysqld start Initializing MySQL database: Installing MySQL system tables... OK Filling help tables... OK

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h jmnote password 'new-password'

Alternatively you can run: /usr/bin/mysql_secure_installation

which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                          [  OK  ]

Starting mysqld: [ OK ] </source>

→ 정상이다. 1) 서버 재부팅시 자동시작 설정과, 2) root 패스워드 지정 안내이다. 다음 문단에서 처리할 것이므로 대충 보고 넘어가자.

7 MySQL 패스워드 지정, 테스트

MySQL 패스워드를 지정하고 테스트해보자.

명령어

<syntaxhighlight lang='bash'> /usr/bin/mysqladmin -u root password 'P@ssw0rd' mysql -u root -p </source>

→ P@ssw0rd 대신 원하는 패스워드를 기입한다.
실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# /usr/bin/mysqladmin -u root password 'P@ssw0rd' [root@zetawiki ~]# mysql -u root -p Enter password: </source>

→ 지정한 패스워드 입력 후 Enter

<syntaxhighlight lang='console'> Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.52 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> </source>

show databases; 입력 후 Enter

<syntaxhighlight lang='console'> mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec)

mysql> </source>

quit 입력 후 Enter

<syntaxhighlight lang='console'> mysql> quit Bye </source>

8 재부팅시 자동시작 설정

명령어

<syntaxhighlight lang='bash'> chkconfig --list | egrep "mysqld|httpd" chkconfig mysqld on chkconfig httpd on chkconfig --list | egrep "mysqld|httpd" </source>

실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# chkconfig --list | egrep "mysqld|httpd" httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off </source>

→ 서버 재부팅시 아파치와 MySQL이 자동으로 시작되지 않는다.

<syntaxhighlight lang='console'> [root@zetawiki ~]# chkconfig mysqld on [root@zetawiki ~]# chkconfig httpd on [root@zetawiki ~]# chkconfig --list | egrep "mysqld|httpd" httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off </source>

→ 런레벨 3~5일 때 데몬을 자동시작하도록 설정되었다.

<syntaxhighlight lang='console'> [root@zetawiki ~]# reboot </source>

→ 실제로 재부팅하여 자동시작되는지 확인해보자.

<syntaxhighlight lang='console'> [root@zetawiki ~]# service httpd status httpd (pid 1278) is running... </source> <syntaxhighlight lang='console'> [root@zetawiki ~]# service mysqld status mysqld (pid 1174) is running... </source>

→ 자동시작되었다.

9 iptables 80포트 열기

외부에서 접근할수 있도록 80포트를 연다.

명령어

<syntaxhighlight lang='bash'> iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/init.d/iptables save /etc/init.d/iptables restart </source>

실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT [root@zetawiki ~]# /etc/init.d/iptables save iptables: 방화벽 규칙을 /etc/sysconfig/iptables에 저장 중: [ OK ] [root@zetawiki ~]# /etc/init.d/iptables restart iptables: 체인을 ACCEPT 규칙으로 설정 중: filter [ OK ] iptables: 방화벽 규칙을 지웁니다: [ OK ] iptables: 모듈을 언로드하는 중: [ OK ] iptables: 방화벽 규칙 적용 중: [ OK ] </source>

10 PHP 동작 확인

명령어

<syntaxhighlight lang='bash'> php -r 'echo "Hello World\n";' </source>

실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# php -r 'echo "Hello World\n";' Hello World </source>

11 브라우저 확인 (1)

명령어

<syntaxhighlight lang='bash'> echo "<?php echo 'Hello';?>" > /var/www/html/hello.php cat /var/www/html/hello.php </source>

실행예시

<syntaxhighlight lang='console'> [root@jmntote ~]# echo "<?php echo 'Hello';?>" > /var/www/html/hello.php [root@jmntote ~]# cat /var/www/html/hello.php <?php echo 'Hello';?> </source>

12 브라우저 확인 (2) 오류 메시지 출력

오류가 있는 PHP 코드를 넣어보자.

명령어

<syntaxhighlight lang='bash'> echo "<?php Hello ?>" > /var/www/html/hello_err.php cat /var/www/html/hello_err.php </source>

실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# echo "<?php Hello ?>" > /var/www/html/hello_err.php [root@zetawiki ~]# cat /var/www/html/hello_err.php <?php Hello ?> </source>

php.ini의 display_errors를 On으로 바꾸고 httpd를 재시작하자.

명령어

<syntaxhighlight lang='bash'> cp /etc/php.ini /etc/php.ini.default sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini diff /etc/php.ini.default /etc/php.ini service httpd restart </source>

실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# cp /etc/php.ini /etc/php.ini.default [root@zetawiki ~]# sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini [root@zetawiki ~]# diff /etc/php.ini.default /etc/php.ini 530c530 > display_errors = Off --- < display_errors = On [root@zetawiki ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] </source> 다시 브라우저에서 http://서버IP/hello_err.php 에 접속해보자. 이번에는 아래와 같이 오류 메시지가 나타날 것이다. <syntaxhighlight lang='text'> Notice: Use of undefined constant Hello - assumed 'Hello' in /var/www/html/hello_err.php on line 1 </source>

13 PHP-MySQL 연동 확인

명령어

<syntaxhighlight lang='bash'> echo '<?php $db = new mysqli("localhost", "root", "P@ssw0rd", "test"); if ($db->connect_errno) die("Connect failed: ".$db->connect_error); $result = $db->query("SHOW DATABASES;"); echo "<xmp>"; while ($row = $result->fetch_object()) print_r($row); echo "</xmp>"; $result->close(); $db->close(); ?>' > /var/www/html/hello_db.php cat /var/www/html/hello_db.php </source>

→ P@ssw0rd 대신 앞서 지정한 MySQL 패스워드를 기입한다.
실행예시

<syntaxhighlight lang='console'> [root@zetawiki ~]# echo '<?php > $db = new mysqli("localhost", "root", "P@ssw0rd", "test"); > if ($db->connect_errno) die("Connect failed: ".$db->connect_error); > $result = $db->query("SHOW DATABASES;"); > echo "<xmp>"; > while ($row = $result->fetch_object()) print_r($row); > echo "</xmp>"; > $result->close(); > $db->close(); > ?>' > /var/www/html/hello_db.php </source> <syntaxhighlight lang='console'> [root@zetawiki ~]# cat /var/www/html/hello_db.php <?php $db = new mysqli("localhost", "root", "P@ssw0rd", "test"); if ($db->connect_errno) die("Connect failed: ".$db->connect_error); $result = $db->query("SHOW DATABASES;"); echo "<xmp>"; while ($row = $result->fetch_object()) print_r($row); echo "</xmp>"; $result->close(); $db->close(); ?> </source>

브라우저 결과

브라우저에서 http://서버IP/hello_db.php 에 접속해보자. <syntaxhighlight lang='text'> stdClass Object (

   [Database] => information_schema

) stdClass Object (

   [Database] => mysql

) stdClass Object (

   [Database] => test

) </source>

→ mysql 설치시 기본으로 생성되는 DB 3개가 보인다.
→ 만약 Fatal error: Class 'mysqli' not found 오류 나면 해당 글 참조

14 기타 설정

필요시 설정하자.

웹 소프트웨어 설치

15 같이 보기

16 주석

  1. CentOS 6 최소 설치 209개 패키지 중에 mysql-libs가 있을 뿐 mysql이 설치된 것은 아니다.
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}