帮助文档>>centos 5编译安装apache+php+mysql

很多客户要求我们帮助他们配置环境,第一是因为我们的VPS是无管理或无技术支持的vps,另一个是我们未必有时间帮助客户做这件事,今天发一个在本站VPS的centos 5下编译安装apache+php+mysql+Zend Optimizer+eaccelerator教程,大家可以做参考!
注意,本教程只在本站vps的centos 5系统下编译安装成功!
一,安装所需开发包

1
2
yum -y install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel patch vim vim-mini* libtool*
yum -y update

二,源码编译安装所需包
1.GD2安装
首先编辑freetype.h文件,不然make的时候会报错

1
vi /usr/include/freetype2/freetype/freetype.h

把以下内容注释掉:

1
2
3
4
5
6
7
#ifndef FT_FREETYPE_H
#error "`ft2build.h' hasn't been included yet!"
#error "Please always use macros to include FreeType header files."
#error "Example:"
#error "  #include <ft2build.h>"
#error "  #include FT_FREETYPE_H"
#endif

改为:

1
2
3
4
5
6
7
8
/*
#ifndef FT_FREETYPE_H
#error "`ft2build.h' hasn't been included yet!"
#error "Please always use macros to include FreeType header files."
#error "Example:"
#error "  #include <ft2build.h>"
#error "  #include FT_FREETYPE_H"
#endif*/
1
2
3
4
5
6
7
cd /usr/local/src
wget -c http://www.vpsyou.com/sources/gd-2.0.9.tar.gz
tar zxvf gd-2.0.9.tar.gz
cd gd-2.0.9
./configure --prefix=/usr/local/gd2 --mandir=/usr/share/man
make
make install

2.Apache 日志截断程序

1
2
3
4
5
6
7
 cd /usr/local/src
 wget -c http://www.vpsyou.com/sources/cronolog-1.7.0-beta.tar.gz
 tar zxvf cronolog-1.7.0-beta.tar.gz
 cd cronolog-1.7.0
 ./configure --prefix=/usr/local/cronolog
 make
 make install

3.编译mysql

1
2
3
4
 cd /usr/local/src
 wget -c http://www.vpsyou.com/sources/mysql-5.0.82sp1.tar.gz
 tar zxvf mysql-5.0.82sp1.tar.gz
 cd mysql-5.0.82sp1

修改mysql 客户端最大连接数

1
  vi sql/mysqld.cc

搜索找到下面一行:

1
2
3
4
5
6
7
{"max_connections", OPT_MAX_CONNECTIONS,
 
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
 
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
 
0},

将其中的100改为1500, 当然小点也可以,根据你的需要来,不建议改的太大

1
2
3
4
5
6
7
{"max_connections", OPT_MAX_CONNECTIONS,
 
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
 
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,
 
0},

保存退出
接着执行:

1
2
3
4
5
6
autoreconf --force --install
libtoolize --automake --force
automake --force --add-missing
 ./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid
 make
 make install

mysql的相关设置:

1
2
3
4
5
6
7
8
9
10
 useradd mysql //添加 mysql 用户
cd /usr/local/mysql
bin/mysql_install_db --user=mysql
chown -R root:mysql . //设置权限,注意后面有一个 "."
chown -R mysql /var/lib/mysql //设置 mysql 目录权限
chgrp -R mysql . //注意后面有一个 "."
cp share/mysql/my-medium.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机自动启动 mysql。
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld

添加LIB PATH

1
echo "/usr/local/mysql/lib" >> /etc/ld.so.conf && ldconfig

修改root密码:

1
2
3
 /etc/rc.d/init.d/mysqld start 
 bin/mysqladmin -u root password "你要修改的密码"
service mysqld restart

4.编译apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cd /usr/local/src
 wget -c http://www.vpsyou.com/sources/httpd-2.2.15.tar.gz
 tar zxvf httpd-2.2.15.tar.gz
 cd httpd-2.2.15
 cd srclib/apr
./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static
make
make install
cd ../apr-util
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql
 
make
make install
cd /usr/local/src/httpd-2.2.15
./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mysql=/usr/local/mysql --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-rotatelogs --enable-static-logresolve --enable-static-htdbm --enable-static-ab --enable-static-checkgid --disable-cgid --disable-cgi --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --enable-ssl --with-ssl=/usr/include/openssl --with-pcre
make
make install
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

编辑vi /etc/rc.d/init.d/httpd ,在#!/bin/sh下添加:

1
2
# chkconfig: 2345 50 90
# description: Activates/Deactivates Apache Web Server

最后,运行chkconfig把Apache添加到系统的启动服务组里面:

1
2
chkconfig --add httpd
chkconfig httpd on

5.编译PHP

1
2
3
4
5
6
7
8
9
10
11
12
cd /usr/local/src
wget -c http://www.vpsyou.com/sources/php-5.2.13.tar.gz
wget -c http://www.vpsyou.com/sources/suhosin-patch-5.2.13-0.9.7.patch.gz
tar zxvf php-5.2.13.tar.gz
gunzip suhosin-patch-5.2.13-0.9.7.patch.gz
cd php-5.2.13
patch -p 1 -i ../suhosin-patch-5.2.13-0.9.7.patch
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-pear=/usr/share/php --with-zlib-dir --with-bz2 --with-libxml-dir=/usr --with-gd-dir=/usr/local/gd2 --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf=shared,/usr --enable-mbstring --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/etc --with-iconv --disable-ipv6 --enable-static --enable-maintainer-zts --enable-zend-multibyte --enable-inline-optimization --enable-zend-multibyte --enable-sockets --enable-soap --with-openssl --with-gettext --enable-suhosin
make
make install
cp php.ini-recommended /etc/php.ini
echo "/usr/local/php/lib" >> /etc/ld.so.conf && ldconfig

6.整合apache 与php

1
vi /usr/local/apache2/conf/httpd.conf

在最后一行加上:

1
AddType application/x-httpd-php .php

查找:(设置 WEB 默认文件)

1
DirectoryIndex index.html

修改为:

1
DirectoryIndex index.php index.html index.htm

找到这一段:

1
2
3
4
5
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none

更改为

1
AllowOverride all

允许apache rewrite
保存httpd.conf,退出
7.安装 Zend Optimizer

1
2
3
4
cd /usr/local/src
wget -c http://www.vpsyou.com/sources/ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
tar zxvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
./ZendOptimizer-3.3.0-linux-glibc21-i386/install.sh

按照它的提示一步步进行就行了。
8.安装Eaccelerator

1
2
3
4
5
6
7
8
cd /usr/local/src
wget -c http://www.vpsyou.com/sources/eaccelerator-0.9.6.tar.bz2
tar -jxvf eaccelerator-0.9.6.tar.bz2
cd  eaccelerator-0.9.6
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config --with-eaccelerator-shared-memory
make
make install

编译安装后我们会看到屏幕提示的eaccelerator.so所在的目录,比如我得到的是/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so,记住这个路径,待会要用到。
修改php.ini(安装完zend之后,php.ini存放于/usr/local/Zend/etc)

1
vi /usr/local/Zend/etc/php.ini

查找:

1
extension_dir = "./"

修改为:

1
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20060613/"

在文件最后,zend之前,注意,这部分内容务必放在zend之前,不然可能会出现不可预期的服务器问题。添加下列信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[eaccelerator]
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

然后:

1
2
3
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator
service httpd restart

9.安装phpmyadmin

1
2
3
wget -c http://www.vpsyou.com/sources/phpmyadmin.tar.gz
tar zxvf phpmyadmin.tar.gz
mv phpmyadmin /usr/local/apache2/htdocs/

你可以用http://ip/phpmyadmin 访问

要发表意见或建议,请到这里,谢谢!