네트워커의 보안 티스토리


CentOS 6.4 64bit


설치순서는 Mysql -> Apache -> PHP 순서


yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel  ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel libtool  libtool-libs openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool-ltdl libtool-ltdl-devel bison




yum groupinstall "Development Tools"

yum -y install cmake wget ncurses-devel libtool-ltdl expat-devel db4-devel pcre-devel openssl-devel



########################## MYSQL 설치 #########################################

useradd -M -c "MySQL" -d /usr/local/mysql -g mysql -s /bin/nologin mysql


tar xvfz mysql-5.6.14.tar.gz


cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql_5.5.27 \

-DMYSQL_DATADIR=/usr/local/mysql_5.5.27/data \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DSYSCONFDIR=/etc \

-DMYSQL_TCP_PORT=3306 \

-DMYSQL_USER=mysql \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1


make && make install


ln -s /usr/local/mysql_5.5.27 /usr/local/mysql


ln -s /usr/local/mysql_5.5.27/bin/mysql /usr/bin/mysql

ln -s /usr/local/mysql_5.5.27/bin/mysqldump /usr/sbin/mysqldump

ln -s /usr/local/mysql_5.5.27/bin/mysql_config /usr/sbin/mysql_config

ln -s /usr/local/mysql_5.5.27/bin/mysqladmin /usr/sbin/mysqladmin


ln -s /usr/local/mysql_5.5.27/support-files/mysql.server /etc/rc.d/init.d/mysql


chkconfig --add mysql

service mysql start


ln -s /usr/local/mysql/lib /usr/local/mysql/lib64


/usr/local/mysql_5.5.27/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql_5.5.27/data


chown -R mysql:mysql /usr/local/mysql/


echo "/usr/local/mysql/lib" >> /etc/ld.so.conf

ldconfig



#################### 아파치 설치 #############################################


64bit일 경우

ln -s /lib64/libexpat.so.1.5.2 /usr/lib/libexpat.so




# APR 다운로드 및 압축 해제

wget http://mirror.apache-kr.org/apr/apr-1.5.2.tar.gz

wget http://mirror.apache-kr.org/apr/apr-util-1.5.4.tar.gz

wget http://apache.tt.co.kr//httpd/httpd-2.4.26.tar.gz


tar xvfz apr-1.5.2.tar.gz 

tar xvfz apr-util-1.5.4.tar.gz

tar xvfz httpd-2.4.26.tar.gz



# APR 설치

cd apr-1.5.2

./configure --prefix=/usr/local/apr


make && make install


# APR-util 설치

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr \

--with-apr=/usr/local/apr/bin/apr-1-config \

--with-crypto=/usr --with-openssl \

--with-dbm=db47 --with-gdbm --with-berkeley-db \

--with-mysql=/usr/local/mysql \

--with-sqlite3 \

--with-expat=/usr


make && make install


#아파치 설치

cd httpd -2.4.26


./configure --prefix=/usr/local/apache_2.4.26  \

--with-pcre --with-libxml2 --with-ssl=/usr/local/openssl --with-z \

--with-mpm=worker \

--enable-modules=most --enable-mods-shared=most \

--enable-file-cache --enable-cache --enable-file-cache \

--enable-so \

--enable-mime-magic --enable-expires --enable-header \

--enable-proxy --enable-ssl \

--enable-mpms-shared=all \

--enable-vhosts-alias --enable-rewrite


make && make install



ln -s /usr/local/apache_2.4.26/bin/apachectl /etc/rc.d/init.d/httpd

vi /usr/local/apache_2.4.26/bin/apachectl 

#!/bin/sh

## Apache This starts and stops Apache.

## chkconfig: 35 20 80

# description: Apache Web Service

#

# Licensed to the Apache Software Foundation... 

---------------------------------------------------------------- 

service httpd start


echo "/usr/local/apache/module" >> /etc/ld.so.conf

ldconfig




##################################### PHP 설치 ###########################################################################


yum install -y libxml2-devel bzip2-devel libcurl-devel gdbm-devel libvpx yum install libvpx-devel \

libjpeg-turbo-devel libpng-devel libXpm libXpm-devel freetype-devel t1lib t1lib-devel gmp-devel libc-client libc-client-devel \

pam-devel libicu libicu-devel openldap-devel readline-devel libedit-devel libtidy libtidy-devel libxslt libxslt-devel 



-libmcrypt 설치


wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz


tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make && make install


ln -s /usr/local/lib/libmcrypt.so.4 /usr/local/lib64/libmcrypt.so.4


#### PHP 컴파일 전 아래파일 수정(PHP 5.2 버젼만 ###

vi sapi/apache2handler/php_functions.c 

386         AP_DECLARE_DATA extern unixd_config_rec unixd_config;

417         snprintf(tmp, sizeof(tmp), "%s(%d)/%d", unixd_config.user_name, unixd_config.user_id, unixd_config.group_id);


386         AP_DECLARE_DATA extern unixd_config_rec ap_unixd_config;

417         snprintf(tmp, sizeof(tmp), "%s(%d)/%d", ap_unixd_config.user_name, ap_unixd_config.user_id, ap_unixd_config.group_id);



cd php디렉토리

 

./configure \

--prefix=/usr/local/php \

--with-apxs2=/usr/local/apache_2.4.26/bin/apxs \

--with-config-file-path=/usr/local/apache_2.4.26/conf/ \

--with-mysql=/usr/local/mysql \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-regex=php \

--with-libxml-dir=/usr \

--with-openssl \

--with-pcre-regex \

--with-zlib --with-bz2 --with-curl \

--with-gdbm --with-db4=/usr --with-dbm \

--with-pcre-dir=/usr --with-openssl-dir=/usr \

--with-libxml-dir=/usr \

--with-gd \

--with-vpx-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr \

--with-php-config=/usr/local/php/bin/php-config \

--with-zlib-dir=/usr --with-xpm-dir=/usr \

--with-freetype-dir=/usr --with-t1lib=/usr \

--with-gettext --with-gmp  \

--with-imap --with-imap-ssl \

--with-curl \

--with-kerberos \

--with-icu-dir=/usr \

--with-ldap --with-ldap-sasl \

--with-libmbfl --with-onig \

--with-mcrypt \

--with-libedit --with-readline \

--with-tidy \

--with-libexpat-dir=/usr --with-xmlrpc --with-xsl \

--with-pear --with-pic \

--with-libdir=lib64 \

--enable-bcmath --enable-calendar \

--enable-exif --enable-ftp --enable-pcntl \

--enable-gd-native-ttf --enable-gd-jis-conv \

--enable-intl --enable-mbstring \

--enable-shmop --enable-sockets \

--enable-sysvmsg --enable-sysvsem --enable-sysvshm \

--enable-wddx --enable-zip \

--enable-mysqlnd \

--enable-dba=shared --enable-mod-charset \

--enable-dom --enable-mbregex --enable-inline-optimization \

--enable-sigchild --enable-soap \

--enable-maintainer-zts \

--enable-opcache=no


make && make test && make install



아파치와 연동.


[root@host php-5.5.4] cp php.ini-production /etc/httpd/php.ini

[root@host php-5.5.4] vi /etc/httpd/php.ini


; PHP's default character set is set to empty.

; http://php.net/default-charset

default_charset = "UTF-8":


; Whether to allow HTTP file uploads.

; http://php.net/file-uploads

file_uploads = Ona


; Temporary directory for HTTP uploaded files (will use system default if not

; specified).

; http://php.net/upload-tmp-dir

upload_tmp_dir = /tmp


; Maximum allowed size for uploaded files.

; http://php.net/upload-max-filesize

upload_max_filesize = 50M


; Maximum number of files that can be uploaded via a single request

max_file_uploads = 20


; Defines the default timezone used by the date functions

; http://php.net/date.timezone

date.timezone = "Asia/Seoul"


vi /etc/httpd/httpd.conf 


# PHP 모듈이 정상적으로 추가되었는지 확인

LoadModule php5_module        modules/libphp5.so 

<IfModule mime_module>     

... 중략 ...     

AddType application/x-httpd-php .php .html     

AddType application/x-httpd-php-source .phps 

</IfModule> 


[root@host php-5.5.4] service httpd restart



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

ln -s /usr/local/php/bin/php-config /usr/local/bin/php-config

ln -s /usr/local/php/bin/phpize /usr/local/bin/phpize


root@host php-5.5.4] echo "<?php phpinfo() ?>" > /usr/local/apache/htdocs/index.html



#참고사이트

http://blog.keypointer.co.kr/?p=53