APM.vol1.egg


APM.vol2.egg


######################

## Apache webserver ##

######################


1. 가장 쉽게 웹서버를 사용해보기


1. 웹서버 설치하기

# tar xzf apache_1.3.41.tar.gz 

# cd apache_1.3.41

# ./configure 

# make

# make install




2. 웹서버 사용하기

# /usr/local/apache/bin/apachectl start

# netstat -nltp | grep 80



# cd /usr/local/apache/

# rm -rf *

# echo "Hello my webserver" >  index.html

# ifconfig eth0



웹브라우저로 접속해서 확인한다.



3. 가상호스트로 웹서버 설치하기

가장 쉽게 웹서버를 사용해보기 + 1 (모듈을 추가해서 설치하기)

sbs.com, www.sbs.com   /home/sbs/public_html

kbs.com, www.kbs.com   /home/kbs/public_html

mbc.com, www.mbc.com   /home/mbc/public_html


# cd /root/apache_1.3.41

# ./configure --enable-module=vhost_alias

# make

# make install



# mkdir -m 711 /etc/skel/public_html

(/etc/skel 디렉터리는 리눅스에서 사용자를 만들때 홈디렉터리에 기본적으로 들어갈 파일들이 있는 곳이다.)

# useradd sbs

# useradd kbs

# useradd mbc

# chmod 711 /home/???



- 웹페이지 생성

# install -m 644 -o sbs -g sbs /dev/null ~sbs/public_html/index.html

# install -m 644 -o kbs -g kbs /dev/null ~kbs/public_html/index.html

# install -m 644 -o mbc -g mbc /dev/null ~mbc/public_html/index.html



# for i in sbs kbs mbc

> do

>   echo "Welcome to ${i}.com" > /home/${i}/public_html/index.html

> done



# cat /home/???/public_html/index.html

Welcome to kbs.com

Welcome to mbc.com

Welcome to sbs.com



- 웹서버 세팅 

# vi /usr/local/apache/conf/httpd.conf

-- /usr/local/apache/conf/httpd.conf --

  :

  :

NameVirtualHost *:80


<VirtualHost *:80>

    DocumentRoot /home/sbs/public_html

    ServerName   sbs.com 

    ServerAlias  www.sbs.com

</VirtualHost>

<VirtualHost *:80>

    DocumentRoot /home/kbs/public_html

    ServerName   kbs.com

    ServerAlias  www.kbs.com

</VirtualHost>

<VirtualHost *:80>

    DocumentRoot /home/mbc/public_html

    ServerName   mbc.com

    ServerAlias  www.mbc.com

</VirtualHost>

-- /usr/local/apache/conf/httpd.conf --


시프트 + G 누르면 맨 아래로 이동 됨


거기에 가상 호스트 추가해주자



# vi /etc/hosts

- 윈도우는 (%systemroot%\system32\drivers\etc\hosts)

-- /etc/hosts --

  :

  :

192.168.56.200 sbs.com www.sbs.com  <-- 추가

192.168.56.200 kbs.com www.kbs.com  <-- 추가

192.168.56.200 mbc.com www.mbc.com  <-- 추가

-- /etc/hosts --



# /usr/local/apache/bin/apachectl restart



# yum -y install lynx



- 웹페이지 확인

# lynx --dump www.sbs.com


   Welcome to sbs.com


# lynx --dump sbs.com


   Welcome to sbs.com


# lynx --dump www.kbs.com


   Welcome to kbs.com


# lynx --dump kbs.com


   Welcome to kbs.com


# lynx --dump mbc.com


   Welcome to mbc.com


# lynx --dump www.mbc.com


   Welcome to mbc.com



4.  DSO 방식으로 웹서버 설치하기

- 설치된 아파치 웹서버를 삭제한다.

# /usr/local/apache/bin/apachectl stop

# apachectl stop

# rm -rf /usr/local/apache



- configure 옵션은 config.status 파일에 저장된다.

cd /root/apache_1.3.41

# ./configure  \                   

--prefix=/usr/local/apache \

--enable-shared=max \

--enable-rule=SHARED_CORE \

--enable-module=so \

--enable-module=vhost_alias


# make

# make install



- 런레벨 등록

# rm -rf /etc/init.d/httpd

# ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd  

# vi /etc/init.d/httpd 



-- /etc/init.d/httpd --

#!/bin/sh

# chkconfig: 2345 91 19               <-- 추가

# description: Apache web server      <-- 추가

  :

  :

-- /etc/init.d/httpd --



# chkconfig --add httpd

# chkconfig --list httpd

httpd           0:off 1:off 2:on 3:on 4:on 5:on 6:off



4. MySQL 설치하기

1. 패키지 확인 작업 

# rpm -qa |grep mysql   <-- 설치된 mysql 패키지가 있는지 확인한다. 

# yum grouplist 



# yum groupremove "MySQL Database"

# userdel -r mysql



# vi /usr/include/pthread.h 

...

  /* Linuxthreads */ <-- CentOS 5 에서는 반드시 추가해야 한다. CentOS 4에서는 들어있으므로 추가하지 않아도 된다. 

...


# tar xzf mysql-4.0.27.tar.gz 

# cd mysql-4.0.27



o 환경설정

# ./configure \

--prefix=/usr/local/mysql \

--localstatedir=/usr/local/mysql/data \

--with-mysqld-user=mysql \

--enable-thread-safe-client \

--with-charset=euc_kr  


o 컴파일 

# make 


o 설치 

# make install



o 세팅 

# cd support-files

# cp my-large.cnf /etc/my.cnf  <-- 설정파일 복사

# install -m 700 mysql.server /etc/init.d/mysqld  <-- 데몬실행 스크립트 복사

# chkconfig --add mysqld  <-- 부팅시 활성화 등록 

# chkconfig --list mysqld

mysqld         0:off 1:off 2:on 3:on 4:on 5:on 6:off



# /usr/local/mysql/bin/mysql_install_db  <-- DB 초기화 작업



# useradd -s /bin/false -d /usr/local/mysql/data -M -r -u 27 mysql  

# chown -R mysql.mysql /usr/local/mysql/data                         <-- mysql DB 디렉토리를 모두 mysql 권한으로 변경


# ln -s /usr/local/mysql/bin/* /usr/bin               <-- 실행파일 링크를 걸어준다. 

# ln -s /usr/local/mysql/libexec/mysqld /usr/sbin     <-- 실행파일 링크를 걸어준다. 


# /etc/init.d/mysqld start   <-- mysql 데몬 시작 


# netstat -nltp   <-- mysql 포트(3306) 확인 

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      12704/mysqld        

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3425/httpd          

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1748/sshd           

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3521/sendmail  



5. PHP 설치하기

# tar xzf php-4.4.8.tar.gz 

# cd php-4.4.8

# ./configure \

> --prefix=/usr/local/php \

> --with-apxs=/usr/local/apache/bin/apxs \

> --with-mysql


# make 

# make install



# cp php.ini-dist /usr/local/php/lib/php.ini

# ln -s /usr/local/php/bin/* /usr/bin

# ls /usr/local/apache/libexec

libphp4.so



# vi /usr/local/apache/conf/httpd.conf  

-- /usr/local/apache/conf/httpd.conf -- 

  :

  :

<IfModule mod_dir.c>  <-- 406번 라인 부근에 위치에 추가

    DirectoryIndex index.html  index.php index.php3 index.htm  

</IfModule>

  :

  :

AddType application/x-tar .tgz  <-- 801번 라인 부근에 위치

AddType application/x-httpd-php .php .php3 .html .htm  <-- PHP 파일

AddType application/x-httpd-php-source .phps           <-- PHP 소스 파일

-- /usr/local/apache/conf/httpd.conf -- 




# /usr/local/apache/bin/apachectl configtest

Syntax OK



# cd /usr/local/apache/htdocs

# rm -rf *

# touch index.html

# vi test.html



-- test.html --

<?

  phpinfo();

?>

-- test.html --



# /usr/local/apache/bin/apachectl restart



브라우저로 접근 : http://웹서버IP/test.html



6. PHP 프로그래밍


# vi index.html 

-- index.html --

<?php


// $a = 10;

$a = $_GET["number"];

echo $a;


?>

-- index.html --



http://웹서버ip/index.html 접근


vi index.html



http://웹서버ip/index.html 접근


아무것도 나타나지 않음



http://웹서버ip/index.html?number=20 접근


20 이 echo 됨







APM 삭제 및 YUM으로설치하기


- mysql 삭제 


# /etc/init.d/mysqld stop

# rm -f /etc/my.cnf 

# rm -f /etc/init.d/mysqld

# rm -f /usr/bin/mysql*

# rm -f /usr/sbin/mysqld

# userdel -r mysql

# rm -rf /usr/local/mysql

# 링크파일들 삭제 (ls -l /usr/bin | grep mysql)



- apache 삭제 

# /etc/init.d/httpd stop

# rm -rf /usr/local/apache

# 링크파일들 삭제 (ls -l /usr/bin | grep apache)


- php 삭제 

# rm -rf /usr/local/php

# 링크파일들 삭제 (ls -l /usr/bin | grep php)



Yum 을 이용한 APM 설치


# iptables -F

# LANG=C

# yum grouplist

# yum groupinstall "MySQL Database"

# yum groupinstall "Web Server"




# /etc/init.d/mysqld start



# rm -f ~/.my.cnf

# mysql

mysql> quit



# rm -rf /etc/init.d/httpd

# cp `which apachectl` /etc/init.d/httpd

# /etc/init.d/httpd start

# netstat -nltp  <-- 3306, 80 확인

# ifconfig eth0



호스트 OS 에서 접근했을때 페이지가 뜨면 성공



# vi /etc/httpd/conf.d/php.conf

-- /etc/httpd/conf.d/php.conf --

  :

  :

AddHandler php5-script .php .html .htm

AddType text/html .php .html .htm

  :

  :

-- /etc/httpd/conf.d/php.conf --



# /etc/init.d/httpd restart or apachectl restart


# echo '<? phpinfo(); ?>' > p.html



http://HostOS/p.html

호스트 OS 에서 접근했을때 php 페이지가 뜨면 성공



- yum 으로 설치한 APM 삭제

# /etc/init.d/mysqld stop

# /etc/init.d/httpd stop

# yum -y groupremove "MySQL Database" 

# yum -y groupremove "Web Server"

# rpm -qa | grep php

# yum -y remove php-common php-cli