Centos服务器架设之一

mysql, apache, php, GD,Zend Optimizer, eaccelerator
我购买的服务器的操作系统是Centos5 32bit的,所以以下的都是基于此操作系统的,其实其他Linux系统也可以参考一下!
一,安装前准备:
1.准备安装所需软件包:

Apache:2.2.8
Php:5.2.5
mysql:5.0.56
GD:2.0.35
Zend Optimizer:3.3.0
eaccelerator:0.9.5.2
cronolog:1.7.0.beta
Libmcrypt: 2.5.8
Suhosin:0.9.6.2
我是用wget下载至/usr/local/src/

2.安装所需开发包

[root@server ~]#yum 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

二,编译安装
1.GD2

[root@server ~]#cd /usr/local/src
[root@server src]# tar xzvf gd-2.0.35.tar.gz
[root@server src]# cd gd-2.0.35
[root@server gd-2.0.35]# aclocal
[root@server gd-2.0.35]#./configure --prefix=/usr/local/gd2 --mandir=/usr/share/man
[root@server gd-2.0.35]#make
[root@server gd-2.0.35]#make install


2.Cronolog (apache 日志截断程序)

[root@server ~]#cd /usr/local/src
[root@server src]#tar cronolog-1.7.0-beta.tar.gz
[root@server src]#cd cronolog-1.7.0-beta
[root@server cronolog-1.7.0-beta]#./configure --prefix=/usr/local/cronolog
[root@server cronolog-1.7.0-beta]#make
[root@server cronolog-1.7.0-beta]#make install

3.mysql 5.0.56

root@server ~]#cd /usr/local/src
[root@server src]# tar xzvf mysql-5.0.56.tar.gz
[root@server src]# cd mysql-5.0.56
[root@server mysql-5.0.56]#vi sql/mysqld.cc
搜索找到下面一行:

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

将其中的100改为1500,当然改成你想改的也可以,然后保存。

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

[root@server mysql-5.0.56]#./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
如果编译成功,你会看到:Thank you for choosing MySQL!
[root@server mysql-5.0.56]#make
[root@server mysql-5.0.56]#make install
编译安装完成后执行后续操作:
[root@server mysql-5.0.56]#useradd mysql
[root@server mysql-5.0.56]#cd /usr/local/mysql
[root@server mysql]#bin/mysql_install_db --user=mysql
[root@server mysql]#chown -R root:mysql .
[root@server mysql]#chown -R mysql /var/lib/mysql
[root@server mysql]#chgrp -R mysql .
[root@server mysql]#cp share/mysql/my-medium.cnf /etc/my.cnf
[root@server mysql]#cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
[root@server mysql]#chmod 755 /etc/rc.d/init.d/mysqld
[root@server mysql]# chkconfig --add mysqld
[root@server mysql]#echo "/usr/local/mysql/lib" >> /etc/ld.so.conf && ldconfig
用 /etc/rc.d/init.d/mysqld start 或service mysqld stop 开始关闭mysqld服务!
修改root初始密码:bin/mysqladmin -u root password "你要改的密码"

4.Apache

[root@server ~]# cd /usr/local/src
[root@server src]# tar zxvf httpd-2.2.8.tar.gz
[root@server src]#cd httpd-2.2.8
[root@server httpd-2.2.8]#cd srclib/apr
[root@server apr]#./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static
[root@server apr]#make && make install
[root@server apr]#cd ../apr-util
[root@server apr-util]#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/mysql
[root@server apr-util]#make && make install
[root@server apr-util]#cd /usr/local/src/httpd-2.2.8
[root@server httpd-2.2.8]#./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
[root@server httpd-2.2.8]#make
[root@server httpd-2.2.8]#make install
[root@server httpd-2.2.8]#cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
[root@server httpd-2.2.8]# chkconfig --add httpd
[root@server httpd-2.2.8]#chkconfig httpd on
[root@server httpd-2.2.8]#service httpd start

5.Libmcrypt

[root@server ~]# cd /usr/local/src
[root@server src]#tar zxvf libmcrypt-2.5.8.tar.gz
[root@server src]#cd libmcrypt-2.5.8
[root@server libmcrypt-2.5.8]#./configure --prefix=/usr/local/libmcrypt
[root@server libmcrypt-2.5.8]#make
[root@server libmcrypt-2.5.8]#make install

6.php

[root@server ~]# cd /usr/local/src
[root@server src]# tar zxvf php-5.2.5.tar.gz
[root@server src]# gunzip suhosin-patch-5.2.5-0.9.6.2.patch.gz
[root@server src]# cd php-5.2.5
[root@server php-5.2.5]# patch -p 1 -i ../suhosin-patch-5.2.5-0.9.6.2.patch
[root@server php-5.2.5]# ./buildconf --force
[root@server php-5.2.5]# ./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=/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-libmcrypt=usr/local/libmcrypt/lib --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
编译成功会出现:Thank you for using PHP.
[root@server php-5.2.5]#make
[root@server php-5.2.5]#make test
[root@server php-5.2.5]#make install
让apache支持php
[root@server ~]#vi /usr/local/apache2/conf/httpd.conf
找到:
DirectoryIndex index.html
修改为:
DirectoryIndex index.html index.php index.htm
加上:AddType application/x-httpd-php .php(建议在最后)
找到:
# 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
修改为:
# 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 All
目的是支持rewrite
保存退出

7.Zend Optimizer

[root@server ~]# cd /usr/local/src
[root@server src]# tar xzvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
[root@server src]#./ZendOptimizer-3.3.0-linux-glibc21-i386/install.sh
按照提示一步一步设置安装就行了,要注意的是安装成功后你的php.ini的路径是:/usr/local/Zend/etc/php.ini

8.Eaccelerator

[root@server ~]# cd /usr/local/src
[root@server src]# tar -jxvf eaccelerator-0.9.5.2.tar.bz2
[root@server src]#cd eaccelerator-0.9.5.2
[root@server eaccelerator-0.9.5.2]# export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize
[root@server src]#cd eaccelerator-0.9.5.2
[root@server eaccelerator-0.9.5.2]# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
[root@server eaccelerator-0.9.5.2]# make & make install
编译安装后你会看到屏幕提示的eaccelerator.so所在的目录如:/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so请记住!
修改php.ini(/usr/local/Zend/etc/php.ini )
在zend之前插入以下内容:
[eaccelerator]
extension="/usr/local/php/lib/php/extensions/no-debug-zts-20060613/eaccelerator.so" //这个就是刚才编译安装得到的eaccelerator.so所在的目录
eaccelerator.shm_size="32"
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"
[root@server eaccelerator-0.9.5.2]# mkdir /tmp/eaccelerator
[root@server eaccelerator-0.9.5.2]# chmod 0777 /tmp/eaccelerator

环境测试:phpinfo
我自己在安装过程中遇到过许多问题,G一下以后都解决了,如果你在安装过程中有什么问题请留言,谢谢!

请回复此日志

你可以使用这些XHTML标签: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>