第1章 环境说明
1.1 系统说明
CentOS 6.4
1.2 软件说明
httpd-2.4.10.tar.gz
apr-util-1.5.3.tar.gz
apr-1.5.1.tar.gz
pcre-8.34.tar.gz
php-5.6.0.tar.bz2
libmcrypt-2.5.3.tar.gz
mysql-5.1.51.tar.gz
第2章 Apache搭建说明
2.1 安装依赖包
yum install make openldap-devel ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf bzip2-devel ncurses-devel openssl-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl-devel curl pam-devel openldap-devel e2fsprogs-devel krb5-devel libidn libidn-devel -y
2.2 安装apr
tar -zxvf apr-1.5.1.tar.gz
cd apr-1.5.1
./configure --prefix=/usr/local/apr
make && make install
2.3 安装apr-util
tar -zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
./configure \
--prefix=/usr/local/apr-util \
--with-apr=/usr/local/apr
make && make install
2.4 安装pcre
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure --prefix=/usr/local/pcre
make && make install
2.5 安装apache
静态编译tar -zxvf httpd-2.4.10.tar.gz
cd httpd-2.4.10
./configure --prefix=/usr/local/apache \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr
make && make install
动态编译
tar -zxvf httpd-2.4.10.tar.gz
cd httpd-2.4.10
./configure --prefix=/usr/local/apache \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--enable-mods-shared=all \
--enable-so \
--enable-rewrite
make && make install
在make的时候,报错:
exports.c:2429: error: redefinition of 'ap_hack_apr_xlate_open'
exports.c:2013: note: previous definition of 'ap_hack_apr_xlate_open' was here
打开 server/exports.c ,发现里面确实有大量重复。apr 与 apr-util 都包含了重复同样头文件。删除重复再make就可以了。
make install 正常
2.6 配置文件说明
/usr/local/apache/conf/httpd.conf
DocumentRoot "/usr/local/apache/htdocs"
修改此条可配置项目运行目录。
启动文件
/usr/local/apache/bin/apachectl start
报错:httpd: Could not open configuration file /usr/local/apache2/conf/httpd.conf: No such file or directory
这个错误,是由于上次./configure时--prefix=/usr/local/apache2,而本次没有make clean时没有清除上次的记录。解决方法:要么删除整个目录,要么
./configure --prefix=/usr/local/apache2
make clean
再按上面的步骤 ./configure,make
这次正常通过~
2.7 安装MySql
1.使用yum安装 yum -y install mysql-server mysql mysql-devel2.编译安装
tar zxf mysql-5.1.51.tar.gz
cd mysql-5.1.51
./configure --prefix=/usr/local/mysql
make && make install
安装完之后,执行 mysql 报错:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
这是因为本地的mysql服务器没有启动起来。
service mysqld start
再次输入 mysql 命令就没有问题了。
第3章 PHP搭建说明
3.1 安装libmcrypt
tar xvf libmcrypt-2.5.3.tar.gz
cd libmcrypt-2.5.3
./configure
make && make install
3.2 安装php
安装依赖包
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel openssl openssl-devel curl curl-devel openssl openssl-devel libxslt libxslt-develtar -zxvf php-5.6.0.tar.gz
cd php-5.6.0
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc --with-curl --with-freetype-dir --with-gd --with-jpeg-dir --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
修改时区 date.timezone = "PRC"
第4章 修改配置并测试
4.1 修改apache配置文件支持php
打开 /usr/local/apache/conf/httpd.conf
将文件中:DirectoryIndex index.html
替换为:DirectoryIndex index.html index.php
并添加:AddType application/x-httpd-php .php
4.2 测试php支持
在 /usr/local/apache/htdocs/ 目录中创建测试php页面 test.php
<?php
phpinfo();
?>
重启apache服务后,在浏览器上输入网址:http://127.0.0.1/test.php
看到站点,则说明php搭建完成。