您的位置:首页 > 运维架构 > Apache

一版完整lamp环境搭建文档

2011-11-26 22:26 363 查看
源码包搭建一个完整的LAMP环境,这个文档我可是零零散散的花了将近5天的时间,做一步写一下文档哦!因为机器的环境不一样,安装过程中可能会出现这样或那样的问题,请根据提示消息处理相关问题即可。一共用了17个源码包.废话不多说,下面开始。

1、安装mysql

#tar xvf mysql-5.1.53.tar.gz -C /usr/src

#cd /usr/src/mysql-5.1.53

#./configure --localstatedir=/data/mysql/ --prefix=/usr/local/mysql --enable-assembler --enable-profiling --enable-local-infile --with-charset=utf8 --with-extra-charsets=gbk,gb2312 --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-low-memory --with-big-tables --sysconfdir=/usr/local/mysql/etc --datadir=/data/mysql/

#make

#make install

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

#ldconfig

2.安装apache

Apache可移植运行时库(Apache Portable Runtime,APR)和APR的实用库(APR Utilities、APR-UTILS或者APU)是Apache软件基金会旗下两个自主开发和维护的库,为Apache的httpd程序所使用。尽管很多的内核开发者要同时涉及开发httpd(即Web服务器)和APR,然而这两个项目却是相互独立的。APR和APU提供了内核函数,这些函数不仅仅只与Web服务相关,对于更加普遍的应用开发也很有用。

APR实际上包含了三个开发包:apr、apr-util以及apr-iconv,每一个开发包分别独立开发,并拥有自己的版本。

apr开发包位于目录${APR}\apr下,其中包含了一些通用的开发组件,包括mmap,文件等等,前面已经描述过。

apr-util开发包位于目录${APR}\apr-util下,该目录中也是包含了一些常用的开发组件。这些组件与apr目录下的相比,它们与apache的关系更加密切一些。比如存储段和存储段组,加密等

apr-iconv包中的文件主要用于实现iconv编码。目前的大部分编码转换过程都是与本地编码相关的。在进行转换之前必须能够正确地设置本地编码。因此如果两个非本地编码A和B需要转换,则转换过程大致为A->Local以及Local->B或者B->Local以及Local->A。

XPG2 标准中另外定义了一组全新的函式接口ICONV,该接口是一种更广义的字集转换系统。也是一个与本地编码无关的字集转换系统。APR中也支持这种字集转换系统,为此它提供了完整的实现。Apr-iconv正是为此目的而产生。

--安装apr-1.3.8.tar.gz

# tar xf apr-1.3.8.tar.gz -C /usr/src/

# cd /usr/src/apr-1.3.8/

#./configure --prefix=/usr/local/apr --enable-threads && make && make install

--安装apr-iconv-1.2.1.tar.gz

# tar xvf apr-iconv-1.2.1.tar.gz -C /usr/src/

# cd /usr/src/apr-iconv-1.2.1/

# ./configure --prefix=/usr/local/apache2 --with=/usr/local/apr/bin/apr-1-config && make && make install //默认安装路径/usr/local/apache2

--安装apr-util-1.3.9.tar.gz

# tar xf apr-util-1.3.9.tar.gz -C /usr/src/

# cd /usr/src/apr-util-1.3.9/

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config --with-mysql=/usr/local/mysql/ --with-iconv=/usr/local/apache2 && make && make install

--安装httpd-2.2.9.tar.gz

# tar xvf httpd-2.2.9.tar.gz -C /usr/src

# cd /usr/src/httpd-2.2.9/

# ./configure --enable-so --enable-rewrite --enable-vhost-alias --enable-cgi --enable-info --enable-http --enable-static-ab --enable-static-htpasswd --enable-static-support --enable-proxy --enable-proxy-balancer --enable-deflate --enable-cache --enable-disk-cache --enable-mem-cache --enable-modules=all --enable-mods-shared=all --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util --with-mpm=worker

# make && make install

3.安装PHP

--安装freetype

FreeType库是一个完全免费(开源)的、高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件,包括TrueType, OpenType, Type1, CID, CFF, Windows FON/FNT, X11 PCF等。支持单色位图、反走样位图的渲染。FreeType库是高度模块化的程序库,虽然它是使用ANSI C开发,但是采用面向对象的思想,因此,FreeType的用户可以灵活地对它进行裁剪。

# tar jxvf freetype-2.4.0.tar.bz2 -C /usr/src

# cd /usr/src/freetype-2.4.0

# ./configure --prefix=/usr/local/freetype

# make && make install

--安装jpegsrc

# tar -zvxf jpegsrc.v7.tar.gz -C /usr/src/

# cd /usr/src/jpegsrc.v7

# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static

# make && make install

--安装libpng-1.2.41.tar.bz2

# tar -jxvf libpng-1.2.41.tar.bz2 -C /usr/src/

# cd /usr/src/libpng-1.2.41

# ./configure --prefix=/usr/local/libpng && make && make install

# ln -s /usr/local/libpng/include/pngconf.h /usr/include/

# ln -s /usr/local/libpng/include/png.h /usr/include/

--安装gettext-0.18.tar.gz

Gettext 用于系统的国际化(I18N)和本地化(L10N),可以在编译程序的时候使用本国语言支持(Native Language Support(NLS)),其可以使程序的输出使用用户设置的语言而不是英文.

[gettext-0.18]# ./configure && make && make install

#echo /usr/local/lib >> /etc/ld.so.conf

#ldconfig

--安装fontconfig-2.8.0.tar.gz

# tar xvf fontconfig-2.8.0.tar.gz -C /usr/src

# cd /usr/src/fontconfig-2.8.0

# ./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config && make && make install

--安装 gd-2.0.35.tar.gz

# tar zxvf gd-2.0.35.tar.gz -C /usr/src/

# cd /usr/src/gd-2.0.35

# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/fontconfig

# make && make install

--安装mcrypt-2.6.6.tar.gz

# tar xvf mcrypt-2.6.6.tar.gz -C /usr/src/

# cd /usr/src/mcrypt-2.6.6/

# ./configure && make && make install

--安装php-5.3.3.tar.bz2

# tar xvf php-5.3.3.tar.bz2 -C /usr/src/

# cd /usr/src/php-5.3.3

# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mod-charset --enable-sigchild --enable-magic-quotes --enable-libgcc --with-zlib --enable-bcmath --enable-calendar --enable-dba --enable-exif --enable-ftp --enable-gd-native-ttf --enable-gd-jis-conv --enable-intl --enable-mbstring --enable-pcntl --enable-shmop --enable-soap --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --with-zlib-dir --with-gettext=/usr/local --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-mcrypt //如编译中途提示找不到icu配置文件,执行 yum install libicu libicu-devel -y

# make && make install

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

禁止php脚本执行系统指令

# vim /usr/local/lib/php.ini

disable_functions = passthru,shell_exec,system,proc_nice,proc_open,proc_terminate,exec,popen

4、apache相关设置

apache添加php支持

AddType application/x-http-php .php

网站安全设定,对敏感网页加密,

# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

NameVirtualHost *:80

<VirtualHost *:80>

ServerAdmin hishijun@yeah.net.com

DocumentRoot "/data/webroot01"

ServerName 10.0.10.9

ErrorLog "logs/10.0.10.9-error_log"

CustomLog "logs/10.0.10.9-access_log" common

<Directory "/data/webroot01">

AllowOverride None

Options FollowSymLinks

Order allow,deny

Allow from all

</Directory>

<Directory "/data/webroot01/phpmyadmin"> //网页加密

Options FollowSymLinks

AllowOverride None --none不用改成all

Order allow,deny

Allow from all

authname "please input your username and password! @_@"

authtype basic

authuserfile /usr/local/apache2/conf/userpasswd

require valid-user --把这四句直接加到这个目录标签里

</Directory>

</VirtualHost>

# htpasswd -c /usr/local/apache2/conf/userpasswd xuwenadmin //生成可以访问/data/webroot01/phpmyadmin的用户及密码

# /usr/local/apache2/bin/apachectl -k start --重启后,验证,也可以

若启动过程中报如下错误,说明打开了selinux

httpd: Syntax error on line 114 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

查看selinux运行状态:

# getenforce

Enforcing

# sestatus

SELinux status: enabled

SELinuxfs mount: /selinux

Current mode: enforcing

Mode from config file: enforcing

Policy version: 21

Policy from config file: targeted

查看系统默认对libphp5.so(RPM包的libphp5.so,然后在源码包上打上一样的标记就搞定)打上什么样的标记

#semanage fcontext -l | grep php

/usr/lib(64)?/php/modules/.+\.so regular file system_u:object_r:textrel_shlib_t:s0

/usr/lib(64)?/httpd/modules/libphp5\.so regular file system_u:object_r:textrel_shlib_t:s0

修改libphp5.so是安全上下文:

# chcon -R -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so //restorecon -RFv /webroot/ 将此目录下的文件及文件夹恢复到默认标记

# semanage fcontext -a -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so

# /usr/local/apache2/bin/apachectl -k restart

日志切割

# tar xvf cronolog-1.6.2.tar.gz -C /usr/src/

# cd /usr/src/cronolog-1.6.2/

编译安装

# ./configure --prefix=/usr/local/cronolog ;make ;make install

vim /usr/local/apache2/conf/extra/http-vhost.conf

修改:

CustomLog logs/access_log combined

改成:

CustomLog "|/usr/local/cronolog/sbin/cronolog /usr/local/apache2/logs/%Y/%m/%d/access_log" combined

--注意格式不要写错

重启apache后,过几秒,或者访问一下apache

就会在/usr/local/apache2/logs下产生了切割日志

# ls /usr/local/apache2/logs/* -R

/usr/local/apache2/logs/10.0.10.9-error_log /usr/local/apache2/logs/error_log

/usr/local/apache2/logs/access_log /usr/local/apache2/logs/httpd.pid

/usr/local/apache2/logs/cgisock.2045

/usr/local/apache2/logs/2011:

11

/usr/local/apache2/logs/2011/11:

26

/usr/local/apache2/logs/2011/11/26:

access_log

到此结束,终于大功造成……泪满面……

文档整理人:石军 QQ:295568080 E-mail:hishijun@yeah.net

交流群:我们都是挨踢人 167125978
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php mysql apache web lamp