登录|注册|快速了解|帮助

小戴 的维客空间

http://wiki.hudong.com/daiqi/index  ( 复制链接 | 加入收藏夹 )

当前位置: LAMP的配置指南 >> 正文

LAMP的配置指南


      近日由于项目需求,需要重新配置
LAMPlinux+apache+mysql+php)环境,为此查阅了网上大量资料,由于网上此类资料很繁杂,特将重点内容提取出来,供需要配置LAMP环境的同学参考:

建立安装源码包的文件夹

例如:在 /root 目录下建了一个 soft 文件夹来保存我要安装的源码包
mkdir /root/soft
cd /root/soft

先找到 apache php mysql源码包下载的URL地址
请浏览
http://www.apache.org
http://www.php.net
http://www.mysql.com
等官方网站
使用wget 直接下载

wget http://apache.justdn.org/httpd/httpd-2.0.55.tar.gz

wget http://cn.php.net/get/php-5.0.5.tar.gz/from/cn2.php.net/mirror

wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-standard-5.0.15-linux-i686.tar.gz/from/http://mysql.oss.eznetsols.org/


 

注:当前目录为/root/soft ,
目录下有
httpd-2.0.55.tar.gz, php-5.0.5.tar.gz
等二进制源码包
号代表为root 根权限,后是输入的一条命令

执行下列命令
解压源码包
 tar -zxf httpd-2.0.55.tar.gz
进入安装目录
 cd httpd-2.0.55
配置apache安装信息
 ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
执行make安装
 make; make install
安装完后
 vi /usr/local/apache/conf/httpd.conf
找到 prefork.c 下的
MaxClients 150
改为
ServerLimit 2000
MaxClients 1000
apache默认工作在prefork.c模式下,并发进程为150,超过后就无法访问,150是远远不够的,所以这里按自己网站的需求改, 如1000
由于apache默认最大并发进程是 256 所以要先设置 ServerLimit 2000 将服务器可设的最大并发数设为2000, 然后再设置最大并发数 MaxClients 1000

找到 ServerName www.example.com:80 在其下设置 ServerName 如下
ServerName www.mysite.com
基中 www.mysite.com 为你网站名,也可用IP代替
找到 DocumentRoot "/usr/local/apache/htdocs"
设置你的 WEB 服务器的根目录 如
DocumentRoot "/myweb"
找到 DirectoryIndex index.html index.html.var 改为
DirectoryIndex index.html index.php index.htm
找到 ForceLanguagePriority Prefer Fallback 在其下加上
AddDefaultCharset gb2312
改完后保存(vi 的用法请查 Linux vi 命令)
用下面命令启动WEB服务器
 /usr/local/apache/bin/apachectl start
查看自己的站点是否正常 http://www.mysite.com 也可用IP
用  /usr/local/apache/bin/apachectl stop 可停止服务


 

 cd /root/soft
 wget
http://curl.haxx.se/download/curl-7.15.0.tar.gz
 tar -zxf curl-7.15.0.tar.gz
 ./configure --prefix=/usr/local/curl
 make; make install

 

 cd /root/soft
 wget
http://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.19.tar.gz
 tar -zxf libxml2-2.6.19.tar.gz
 cd libxml2-2.6.19
 ./configure --prefix=/usr/local/libxml2
 make; make install

 

 cd /root/soft
 wget
http://ftp.gnome.org/pub/GNOME/sources/libxslt/1.1/libxslt-1.1.15.tar.gz
 tar -zxf libxslt-1.1.15.tar.gz
 cd libxslt-1.1.15
 ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
 make; make install

 

www.zend.org下载对应的安装包:

64位Linux下载

http://www.zend.org/free_download/download?product=optimizer&version=3.2.8&binary=ZendOptimizer-3.2.8-linux-glibc23-x86_64.tar.gz

32位Linux下载

http://www.zend.org/free_download/download?product=optimizer&version=3.2.8&binary=ZendOptimizer-3.2.8-linux-glibc21-i386.tar.gz

解压缩源码包,运行里面的install.sh,按照提示输入php.ini和apache的bin目录的路径,最后按照提示重启Apache即可。

编写一个php脚本,如下:

<?php phpinfo();?>

把它放到Apache的网页发布目录。运行,会看到如下截图:

LAMP的配置指南
 
请注意Configure Command 区域,图中显示为:

'./configure' '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-mysql=/usr/local/mysql' '--with-libxml-dir=/usr/local/libxml2' '--with-expat-dir=/usr/lib' '--enable-soap' '--with-xsl=/usr/local/libxslt' '--enable-xslt' '--with-gd=/usr/local/gd2/' '--with-jpeg-dir=/usr/local/jpeg6/' '--with-zlib-dir=/usr/lib' '--with-png' '--with-freetype-dir=/usr/local/freetype' '--with-iconv=/usr/local/libiconv'

还有Zend图标显示的那个表格,如果有以下字样证明Zend Optimizer已经安装成功。

with Zend Optimizer v3.2.8, Copyright (c) 1998-2007, by Zend Technologies

至此全部的lamp环境配置已经完成,以下部分为lamp常用的一些程序的介绍和安装的后续过程介绍。

下载
 cd /root/soft
 wget
http://nchc.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-2.6.4-pl3.tar.gz
 tar -zxf phpMyAdmin-2.6.4-pl3.tar.gz
 vi phpMyAdmin-2.6.4-pl3/config.inc.php
找到 $cfg['Servers'][$i]['auth_type'] = 'config'; 将config 改为 http
保存后
mv phpMyAdmin-2.6.4-pl3 /你的phpmyadmin目录
关于mysql4.1-4移植4.0旧数据库中文乱码问题的解决方法
进入phpmyadmin管理
建立你数据库名并选上 gb2312_bin 的编码
然后导入你先前备份好的SQL文件, 导入时选择 文件的字符集:gb2312
完成后就OK了
注: PHP连接mysql4.1和5.0 数据库后需指定字符集 需执行如 mysql_query("SET NAMES 'gb2312' ");
否则会产生中文乱码问题!

注:如果MySQL安装后只能本地进行访问,而不能用PHP访问MySQL,请按以下方式解决(检验MySQL的访问权限是否正确):
shell> mysqladmin version
shell> mysqladmin variables
shell> mysqladmin -h `hostname` version variables
shell> mysqladmin -h `hostname` --port=3306 version
shell> mysqladmin -h host_ip version
shell> mysqladmin --protocol=socket --socket=/tmp/mysql.sock version

1)将MySQL作为系统服务自动启动的配置

经过查看MySQL的官方文档,进入mysql安装源码目录下的support-files目录后,在命令行执行以下命令即可:

shell> cp mysql.server /etc/init.d/mysql
shell> chmod +x /etc/init.d/mysql

2)将Apache作为系统服务自启动的配置

如果linux服务器已安装的有apache服务器,为使不影响我们的apache,需要更改/etc/rc.d/init.d/httpd这个启动脚本文件:

vi /etc/rc.d/init.d/httpd
更改以下三个属性:
将apachectl=/usr/sbin/apachectl改为:
apachectl=/usr/local/apache/bin/apachectl
将httpd=/usr/sbin/httpd改为:
httpd=/usr/local/apache/bin/httpd
将CONFFILE=/etc/httpd/conf/httpd.conf改为:
CONFFILE=/usr/local/apache/conf/httpd.conf
完成之后,可以通过service httpd restart重新启动我们需要的apache服务。

如果以前没有安装过Apache,只要输入以下命令即可:

shell>cp apache源码目录/support-files/apachectl /etc/rc.d/init.d/httpd

shell>chmod  +x /etc/init.d/httpd
shell>chkconfig --add httpd

3)禁止apache的目录浏览

编辑httpd.conf,找到“Options Indexes FollowSymLinks”,将其改为“Options -Indexes FollowSymLinks”即可。

4)给Apache加入目录认证

编辑httpd.conf,找到“AllowOverride None”,改为“AllowOverride AuthConfig ”

 建立一个密码文件。这个文件可以放在不能被网络访问的位置,以避免被下载, 例如,如果,/usr/local/apache/htdocs以外的空间不能被网络访问, 那么可以考虑把密码文件放在/usr/local/apache/passwd目录中。

Apache在其安装目录的bin子目录中提供了叫htpasswd的工具,以建立密码文件,可以这样使用:

htpasswd -c /usr/local/apache/passwd/passwords rbowen

htpasswd会要你输入密码,并要求重新输入以确认:

# htpasswd -c /usr/local/apache/passwd/passwords rbowen
New password: mypassword
Re-type new password: mypassword
Adding password for user rbowen

如果htpasswd不在搜索路径中,则必须使用完整路径, 如,/usr/local/apache/bin/htpasswd

然后,需要修改httpd.conf.htaccess文件, 以指示服务器允许哪些用户访问并向用户索取密码。 例如,要保护 /usr/local/apache/htdocs/secret 目录, 则可以将下列指令写入 /usr/local/apache/htdocs/secret/.htaccess, 或者httpd.conf的 <Directory /usr/local/apache/apache/htdocs/secret> 段。

AuthType Basic
AuthName "Restricted Files"
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen

进行以上修改后,重启Apache即可生效。

1)在进行PHP的安装时出现错误:configure: error: mysql configure failed. mysql

经过查看错误日志-config.log,发现以下错误提示:

/* Override any gcc2 internal prototype to avoid an error.  */
/* We use char because int might match the return type of a gcc2
    builtin and then its argument prototype would still apply.  */

google一下,发现是gcc版本不兼容的问题,于是从mysql官网下载mysql-standard-5.0.27-linux-i686-glibc23.tar.gz进行安装,一切正常,未出现此错误。
经测试,用mysql-standard-5.0.27-linux-i686.tar.gz时会提示错误,换了mysql-standard-5.0.27-linux-i686-glibc23.tar.gz后就正常了。

2)无法用PHPMyAdmin远程访问MySQL数据库

错误提示如下图:

LAMP的配置指南

出现以上错误是由于MySQL数据库不允许远程访问导致的,解决办法是用命令行方式打开MySQL数据库。输入如下命令:

[root@localhost bin]# ./mysql -u root -p

输入mysql密码。

mysql> use mysql
mysql> update user set host='%' where user='访问mysql的用户名';
mysql> exit

经过以上设置,即可远程访问mysql数据库。

3.在编译php的过程中报以下错误

configure: error: mysql configure failed. Please check config.log for more information.

以上错误是在RHEL4 64的系统中编译PHP源码包出现的,所用的mysql安装源码包是mysql-standard-5.0.27-linux-i686-glibc23.tar.gz,去网上查了大量资料,也未找到答案。最后下载最新的mysql源码安装包 mysql-5.0.41-linux-x86_64-icc-glibc23.tar.gz,重新安装最新版mysql,然后编译PHP,终于通过了PHP的编译,出现以下熟悉的信息:

+--------------------------------------------------------------------------------------------------------+
| License:                                                                                            |
| This software is subject to the PHP License, available in this          |
| distribution in the file LICENSE.  By continuing this installation       |
| process, you are bound by the terms of this license agreement.      |
| If you do not agree with the terms of this license, you must abort    |
| the installation process at this point.                                                 |
+----------------------------------------------------------------------------------------------------------+

Thank you for using PHP.

至此问题解决







标签: 技术   LAMP配置   gd库安装  
评论: LAMP的配置指南
2007-06-26 10:27:39
强!顶小戴一下!
2007-06-26 17:09:56
2008-01-18 16:36:52
发表我的评论
粗体 斜体 下划线 插入超链接 插入表情
Email:
密 码:

验证码:





(请输入图中数字)   看不清,换一个试试
提示
  • 1.遵守国家有关法律、法规,尊重网上道德
  • 2.承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 3.互动维客留言板管理人员有权保留或删除其管辖留言中的任意内容

关于我们| 新闻中心| 服务条款| 联系我们| 招聘信息| 合作伙伴| 站点地图| About us| 奥运知识比拼

Copyright © 2005-2008 Hoodong.com Ltd. All Rights Reserved. 互动在线 版权所有 京ICP证060907号