共计 13391 个字符,预计需要花费 34 分钟才能阅读完成。
系统环境:CentOS 6.4
软件源码包版本:
httpd-2.4.10
php-5.4.32
MySQL-5.5.39
一、编译安装 apache2.4
1、下载所需的软件源码包,使用 wget 命令进行下载:
apr-1.5.1:wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.1.tar.bz2
apr-util-1.5.3:wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2
httpd-2.4.10:wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.bz2
2、解决依赖关系
(1) 使用 yum 安装系统所需的一些依赖库
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-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 openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel
(注意:在这次的安装实验中,只需要 yum 安装 openssl,openssl-devel,pcre,pcre-devel 即可正常编译完成 httpd,而且上面所列出的库与工具,有不少是系统已经安装过了的,这里只是进行一下更新,还有其他的一些库是为下面编译安装 mysql 与 php 作的准备)
(2) 先编译安装 apr
tar jxf apr-1.5.1.tar.bz2
cd apr-1.5.1
./configure –prefix=/usr/local/apr
make && make install
(3) 再编译安装 apr-util
tar jxf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr #(注意:–with-apr=/usr/local/apr 是上面安装 apr 的路径)
make && make install
(解释:apr,全称为 Apache portable Run-time libraries,叫 Apache 可移植运行库,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库,安装 apache 都需要先安装这个库的)
3、正式编译安装 httpd
tar jxf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-pcre –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-modules=most –enable-mods-shared=most –enable-mpms-shared=all –with-mpm=event
make && make install
————————————– 分割线 ————————————–
CentOS 6.5 安装配置 LAMP http://www.linuxidc.com/Linux/2014-07/104373.htm
Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm
CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm
RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm
LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm
基于 Ubuntu 的 LAMP 优化加固 http://www.linuxidc.com/Linux/2014-07/104092.htm
————————————– 分割线 ————————————–
4、配置 httpd
(1)为 httpd 提供 sysv 服务启动与关闭脚本,把以下内容复制成 /etc/init.d/httpd,并且给予此文件执行权限(chmod +x /etc/rc.d/init.d/httpd),就可以直接使用 service httpd <start|stop|restart|reload> 的命令形式控制 httpd 服务:
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: – 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [-f /etc/sysconfig/httpd]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-“C”}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=””
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based “worker” MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $”Starting $prog: “
LANG=$HTTPD_LANG daemon –pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[$RETVAL = 0] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $”Stopping $prog: “
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[$RETVAL = 0] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $”Reloading $prog: “
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $”not reloading due to configuration syntax error”
failure $”not reloading $httpd due to configuration syntax error”
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [-f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $”Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}”
exit 1
esac
exit $RETVAL
(2)把 httpd 服务添加为开机自启动:
chkconfig –add httpd
chkconfig httpd on
(3)修改 httpd 主配置文件 /etc/httpd/httpd.conf,指定 httpd 服务的 PID 文件,直接在配置文件添加如下字段:
PidFile “/var/run/httpd.pid”
(4)启动 httpd 服务,并进行访问测试
service httpd start
(注:如果启动的时候出现这个警告:httpd: apr_sockaddr_info_get() failed for longren
httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName,解决方法:在 /etc/httpd/httpd.conf 添加 ServerName 127.0.0.1)
访问测试:http://your_ipadress,如果出现 It Works,就证明 httpd 编译安装成功
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-09/106580p2.htm
二、编译安装 MySQL(注:一般来说是先安装 mysql 再安装 php,因为在 php 编译时需要指定 mysql 路径)
1、下载所需软件源码包
mysql-5.5.39:http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.39.tar.gz
2、解决库依赖关系
(1)yum 安装依赖库
yum -y install cmake #mysql5.5 是使用 cmake 进行编译的
yum -y install bison automake zlib* libxml* ncurses-devel libtool-ltdl-devel* mysql-devel
3、添加 mysql 用户,下面的编译需要用到
groupadd -r mysql
useradd -g mysql -r -s /sbin/nologin mysql
4、正式编译安装 mysql
tar zxf mysql-5.5.39.tar.gz
cd mysql-5.5.39
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/user/local/mysql/data \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0 \
-DMYSQL_USER=mysql \
-DENABLED_LOCAL_INFILE=1
make && make install
5、初始化数据库
chown -R mysql:mysql /usr/local/mysql/*
cd /usr/local/mysql
./scripts/mysql_install_db –user=mysql –datadir=/usr/local/mysql/data
6、配置数据库
(1)从源码包中拷贝数据库配置文件
cd mysql-5.5.39
cp support-files/my-medium.cnf /etc/my.cnf
(注:support-files 目录里有 my-small.cnf、my-medium.cnf、my-large.cnf、my-huge.cnf,使用哪个是根据机器的内存大小进行选择)
(2)mysql 提供 sysv 服务启动与关闭脚本:
cd /usr/local/mysql
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
(3)添加至服务列表:
chkconfig –add mysqld
chkconfig mysqld on
7、额外的配置:为了使 mysql 的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
(1)输出 mysql 的 man 手册至 man 命令的查找路径:
编辑 /etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
(2)输出 mysql 的头文件至系统头文件路径 /usr/include:
通过简单的创建链接实现:
ln -sv /usr/local/mysql/include /usr/include/mysql
(3)输出 mysql 的库文件给系统库查找路径:
echo ‘/usr/local/mysql/lib’ > /etc/ld.so.conf.d/mysql.conf
让系统重新载入系统库:
ldconfig
(4)修改 PATH 环境变量,让系统可以直接使用 mysql 的相关命令,添加如下命令后,需要重新连接会话才能生效
echo “export PATH=$PATH:/usr/local/mysql/bin” > /etc/profile.d/mysql.sh
8、启动 mysql 服务
service mysqld start
三、源码编译安装 php
1、下载所需软件源码包
php-5.4.32:http://cn2.php.net/get/php-5.4.32.tar.bz2/from/this/mirror
libmcrypt-2.5.7:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
xcache-3.1.0:http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.bz2
mhash-0.9.9:http://pan.baidu.com/s/1hqDtQ2C
2、解决依赖关系
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
tar jxf mhash-0.9.9.tar.gz
cd mhash-0.9.9
./configure
make && make install
3、正式编译安装 php
tar jxf php-5.4.32.tar.bz2
cd php-5.4.32
./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql –with-openssl –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –with-apxs2=/usr/local/apache/bin/apxs –with-mcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2 –enable-maintainer-zts
make && make install
4、配置 php
(1)从源码包拷贝 php 配置文件:
cd php-5.4.32
cp php.ini-production /etc/php.ini
(2)整合 httpd 与 php:编辑 apache 配置文件 httpd.conf,使 apache 支持 php
vim /etc/httpd/httpd.conf
a、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
b、定位至 DirectoryIndex index.html 修改为:
DirectoryIndex index.php index.html
重新启动 httpd 服务,或让其重新载入配置文件
测试:在 /usr/local/apache/htdocs 中添加 index.php,里面写入 php 代码
(3)安装 xcache,为 php 加速
tar jxf xcache-3.1.0.tar.bz2
cd xcache-3.1.0
/usr/local/php/bin/phpize
./configure –enable-xcache –with-php-config=/usr/local/php/bin/php-config
make && make install
编辑 php.ini,整合 php 和 xcache:
首先将 xcache 提供的样例配置导入 php.ini
cd xcache-3.1.0
mkdir /etc/php.d
cp xcache.ini /etc/php.d
然后编辑 /etc/php.d/xcache.ini,找到 zend_extension 开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
重启 httpd 服务并测试 xcache 是否与 php 整合成功
service httpd restart
在 index.php 添加 phpinfo() 函数,让后访问 index.php,查看 xcache 选项的显示
更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
系统环境:CentOS 6.4
软件源码包版本:
httpd-2.4.10
php-5.4.32
MySQL-5.5.39
一、编译安装 apache2.4
1、下载所需的软件源码包,使用 wget 命令进行下载:
apr-1.5.1:wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.1.tar.bz2
apr-util-1.5.3:wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2
httpd-2.4.10:wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.bz2
2、解决依赖关系
(1) 使用 yum 安装系统所需的一些依赖库
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-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 openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel
(注意:在这次的安装实验中,只需要 yum 安装 openssl,openssl-devel,pcre,pcre-devel 即可正常编译完成 httpd,而且上面所列出的库与工具,有不少是系统已经安装过了的,这里只是进行一下更新,还有其他的一些库是为下面编译安装 mysql 与 php 作的准备)
(2) 先编译安装 apr
tar jxf apr-1.5.1.tar.bz2
cd apr-1.5.1
./configure –prefix=/usr/local/apr
make && make install
(3) 再编译安装 apr-util
tar jxf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr #(注意:–with-apr=/usr/local/apr 是上面安装 apr 的路径)
make && make install
(解释:apr,全称为 Apache portable Run-time libraries,叫 Apache 可移植运行库,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库,安装 apache 都需要先安装这个库的)
3、正式编译安装 httpd
tar jxf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-pcre –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-modules=most –enable-mods-shared=most –enable-mpms-shared=all –with-mpm=event
make && make install
————————————– 分割线 ————————————–
CentOS 6.5 安装配置 LAMP http://www.linuxidc.com/Linux/2014-07/104373.htm
Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm
CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm
RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm
LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm
基于 Ubuntu 的 LAMP 优化加固 http://www.linuxidc.com/Linux/2014-07/104092.htm
————————————– 分割线 ————————————–
4、配置 httpd
(1)为 httpd 提供 sysv 服务启动与关闭脚本,把以下内容复制成 /etc/init.d/httpd,并且给予此文件执行权限(chmod +x /etc/rc.d/init.d/httpd),就可以直接使用 service httpd <start|stop|restart|reload> 的命令形式控制 httpd 服务:
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: – 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [-f /etc/sysconfig/httpd]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-“C”}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=””
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based “worker” MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $”Starting $prog: “
LANG=$HTTPD_LANG daemon –pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[$RETVAL = 0] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $”Stopping $prog: “
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[$RETVAL = 0] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $”Reloading $prog: “
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $”not reloading due to configuration syntax error”
failure $”not reloading $httpd due to configuration syntax error”
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [-f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $”Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}”
exit 1
esac
exit $RETVAL
(2)把 httpd 服务添加为开机自启动:
chkconfig –add httpd
chkconfig httpd on
(3)修改 httpd 主配置文件 /etc/httpd/httpd.conf,指定 httpd 服务的 PID 文件,直接在配置文件添加如下字段:
PidFile “/var/run/httpd.pid”
(4)启动 httpd 服务,并进行访问测试
service httpd start
(注:如果启动的时候出现这个警告:httpd: apr_sockaddr_info_get() failed for longren
httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName,解决方法:在 /etc/httpd/httpd.conf 添加 ServerName 127.0.0.1)
访问测试:http://your_ipadress,如果出现 It Works,就证明 httpd 编译安装成功
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-09/106580p2.htm