找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 9287|回复: 1

LAMP环境的搭建

[复制链接]
发表于 2009-11-27 02:25:00 | 显示全部楼层 |阅读模式 IP:江苏扬州
作者:老王
公司里的服务器系统用的都是Redhat AS 4,对与我这样习惯了Debian的人来说,别提多反感了,但是越反感越来事儿,这不,前几天公司一台测试机的系统崩溃了,我得把LAMP环境重新搭建起来,用惯了APT的我很是不习惯RPM,所以相关软件都选择源代码安装。
Redhat本身的安装很简单,不必多言。下面说说AMP三样软件的情况,其中:Apache(httpd-2.2.3.tar.gz);MySQL(mysql-5.0.24a.tar.gz);PHP(php-5.1.6.tar.gz)。
先说说Apache:
tar zxvf httpd-2.2.3.tar.gz
cd httpd-2.2.3
./configure --enable-so --enable-rewrite=shared
make
make install
这里要说明的是,测试机出于方便性的考虑,我们选择了把PHP编译为Apache动态模块的方式,所以Apache使用了enable-so的参数,实际服务器的使用中,出于效率最优化的考虑,通常将PHP静态编译到Apache中去。还有在上面的编译中,我们附带使用了enable-rewrite的参数,激活了重写功能,其中shared是一个有趣的参数,使用它的话,重写模块会按照动态模块的方式建立,也就是说,会生成一个mod_rewrite.so文件,不使用它的话(直接--enable-rewrite),重写模块会被静态编译到Apache里去。安装好Apache后,使用“httpd -l”命令可以查看安装了静态模块,如果要加载动态模块的话,就在httpd.conf文件里添加相应的LoadModule语句就可以了。
LoadModule rewrite_module modules/mod_rewrite.so
注意:每次修改httpd.conf文件后,先用“httpd -t”命令检查语法是否正确,得到肯定的答案后再重启apache服务。
如果你想用redhat的chkconfig命令来管理apache的启动,那么你需要执行一下步骤:
cp /usr/local/apache2/bin/apachectl /etc/init.d/apache
vi /etc/init.d/apache
加入一下注释,以便chkconfig识别相关信息:
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server
然后:
chkconfig --add apache
注意:确保apache脚本有可执行的属性,如果没有则:chmod +x apache
补充(2006-12-20):今天服务器的HTTPD进程竟然达到了好几千个,内存也消耗光了,修改了一下httpd.conf配置,把KeepAlive设置成Off,搞定了。
再说说MySQL:
groupadd mysql
useradd -g mysql mysql
tar zxvf mysql-5.0.24a.tar.gz
cd mysql-5.0.24a
./configure --prefix=/usr/local/mysql \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
cd /usr/local/mysql
./bin/mysql_install_db --user=mysql
chown -R root .
chown -R mysql var
chgrp -R mysql .
/etc/init.d/mysql start #启动,呵呵

可以用“chkconfig --add mysql”把启动脚本加到chkconfig的管理范围内。当然写到rc.local里也可以,不过还是chkconfig专业点。
注释:chkconfig是redhat专有命令,如果你使用的是debian/ubuntu系统的话,对应的命令可以使用sysvconfig,如果没有的话可以使用“aptitude install sysvconfig”安装。
注意:确保mysql脚本有可执行的属性,如果没有则:chmod +x /etc/init.d/mysql
如果你是全新安装的话,那么缺省状态下不用修改my.cnf的内容MySQL就能正常运行,不过我这次属于升级安装,考虑到以前的数据库,还是需要重新写了一个my.cnf配置一下,如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# If you have a very slow DNS and many hosts, you can get more
# performance by either disabling DNS lookups
skip-name-resolve

# The back_log value indicates how many requests can be stacked
# during this short time before MySQL momentarily stops answering
# new requests. You need to increase this only if you expect a large
# number of connections in a short period of time.
back_log=500

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
[mysql.server]
user=mysql
basedir=/usr/local
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
当你连接MySQL服务器的时候,可能会出现找不到“/tmp/mysql.sock”文件的情况,这是因为MySQL默认把socket文件安装到了/var/lib/mysql/mysql.sock路径上,只要做一个符号链接就OK了。
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
注:[mysqld]中的skip-name-resolve很重要,不然在“show processlist”的时候,可能会发现MySQL会出现大量类似“unauthenticated user”的信息。这主要是大量的网络连接,并且DNS反应慢造成的。类似的原因,back_log也很重要。
MySQL的系统变量设置是一个很重要的环节,具体查考此链接:http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
补充:直接安装二进制版本的MySQL似乎更好,稳定且简单:
     shell> groupadd mysql
     shell> useradd -g mysql mysql
     shell> cd /usr/local
     shell> gunzip < /PATH/TO/MYSQL-VERSION-OS.tar.gz | tar xvf -
     shell> ln -s FULL-PATH-TO-MYSQL-VERSION-OS mysql
     shell> cd mysql
     shell> scripts/mysql_install_db --user=mysql
     shell> chown -R root .
     shell> chown -R mysql data
     shell> chgrp -R mysql .
     shell> bin/mysqld_safe --user=mysql &
最后看看PHP:
tar zxvf php-5.1.6.tar.gz
cd php-5.1.6
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql
make
make install
附:本来想把GD也编译到PHP里去,虽然每次编译后phpinfo()中能看到GD的信息,但是在gd_info()中freetype始终是false,有空了再搞一下。唉!
附录:
今天上班把PHP的gd重新编译了一下,加入了freetype的支持,过程如下:
安装zlib支持:
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install
安装png支持:
tar zxvf libpng-1.2.12-no-config.tar.gz
cd libpng-1.2.12-no-config
cp scripts/makefile.linux makefile
make test
make install
安装jpg支持:
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --enable-shared --enable-static
make
make install
安装freetype支持:
tar zxvf freetype-2.2.1.tar.gz
cd freetype-2.2.1
./configure
make
make install
安装gd支持:
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure \
--with-png=/usr/local \
--with-jpeg=/usr/local \
--with-freetype=/usr/local
make
make install
把安装好的gd集成到php中去:
tar zxvf php-5.1.6.tar.gz
cd php-5.1.6
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-zlib=/usr/local \
--with-gd=/usr/local \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-zlib-dir=/usr/local \
--with-freetype-dir=/usr/local \
--enable-gd-native-ttf \
--enable-mbstring \
--with-curl
make
make install
注意:Linux下采用源代码安装软件,一般解压缩后都会有一个INSTALL文件,里面会介绍安装的详细步骤。
相关软件:
zlib: http://www.zlib.net/
pgn: http://www.libpng.org/pub/png/libpng.html
jpg: ftp://ftp.uu.net/graphics/jpeg/
freetype: http://www.freetype.org/
gd: http://www.boutell.com/gd/
注意:软件安装完成后,相关源代码最好留着,以方便以后修改软件设置的时候重新编译使用,比如我一般建立一个“/usr/src/software”目录,把源代码都放到此目录中,并且最好记住每个软件的编译参数。还有一点要提醒一下,每次重新编译前,最好先执行一下“make clean”命令,以免以前的编译过程对现在产生影响。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 21:34 , Processed in 0.328434 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表