您的位置:首页 > 其它

用源码包来实现LAMP 的详细过程

2014-03-06 18:55 423 查看
[align=center]用源码包来实现LAMP的环境[/align] 在安装之前要先确定安装顺序
安装时的顺序:Httpd-----mysql------php安装:安装httpd(源码)1、配置yum 源,看当前的系统是否存在编译环境Yum grouplistDevelopment LibrariesDevelopment ToolsLegacy Software DevelopmentX Software Development如果系统不存在以上包组,可以用yum groupinstall 安装2、上传httpd源码包3、解压到指定目录Tar zxvf httpd-2.4.7.tar.gz –C /usr/src4、在安装httpd时需要用到两个apr可移植运行库和工具apr-1.5.0.tar.gz和apr-util-1.5.3.tar.gz需要一起上传到服务器并解压到相应目录并安装Tar zxvf apr-1.5.0.tar.gz –C /usr/src Tar zxvf apr-util-1.5.3.tar.gz –C /usr/srccd /usr/src/apr-1.5.0./configure –prefix=/usr/local/apr 配置并指明安装路径Make 编译Make install 安装安装完成之后他的库文件可能有其他程序的依赖(解决该方法)在/etc/ld.so.conf.d/下创建一个文件,并指明apr的安装路径Vim /etc/ld.so.conf.d/apr.conf (一定要以.conf结尾)/usr/local/apr/lib刷新缓存(刷新之前可以先看下/etc/ld.so.cache文件的大小)[root@wnt10 apr-util-1.5.3]# ll /etc/ld.so.cache -rw-r--r-- 1 root root 49683 Feb 27 20:55 /etc/ld.so.cacheLdconfig 刷新缓存在看cache文件[root@wnt10 apr-util-1.5.3]# ldconfig [root@wnt10 apr-util-1.5.3]# ll /etc/ld.so.cache -rw-r--r-- 1 root root 49845 Mar 5 00:51 /etc/ld.so.cache可以用ldconfig –pv 来查看apr模块是否被加载[root@wnt10 apr-util-1.5.3]# ldconfig -pv |grep aprlibgstdataprotocol-0.10.so.0 (libc6) => /usr/lib/libgstdataprotocol-0.10.so.0libaprutil-1.so.0 (libc6) => /usr/lib/libaprutil-1.so.0libapr-1.so.0 (libc6) => /usr/local/apr/lib/libapr-1.so.0libapr-1.so.0 (libc6) => /usr/lib/libapr-1.so.0 libapr-1.so (libc6)=> /usr/local/apr/lib/libapr-1.so可以看到apr模块被成功加载除了库文件有可能被其他程序所调用外,头文件一样也可能被其他程序所调用系统所找到的头文件一般都会放在/usr/inclide/ 或者/usr/local/include/这时为了方便系统所找到头文件可以做一个软链接Ln –s /usr/local/apr/include/usr/include/aprcd /usr/src/apr-until 如果不确定怎么安装可以先查看readme 或者install文件./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr/bin/apr-1-config表明要和apr的执行程序所关联起来Make && make installVim /etc/ld.so.conf.d/apr-util.conf (操作原意同上)/usr/local/apr-util/libLdconfigLdconfig –pv |grep apr-util[root@wnt10apr-util-1.5.3]# ldconfig -pv |grep apr-util libaprutil-1.so.0 (libc6)=> /usr/local/apr-util/lib/libaprutil-1.so.0 libaprutil-1.so(libc6) => /usr/local/apr-util/lib/libaprutil-1.soln –s /usr/local/apr-util/include /usr/include/apr-util如果想在系统下任何路径下都能去执行/usr/loca/apr-util/bin/apu-1-conf就需要把它添加到环境变量里面,系统的环境变量一般会涉及到4个文件/etc/profile /etc/bashrc (系统) ~.bashrc ~.bash_profile(个人)如果想让任何人都能去执行apu-1-conf和apr-1-conf就需要放到系统里面/etc/profileVim /etc/profile添加PATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin如果想使其生效,可在下次登录时自动生效或 . /etc/profile5、好了,这里的准备环境已经完成,下面正式安装httpd源码包进入/uar/src/httpd[root@wnt10httpd-2.4.7]# ./configure \(表示换行)>--prefix=/usr/local/apache \ 指明路径>--with-apr=/usr/local/apr/bin/apr-1-config \ 指明和apr关联的可执行文件>--with-apr-util=/usr/local/apr-util/bin/apu-1-config \ 和apr-util关联的执行文件>--sysconfdir=/etc/httpd \ 指明安装路径>--enable-mods-shared=all \ 指明所用的模块>--enable-ssl \ 开启ssl功能>--enable-mpms-shared=all \ 指明mpm机制>--enable-rewrite \ 开启地址重写功能>--with-z \ 开启网页传输自动压缩> --enable-so 开启模块功能这时系统报了一个pcre的错误:configure: error: pcre-config for libpcre not found. PCREis required and available from http://pcre.org/[root@wnt10httpd-2.4.7]# yum list |grep pcreThissystem is not registered with RHN.RHNsupport will be disabled.pcre.i386 6.6-2.el5_1.7 installed pcre-devel.i386 6.6-2.el5_1.7 rhel-server 发现pcre-devel工具没有安装,可以yuminstall pcre-devel直接安装安装完成之后再配置httpd后面还有加上—with-pcre Make && make install安装完成之后想要所有人都能使用/bin/下的可执行文件还需要配置环境变量,Vim /etc/profilePATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/binLn –s /usr/local/apache/include/ /usr/include/apache这里没有库文件,但是有man(帮助手册)还需要把man添加到系统路径Vim /etc/man.config添加MANPATH/usr/local/apache/man还有就是控制脚本,一般系统的控制脚本是放在/etc/init.d/下创建一个httpd的脚本 Vim /etc/init.d/httpd Chmod a+x /etc/init.d/httpd #!/bin/bash# chkconfig: 2345 56 26# description: httpd server daemonconf=/etc/httpd/httpd.conflock=/var/lock/subsys/httpdprog=/usr/local/apache/bin/httpd. /etc/init.d/functionsstart () {if[ -f $lock ] ; then echo "the httpd isstarted" elseecho -n "the httpd is starting......."sleep 1$prog -f $conf && echo "[ok]" && touch$lock || echo "[fail]"fi}stop () {if[ -f $lock ] ; thenecho -n "the httpd is stoping ......"sleep 1killproc httpd && echo "[ok]" && rm -rf$lock ||echo "[fail]"elseecho "the httpd is stoped......"fi}status () {if[ -f $lock ] ; then echo "the httpd isstarted......"elseecho "the httpd is stop"fi}case "$1" instart)start;;stop)stop;;restart)stopstart;;status)status;;*)echo "the httpd useage {start|stop|status|restart}"esacchkconfig –add httpdchkconfig –list |grep httpd[root@wnt10 init.d]# chkconfig --list |grep httpdhttpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off这样httpd就安装完毕,下载源码包地址http://httpd.apache.org安装mysql(源码)下载地址:www.mysql.com1、下载源码包上传到服务器(mysql5.6.10)2、解压到指定目录(同httpd的解压方法一样)Mysql在5.6以后没有./configure配置文件,这里需要cmake工具(说明文档)先下载cmake工具上传到服务器进行解压缩tar zxvfcmake-2.8.12.2.tar.gz -C /usr/src/ cd/usr/src/cmake./configure –prefix=/usr/local/cmakeMake && make install修改环境变量 /etc/profilePATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/cmake/bin添加man手册/etc/man.configMANPATH /usr/local/cmake/man安装完cmake之后需要创建一个系统账号mysql和mysql组Groupadd mysqlUseradd –r –gmysql mysql准备工作完成之后,安装mysql进入到解压目录/usr/src/mysqlCmake . (如果不加其他参数表明安装默认选项)Make &&make install经过漫长的等待时间,总算安装完成mysql然后需要把bin下的工具加到系统环境变量/etc/profilePATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/cmake/bin:/usr/local/mysql/bin添加完之后还要添加头文件、库文件以及man手册更改man手册/etc/man.configMANPATH /usr/local/mysql/manLn –s /usr/local/mysql/include /usr/include/mysqlVim /etc/ld.so.conf.d/mysql.conf/usr/local/mysql/libLdconfigLdconfig –pv |grep mysql这里把基本的安装配置添加等等全做完之后还要做一些设置Cd /usr/local/mysqlChown –R mysql. 更改mysql目录下所有文件及目录的所有者为mysqlChgrp –R mysql . 更改mysql目录下所有文件及目录的所属组为mysql或者Chown –R mysql.mysql. 也可以Scripts/mysql_install_db–user=mysql 去安装初始数据库以mysql的用户安装初始的过程中会看到INnoDB (这表示是5.6版本以后的数据库引擎5.5以前的数据库引擎为myISAM)仅供了解初始化完成之后需要把所有者改回root,其中有一个data特殊所有者为mysqlChown –R root .Chown –R mysqldatacpsupport-files/my-default.cnf /etc/my.cnf 拷贝mysql的配置文件到/etc下cpsupport-files/mysql.server /etc/init.d/mysqld 把mysql的控制脚本拷贝到/etc/init.d/下叫mysqld这时就可以使用Service mysqldstart|stop|restart|status等等的参数Chkconfigmysqld on 开机自动运行到这里mysql已经安装完毕安装php源码包1、下载源码包上传到服务器2、解压到指定目录(同httpd的解压方法一样)3、[root@wnt10php-5.5.9]# ./configure \> --prefix=/usr/local/php \ 安装路径> --sysconfdir=/etc/php.conf \ 主配置文件安装路径> --with-apxs2=/usr/local/apache/bin/apxs\ 必须要有> --with-gd \ 对图形的支持> --with-jpeg-dir \ 对不同格式图片的支持> --with-png-dir \> --with-zlib-dir \ 支持压缩> --enable-mbstring \ 支持多种字符级> --with-mysql=/usr/local/mysql \ 调用mysql 必须要有>--with-mysqli=/usr/local/mysql/bin/mysql_config \ php和mysql结合的接口文件在什么地方必须要有Make && make install安装完之后然后需要把bin下的工具加到系统环境变量/etc/profilePATH=$PATH:/usr/local/apr-util/bin:/usr/local/apr/bin:/usr/local/apache/bin:/usr/local/cmake/bin:/usr/local/mysql/bin:/usr/local/php/bin如果想让httpd支持php网页需要在httpd的配置文件加上一下一行,并且需要加上index.phpAddtype application/x-httpd-php .php .phtml以下是配置文件改完之后的内容AddTypeapplication/x-httpd-php .php .phtml<IfModuledir_module> DirectoryIndex index.php index.html</IfModule>重启服务默认apache:站点的主目录在/usr/local/apache/htdocs[root@wnt10php-5.5.9]# cd /usr/local/apache/htdocs/[root@wnt10htdocs]# lsindex.html[root@wnt10htdocs]# mv index.html index.phpVim index.php<html><body><h1>Itworks!</h1></body></html><?phpphpinfo();?>用网页测试显示php的信息页面这说明httpd与php结合成功Vim index.php<html><body><h1>Itworks!</h1></body></html><?php$link=Mysql_connect(‘127.0.0.1’,’root’,’123’);If ($link)Echo “ok”;Else echo”fail”;?>用网页测试显示ok的信息这说明mysql与php结合成功(这里需要重启mysqld服务)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息