CentOS APM 설치 (yum)

Jmnote (토론 | 기여)님의 2012년 10월 2일 (화) 00:39 판 (→‎설치 전 확인)
리눅스 APM 설치
리눅스 Apache, PHP, MySQL 설치
리눅스 httpd, php, mysqld 설치

1 설치 전 확인

명령어
rpm -qa | egrep "^(httpd|php|mysql)"
실행 예시
[root@jmnote ~]# rpm -qa | egrep "^(httpd|php|mysql)"
mysql-libs-5.1.47-4.el6.x86_64
→ 설치되지 않았다.[1]

2 설치

여기서는 CentOS-Base.repo의 Daum 저장소를 사용한다.

명령어
yum install httpd -y
yum install mysql -y
yum install mysql-server -y
yum install php -y
yum install php-mysql -y
실행결과
[root@jmnote ~]# yum install httpd -y
... (생략)
============================================================================================================
 Package                    Arch                Version                             Repository         Size
============================================================================================================
Installing:
 httpd                      x86_64              2.2.15-15.el6.centos                Daum              809 k
Installing for dependencies:
 apr                        x86_64              1.3.9-3.el6_1.2                     Daum              123 k
 apr-util                   x86_64              1.3.9-3.el6_0.1                     Daum               87 k
 apr-util-ldap              x86_64              1.3.9-3.el6_0.1                     Daum               15 k
 httpd-tools                x86_64              2.2.15-15.el6.centos                Daum               70 k
 mailcap                    noarch              2.1.31-2.el6                        Daum               27 k
 
Transaction Summary
============================================================================================================
Install       6 Package(s)
Upgrade       0 Package(s)
... (생략)
Complete!
[root@jmnote ~]# yum install mysql -y
... (생략)
============================================================================================================
 Package                          Arch              Version                           Repository       Size
============================================================================================================
Installing:
 mysql                            x86_64            5.1.52-1.el6_0.1                  Daum            889 k
Installing for dependencies:
 perl                             x86_64            4:5.10.1-119.el6_1.1              Daum             10 M
 perl-Module-Pluggable            x86_64            1:3.90-119.el6_1.1                Daum             37 k
 perl-Pod-Escapes                 x86_64            1:1.04-119.el6_1.1                Daum             30 k
 perl-Pod-Simple                  x86_64            1:3.13-119.el6_1.1                Daum            209 k
 perl-libs                        x86_64            4:5.10.1-119.el6_1.1              Daum            575 k
 perl-version                     x86_64            3:0.77-119.el6_1.1                Daum             49 k
Updating for dependencies:
 mysql-libs                       x86_64            5.1.52-1.el6_0.1                  Daum            1.2 M

Transaction Summary
============================================================================================================
Install       7 Package(s)
Upgrade       1 Package(s)
... (생략)
Complete!
[root@jmnote ~]# yum install mysql-server -y
... (생략)
============================================================================================================
 Package                      Arch                 Version                         Repository          Size
============================================================================================================
Installing:
 mysql-server                 x86_64               5.1.52-1.el6_0.1                Daum               8.1 M
Installing for dependencies:
 perl-DBD-MySQL               x86_64               4.013-3.el6                     Daum               134 k
 perl-DBI                     x86_64               1.609-4.el6                     Daum               705 k

Transaction Summary
============================================================================================================
... (생략)
[root@jmnote ~]# yum install php -y
... (생략)
============================================================================================================
 Package                 Arch                Version                                Repository         Size
============================================================================================================
Installing:
 php                     x86_64              5.3.3-3.el6_1.3                        Daum              1.1 M
Installing for dependencies:
 libedit                 x86_64              2.11-4.20080712cvs.1.el6               Daum               74 k
 php-cli                 x86_64              5.3.3-3.el6_1.3                        Daum              2.2 M
 php-common              x86_64              5.3.3-3.el6_1.3                        Daum              522 k

Transaction Summary
============================================================================================================
Install       4 Package(s)
Upgrade       0 Package(s)
... (생략)
Complete!
[root@jmnote ~]# yum install php-mysql -y
... (생략)
============================================================================================================
 Package                  Arch                  Version                           Repository           Size
============================================================================================================
Installing:
 php-mysql                x86_64                5.3.3-3.el6_1.3                   Daum                 78 k
Installing for dependencies:
 php-pdo                  x86_64                5.3.3-3.el6_1.3                   Daum                 72 k

Transaction Summary
============================================================================================================
Install       2 Package(s)
Upgrade       0 Package(s)
... (생략)
Complete!

3 설치 후 확인

[root@jmnote ~]# rpm -qa | egrep "^(httpd|php|mysql)" | sort -n
httpd-2.2.15-15.el6.centos.x86_64
httpd-tools-2.2.15-15.el6.centos.x86_64
mysql-5.1.52-1.el6_0.1.x86_64
mysql-libs-5.1.52-1.el6_0.1.x86_64
mysql-server-5.1.52-1.el6_0.1.x86_64
php-5.3.3-3.el6_1.3.x86_64
php-cli-5.3.3-3.el6_1.3.x86_64
php-common-5.3.3-3.el6_1.3.x86_64
php-mysql-5.3.3-3.el6_1.3.x86_64
php-pdo-5.3.3-3.el6_1.3.x86_64

4 서비스 등록 확인

명령어
service httpd status
service mysqld status
php -v
실행예시
[root@jmnote ~]# service httpd status
httpd is stopped
[root@jmnote ~]# service mysqld status
mysqld is stopped
[root@jmnote ~]# php -v
PHP 5.3.3 (cli) (built: Nov  3 2011 12:00:26) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
→ 아파치와 MySQL이 서비스에 등록되어 있다. PHP를 쉘에서 사용할 수 있다.

5 httpd 시작 및 설정

[root@jmnote ~]# 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  ]
→ 정상이지만, 경고 메시지를 없애고 싶다.
명령어
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
sed -i 's/\#ServerName www.example.com:80/ServerName 도메인:80/g' /etc/httpd/conf/httpd.conf
diff /etc/httpd/conf/httpd.conf.default /etc/httpd/conf/httpd.conf
→ "도메인"에 자신의 도메인을 기입한다. 도메인이 없다면 IP를 적거나 그냥 www.example.com을 기입해도 무방하다.
실행예시 (jmnote)
[root@jmnote ~]# vi /etc/httpd/conf/httpd.conf
[root@jmnote ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.default
[root@jmnote ~]# sed -i 's/\#ServerName www.example.com:80/ServerName www.jmnote.com:80/g' /etc/httpd/conf/httpd.conf
[root@jmnote ~]# diff /etc/httpd/conf/httpd.conf.default /etc/httpd/conf/httpd.conf
276c276
< #ServerName www.example.com:80
---
> ServerName www.jmnote.com:80

이제 httpd를 다시 시작해보면...

[root@jmnote ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
→ 경고 메시지가 사라졌다.

6 mysqld 시작 테스트

[root@jmnote ~]# 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  ]
→ 정상이다. 1) 서버 재부팅시 자동시작 설정과, 2) root 패스워드 지정 안내이다. 다음 문단에서 처리할 것이므로 대충 보고 넘어가자.

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

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

명령어
/usr/bin/mysqladmin -u root password '패스워드'
mysql -u root -p
→ 원하는 패스워드를 기입한다.
실행예시
[root@jmnote ~]# /usr/bin/mysqladmin -u root password 'P@ssw0rd'
[root@jmnote ~]# mysql -u root -p
Enter password:
→ 지정한 패스워드 입력 후 Enter
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>
show databases; 입력 후 Enter
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql>
quit 입력 후 Enter
mysql> quit
Bye

8 재부팅시 자동시작 설정

명령어
chkconfig | egrep "(mysqld|httpd)"
chkconfig mysqld on
chkconfig httpd on
chkconfig | egrep "(mysqld|httpd)"
실행예시
[root@jmnote ~]# chkconfig | 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
→ 서버 재부팅시 아파치와 MySQL이 자동으로 시작되지 않는다.
[root@jmnote ~]# chkconfig mysqld on
[root@jmnote ~]# chkconfig httpd on
[root@jmnote ~]# chkconfig | 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
→ 런레벨 3~5일 때 데몬을 자동시작하도록 설정되었다.
[root@jmnote ~]# shutdown -r now
→ 실제로 재부팅하여 자동시작되는지 확인해보자.
[root@jmnote ~]# service httpd status
httpd (pid  1278) is running...
[root@jmnote ~]# service mysqld status
mysqld (pid  1174) is running...
→ 자동시작되었다.

9 PHP 동작 확인

명령어
php -r 'echo "Hello World\n";'
실행예시
[root@jmnote ~]# php -r 'echo "Hello World\n";'
Hello World

10 브라우저 확인 (1)

명령어
echo "<?php echo 'Hello';?>" > /var/www/html/hello.php
cat /var/www/html/hello.php
실행예시
[root@jmntote ~]# echo "<?php echo 'Hello';?>" > /var/www/html/hello.php
[root@jmntote ~]# cat /var/www/html/hello.php
<?php echo 'Hello';?>

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

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

명령어
echo "<?php Hello ?>" > /var/www/html/hello_err.php
cat /var/www/html/hello_err.php
실행예시
[root@jmnote ~]# echo "<?php Hello ?>" > /var/www/html/hello_err.php
[root@jmnote ~]# cat /var/www/html/hello_err.php
<?php Hello ?>

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

명령어
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
실행예시
[root@jmnote ~]# cp /etc/php.ini /etc/php.ini.default
[root@jmnote ~]# sed -i 's/\display_errors = Off/display_errors = On/g' /etc/php.ini
[root@jmnote ~]# diff /etc/php.ini.default /etc/php.ini
530c530
> display_errors = Off
---
< display_errors = On
[root@jmnote ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

다시 브라우저에서 http://서버IP/hello_err.php 에 접속해보자. 이번에는 아래와 같이 오류 메시지가 나타날 것이다.

Notice: Use of undefined constant Hello - assumed 'Hello' in /var/www/html/hello_err.php on line 1

12 PHP-MySQL 연동 확인

명령어
echo "<?php" > /var/www/html/hello_db.php
echo "\$db = new mysqli('localhost', 'root', '패스워드', 'test');" >> /var/www/html/hello_db.php
echo "if (\$db->connect_errno) die('Connect failed: '.\$db->connect_error);" >> /var/www/html/hello_db.php
echo "\$result = \$db->query('SHOW DATABASES;');" >> /var/www/html/hello_db.php
echo "echo '<xmp>';" >> /var/www/html/hello_db.php
echo "while (\$row = \$result->fetch_object()) print_r(\$row);" >> /var/www/html/hello_db.php
echo "echo '</xmp>';" >> /var/www/html/hello_db.php
echo "\$result->close();" >> /var/www/html/hello_db.php
echo "\$db->close();" >> /var/www/html/hello_db.php
echo "?>" >> /var/www/html/hello_db.php
cat /var/www/html/hello_db.php
→ 앞서 지정한 MySQL 패스워드를 기입한다.
실행예시
[root@jmnote ~]# echo "<?php" > /var/www/html/hello_db.php
[root@jmnote ~]# echo "\$db = new mysqli('localhost', 'root', 'P@ssw0rd', 'test');" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "if (\$db->connect_errno) die('Connect failed: '.\$db->connect_error);" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "\$result = \$db->query('SHOW DATABASES;');" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "echo '<xmp>';" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "while (\$row = \$result->fetch_object()) print_r(\$row);" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "echo '</xmp>';" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "\$result->close();" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "\$db->close();" >> /var/www/html/hello_db.php
[root@jmnote ~]# echo "?>" >> /var/www/html/hello_db.php
[root@jmnote ~]# 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();
?>
브라우저 결과

브라우저에서 http://서버IP/hello_db.php 에 접속해보자.

stdClass Object
(
    [Database] => information_schema
)
stdClass Object
(
    [Database] => mysql
)
stdClass Object
(
    [Database] => test
)
→ mysql 설치시 기본으로 생성되는 DB 3개가 보인다.

13 기타 설정

필요시 설정하자.

14 같이 보기

15 주석

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