搞搞Linux下的apache2.2+php5+mysql5的配置

By SuperTaoer | 二月 23, 2009
Under: 程序 技术 周边
Views: 4,304 views

近来一直在北京养我的腿,闲来无事,就听从了车东的建议,把以前的技术的dd再整理下儿,
对webserver的配置还停留在apache2.0 php4 mysql4的阶段,借这个时机也来搞搞apache2.2+php5+mysql5的配置

我下载的都是最新的版本,目前我下载的版本号为:
httpd-2.2.11.tar.gz
mysql-5.1.31-linux-i686-glibc23.tar.gz
php-5.2.8.tar.gz
ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
PHPUnit3.3.14.tar.gz
ZendFramework-1.7.5.zip

—– mysql 的分割线 —–

好,咱们还是先来编译配置mysql吧
先建立mysql用户组,mysql用户,并且把mysql用户加入到mysql用户组中。
并且这里为了安全起见,将禁止mysql这个用户登录,并且不设置用户目录,起个密码儿就变态点儿呗。

#*-g 是加入到mysql用户组,-p是设置密码,-s是设置shell,这里设置的是不让其登录,-M就是不建立用户目录啦。

  1. groupadd mysql
  2. useradd mysql -g mysql -p aabbKDJF -s /sbin/nologin -M

然后解压缩并进入到目录中,执行如下命令

#编译并安装mysql

  1. ./configure –prefix=/usr/local/mysql5.1.31 –exec-prefix=/usr/local/mysql5.1.31 –sysconfdir=/etc/ –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-mysqld-user=mysql –enable-assembler –disable-shared –with-charset=utf8 –with-extra-charsets=all
  2. make && make install

#安装完成,接下来安装库文件

  1. cd scripts/
  2. ./mysql_install_db –user=mysql

#这两个命令是将mysql5.1.31软链接为mysql这样以后升级的时候,还可以在这个目录下面安装mysql5.xx.xx,这样只要改变mysql软链接的指向就可以了。之后的apache2和php5都将采取这种方式。

  1. cd /usr/local/
  2. ln -s mysql5.1.31 mysql

#设置目录访问权限

  1. cd /usr/local/mysql5.1.31
  2. chown -R root ./
  3. chown -R mysql var/
  4. chown -R mysql var/ ./
  5. chgrp -R mysql ./

#启动mysql

  1. /usr/local/mysql/bin/mysqld_safe –user=mysql &

#设置root初始密码

  1. /usr/local/mysql5.1.31/bin/mysqladmin -u root password ‘123123′

#下面两行是进入到mysql控制台修改root密码的方法

  1. USE mysql
  2. UPDATE user SET Password=PASSWORD(‘123123′) WHERE User=’root’;
  3. FLUSH PRIVILEGES;

再把: /usr/local/mysql/bin/mysqld_safe –user=mysql & 加入到你的/etc/rc.local文件中吧,这样就可以随系统启动了。

OK,现在mysql部分就安装完鸟,更多的配置请参考相关手册吧。。。

—– apache2的分割线 —–
由于apache2和php5都要用到openssl,所以就先来整openssl吧,我用的版本是:openssl-0.9.8j.tar.gz
openssl编译:

  1. ./config –prefix=/usr/local/openssl && make && make install

现在来安装apache2,解压缩并进入解压缩后的目录,然后执行:

  1. ./configure –prefix=/usr/local/apache2.2.11 –enable-log-config –enable-rewrite –enable-vhost-alias –disable-access –disable-include –disable-setenvif –disable-autoindex –disable-negotiation –disable-userdir –enable-deflate –disable-auth –disable-env –disable-asis –disable-cgi –disable-imap –enable-actions –disable-alias –enable-ssl=static –with-ssl=/usr/local/ssl
  2. make && make install

#为了使用方便建立软链接

  1. cd /usr/local
  2. ln -s apache2.2.11 apache2

好的,apache2先到此告一段落。

—– php5的分割线 —–
为了增加一些php的扩展,首先需要安装一些玩艺儿,我安装了如下的dd
curl-7.14.0
freetype-2.1.10
gd-2.0.33
jpegaltui.v6b
libiconv-1.9.1
libmcrypt-2.5.7
libpng-1.2.8
libxml2-2.6.20
mhash-0.9.2
zlib-1.2.2

好了 let’s go!

curl编译:

  1. ./configure –prefix=/usr/local/curl && make && make install

libiconv编译:

  1. ./configure –prefix=/usr/local/libiconv && make && make install

libmcrypt编译:

  1. ./configure –prefix=/usr/local/libmcrypt && make && make install

libxml2编译:

  1. ./configure –prefix=/usr/local/libxml2 && make && make install

zlib编译:

  1. ./configure –prefix=/usr/local/zlib && make && make install

mhash编译:

  1. ./configure –prefix=/usr/local/mhash && make && make install

下面编译的是和gd2库相关的
libpng编译:

  1. mv ./scripts/makefile.linux ./makefile
  2. make && make install

freetype编译:

  1. ./configure –prefix=/usr/local/freetype && make && make install

jpeg编译:

  1. ./configure –enable-shared && make && make test && make install

如果编译过程中出现这样的错误:
/usr/bin/install: cannot create regular file `/usr/local/man/man1/cjpeg.1′: No such file or directory
make: *** [install] Error 1

执行

  1. mkdir /usr/local/man/man1

然后在重新编译

gd2编译:

  1. ./configure –prefix=/usr/local/gd2 –with-png –with-jpeg –with-freetype=/usr/local/freetype && make && make install

开始咱们的php编译:

  1. ./configure –prefix=/usr/local/php-5.2.8/ –enable-force-cgi-redirect –enable-mbstring=all –enable-mbregex –enable-mbstr-enc-trans –enable-versioning –enable-trans-sid –enable-ftp –with-mysql=/usr/local/mysql/ –with-apxs2=/usr/local/apache2/bin/apxs –with-soap=yes –with-curl=/usr/local/curl/ –with-zlib-dir=/usr/local/zlib/ –with-mcrypt=/usr/local/libmcrypt/ –with-gd=/usr/local/gd2 –with-jpeg-dir=/usr –with-freetype-dir=/usr/local/freetype –with-ttf –with-png-dir=/usr –with-mhash=/usr/local/mhash/ –with-dom=/usr/local/libxml2 –with-iconv=/usr/local/libiconv –with-openssl=/usr/local/openssl && make && make install

#为了使用方便建立软链接

  1. cd /usr/local
  2. ln -s php-5.2.8 php

#然后copy配置文件

  1. cp ./php.ini-dist /usr/local/php/lib/php.ini
  2. cd /usr/local/lib
  3. ln -s /usr/local/php/lib/php.ini php.ini

#现在安装zend
zend安装比较简单,解压缩后运行 ./install.sh
然后字符图形界面儿安装就成了。

安装完后,原来的/usr/local/php/lib/php.ini 变成了/usr/local/php/lib/php.ini-zend_optimizer.bak,
而在/usr/local/lib/中的软链接重新指向了:/usr/local/Zend/etc/php.ini

然后咱们还需要一个步骤:

  1. ln -s /usr/local/Zend/etc/php.ini /usr/local/php/lib/php.ini

因为php运行的时候还是会去/usr/local/php/lib/php.ini来读取配置配置文件

好了,基本的安装就到此结束了,下面再来说说一些配置文件的修改。
其实安装apache2.2 mysql5 php5 与apache2.0 mysql4 php4还是大同小异的,那些扩展基本不用动直接拿过来是成,apache2的配置文件我也是从原来的copy过来就改了下儿基本来说很顺利。
现在,其实apache还不能解析php,要想让apache解析php,请看下面。

后面会介绍一些进阶知识(包括让apache解析php,php配置PHPUnit,ZendFramework等)。

差..好文!! (还没评价)
Loading ... Loading ...

Leave a Message

1 Message

RSS feed for comments on this post. TrackBack URI

Leave a Message