基于CentOS 6.0最小化编译安装Apache+MySQL+PHP+Zend
操作系统:CentOS 6.0 32位
安装方式:采用最小化安装,在安装系统的时候选择Minimal(CentOS 6.0默认就是Minimal安装模式,不含有任何 可选安装包)
最小化安装完成之后,系统占用900M左右磁盘空间。
安装前准备:
1、配置好ip dns 网关,确保使用远程连接工具能够连接服务器
2、关闭selinux
vi /etc/selinux/config 把SELINUX=enforcing SELINUXTYPE=targeted注释掉,然后新加一行为:SELINUX=disabled
3、开启防火墙相应端口,apache需要开启80端口 MySQL需要开启3306端口
vi /etc/sysconfig/iptables #编辑配置文件添加下面的内容
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #(允许80端口通过防火墙)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #(允许3306端口通过防火墙)
/etc/init.d/iptables restart #重启防火墙使配置生效
4 、系统约定
软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
5、下载软件
http://apache.etoak.com//httpd/httpd-2.2.21.tar.gz #下载apache
http://gd.tuwien.ac.at/db/mysql/Downloads/MySQL-5.1/mysql-5.1.59-linux-i686-glibc23.tar.gz #下载mysql
http://cn.php.net/distributions/php-5.2.17.tar.gz #下载php
http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz #下载ZendOptimize
http://www.cpan.org/src/5.0/perl-5.14.1.tar.gz #下载perl
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz #下载libmcrypt
用WinSCP远程连接到服务器,把下载好的软件上传到服务器/usr/local/src下面。
6、下载编译工具(要编译安装软件,必须先安装编译工具)
下载地址 http://mirror.centos.org/centos/6.0/os/i386/Packages/
或者直接从CentOS 6.0的安装光盘中复制出来,打开安装光盘,在Packages文件夹下面,找到下面的安装包
kernel-headers-2.6.32-71.el6.i686.rpm
compat-glibc-headers-2.5-46.2.i686.rpm
compat-glibc-2.5-46.2.i686.rpm
compat-libstdc++-33-3.2.3-69.el6.i686.rpm
compat-libf2c-34-3.4.6-19.el6.i686.rpm
compat-libgcc-296-2.96-144.el6.i686.rpm
mpfr-2.4.1-6.el6.i686.rpm
cpp-4.4.4-13.el6.i686.rpm
glibc-headers-2.12-1.7.el6.i686.rpm
glibc-devel-2.12-1.7.el6.i686.rpm
libgomp-4.4.4-13.el6.i686.rpm
libstdc++-devel-4.4.4-13.el6.i686.rpm
ppl-0.10.2-11.el6.i686.rpm
cloog-ppl-0.15.7-1.2.el6.i686
gcc-4.4.4-13.el6.i686.rpm
compat-gcc-34-3.4.6-19.el6.i686.rpm
compat-gcc-34-c++-3.4.6-19.el6.i686.rpm
make-3.81-19.el6.i686.rpm
keyutils-libs-devel-1.4-1.el6.i686.rpm
libcom_err-devel-1.41.12-3.el6.i686.rpm
libsepol-devel-2.0.41-3.el6.i686.rpm
libselinux-devel-2.0.94-2.el6.i686.rpm
krb5-devel-1.8.2-3.el6.i686.rpm
zlib-devel-1.2.3-25.el6.i686.rpm
openssl-devel-1.0.0-4.el6.i686.rpm
libXpm-3.5.8-2.el6.i686.rpm
gd-2.0.35-10.el6.i686.rpm
freetype-2.3.11-5.el6.i686.rpm
libxml2-2.7.6-1.el6.i686.rpm
libxml2-devel-2.7.6-1.el6.i686.rpm
curl-7.19.7-16.el6.i686.rpm
libjpeg-devel-6b-46.el6.i686.rpm
libjpeg-6b-46.el6.i686.rpm
libjpeg-static-6b-46.el6.i686.rpm
libpng-1.2.44-1.el6.i686.rpm
libpng-devel-1.2.44-1.el6.i686.rpm
libpng-static-1.2.44-1.el6.i686.rpm
php-common-5.3.2-6.el6.i686.rpm
php-gd-5.3.2-6.el6.i686.rpm
gcc-c++-4.4.4-13.el6.i686.rpm
ncurses-devel-5.7-3.20090208.el6.i686.rpm
ncurses-term-5.7-3.20090208.el6.i686.rpm
ncurses-static-5.7-3.20090208.el6.i686.rpm
perl-Pod-Escapes-1.04-115.el6.i686.rpm
perl-libs-5.10.1-115.el6.i686.rpm
perl-version-0.77-115.el6.i686.rpm
perl-Module-Pluggable-3.90-115.el6.i686.rpm
perl-Pod-Simple-3.13-115.el6.i686.rpm
perl-5.10.1-115.el6.i686.rpm
autoconf213-2.13-20.1.el6.noarch.rpm
autoconf-2.63-5.1.el6.noarch.rpm
automake-1.11.1-1.2.el6.noarch.rpm
automake14-1.4p6-19.2.el6.noarch.rpm
automake16-1.6.3-18.el6.1.noarch.rpm
libtool-ltdl-2.2.6-15.5.el6.i686.rpm
libtool-ltdl-devel-2.2.6-15.5.el6.i686.rpm
libtool-2.2.6-15.5.el6.i686.rpm
patch-2.6-6.el6.i686.rpm
把这些安装包用WinSCP远程连接工具上传到服务器的/usr/local/src下面
到此,安装前准备工作完成,
注意:这里我们是把软件下载好之后,再通过远程连接工具上传到服务器上面的。
因为最小化安装完系统之后是不带wget命令的,所以无法直接从服务器下载,
当然,不建议直接在服务器上面下载软件。正式安装开始
以下是用putty工具远程登录到服务器,在终端命令行下面操作的
1、安装编译工具
cd /usr/local/src #进入软件包存放目录
按照以下顺序进行安装,特别注意:顺序一定不能错,否则安装失败
小技巧:可以把下面的所有行按顺序一次性复制到终端命令行,
系统会自动安装的,这样会节省很对时候,同时也避免操作错误!
####################################################################
rpm -ivh kernel-headers-2.6.32-71.el6.i686.rpm
rpm -ivh compat-glibc-headers-2.5-46.2.i686.rpm
rpm -ivh compat-glibc-2.5-46.2.i686.rpm
rpm -ivh compat-libstdc++-33-3.2.3-69.el6.i686.rpm
rpm -ivh compat-libf2c-34-3.4.6-19.el6.i686.rpm
rpm -ivh compat-libgcc-296-2.96-144.el6.i686.rpm
rpm -ivh mpfr-2.4.1-6.el6.i686.rpm
rpm -ivh cpp-4.4.4-13.el6.i686.rpm
rpm -ivh glibc-headers-2.12-1.7.el6.i686.rpm
rpm -ivh glibc-devel-2.12-1.7.el6.i686.rpm
rpm -ivh libgomp-4.4.4-13.el6.i686.rpm
rpm -ivh libstdc++-devel-4.4.4-13.el6.i686.rpm
rpm -ivh ppl-0.10.2-11.el6.i686.rpm
rpm -ivh cloog-ppl-0.15.7-1.2.el6.i686.rpm
rpm -ivh gcc-4.4.4-13.el6.i686.rpm
rpm -ivh compat-gcc-34-3.4.6-19.el6.i686.rpm
rpm -ivh compat-gcc-34-c++-3.4.6-19.el6.i686.rpm
rpm -ivh make-3.81-19.el6.i686.rpm
rpm -ivh keyutils-libs-devel-1.4-1.el6.i686.rpm
rpm -ivh libcom_err-devel-1.41.12-3.el6.i686.rpm
rpm -ivh libsepol-devel-2.0.41-3.el6.i686.rpm
rpm -ivh libselinux-devel-2.0.94-2.el6.i686.rpm
rpm -ivh krb5-devel-1.8.2-3.el6.i686.rpm
rpm -ivh zlib-devel-1.2.3-25.el6.i686.rpm
rpm -ivh openssl-devel-1.0.0-4.el6.i686.rpm
rpm -ivh libXpm-3.5.8-2.el6.i686.rpm
rpm -ivh gd-2.0.35-10.el6.i686.rpm
rpm -ivh freetype-2.3.11-5.el6.i686.rpm
rpm -ivh libxml2-2.7.6-1.el6.i686.rpm
rpm -ivh libxml2-devel-2.7.6-1.el6.i686.rpm
rpm -ivh curl-7.19.7-16.el6.i686.rpm
rpm -ivh libjpeg-devel-6b-46.el6.i686.rpm
rpm -ivh libjpeg-6b-46.el6.i686.rpm
rpm -ivh libjpeg-static-6b-46.el6.i686.rpm
rpm -ivh libpng-1.2.44-1.el6.i686.rpm
rpm -ivh libpng-devel-1.2.44-1.el6.i686.rpm
rpm -ivh libpng-static-1.2.44-1.el6.i686.rpm
rpm -ivh php-common-5.3.2-6.el6.i686.rpm
rpm -ivh php-gd-5.3.2-6.el6.i686.rpm
rpm -ivh gcc-c++-4.4.4-13.el6.i686.rpm
rpm -ivh ncurses-devel-5.7-3.20090208.el6.i686.rpm
rpm -ivh ncurses-term-5.7-3.20090208.el6.i686.rpm
rpm -ivh ncurses-static-5.7-3.20090208.el6.i686.rpm
rpm -ivh --nodeps perl-Pod-Escapes-1.04-115.el6.i686.rpm
rpm -ivh --nodeps perl-libs-5.10.1-115.el6.i686.rpm
rpm -ivh --nodeps perl-version-0.77-115.el6.i686.rpm
rpm -ivh --nodeps perl-Module-Pluggable-3.90-115.el6.i686.rpm
rpm -ivh --nodeps perl-Pod-Simple-3.13-115.el6.i686.rpm
rpm -ivh --nodeps perl-5.10.1-115.el6.i686.rpm
rpm -ivh autoconf213-2.13-20.1.el6.noarch.rpm
rpm -ivh autoconf-2.63-5.1.el6.noarch.rpm
rpm -ivh automake-1.11.1-1.2.el6.noarch.rpm
rpm -ivh automake14-1.4p6-19.2.el6.noarch.rpm
rpm -ivh automake16-1.6.3-18.el6.1.noarch.rpm
rpm -ivh libtool-ltdl-2.2.6-15.5.el6.i686.rpm
rpm -ivh libtool-ltdl-devel-2.2.6-15.5.el6.i686.rpm
rpm -ivh libtool-2.2.6-15.5.el6.i686.rpm
rpm -ivh patch-2.6-6.el6.i686.rpm
#####################################################
2、安装libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.7.tar.gz #解压
cd libmcrypt-2.5.7 #进入目录
./configure #配置
make #编译
make install #安装
========================================
3、安装perl
cd /usr/local/src
tar zxvf perl-5.14.1.tar.gz
cd perl-5.14.1
./Configure -des -Dprefix=/usr/local/perl
make
make install
=======================================
4、安装MySQL
cd /usr/local/src
tar zxvf mysql-5.1.59-linux-i686-glibc23.tar.gz #解压
cp -r mysql-5.1.59-linux-i686-glibc23 /usr/local/ #复制文件夹到/usr/local/目录下面
cd /usr/local #进入/usr/local目录
mv mysql-5.1.59-linux-i686-glibc23 mysql #把文件夹mysql-5.1.59-linux-i686-glibc23改名为mysql
groupadd mysql #添加mysql组
useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
chown -R root /usr/local/mysql/ #允许root访问
chgrp -R mysql /usr/local/mysql/ #允许mysql组访问
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld #执行权限
cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
或者服务器有4G以上内存,用下面的这行
cp /usr/local/mysql/support-files/my-innodb-heavy-4G.ini /etc/my.cnf #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
cd /usr/local/mysql/
./scripts/mysql_install_db --user=mysql& #生成mysql系统数据库
./bin/mysqld_safe --user=mysql& #开启MySQL服务
vi /etc/profile #把mysql服务加入系统环境变量:
在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
/etc/rc.d/init.d/mysqld start #启动
chkconfig mysqld on #加入开机启动
shutdown -r now #需要重启系统,等待系统重新启动之后继续在终端命令行下面操作
mysql_secure_installation #设置Mysql密码
根据提示按Y 回车输入2次密码
或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码
service mysqld restart #重启
=====================================================================
5、安装apache2
cd /usr/local/src
tar -zvxf httpd-2.2.21.tar.gz
cd httpd-2.2.21
mkdir -p /usr/local/apache2 #创建安装目录
./configure --prefix=/usr/local/apache2 --with-ssl --enable-ssl --enable-module=so --enable-rewrite --enable-cgid --enable-cgi #配置
make #编译
make install #安装
/usr/local/apache2/bin/apachectl -k start #启动
vi /usr/local/apache2/conf/httpd.conf #编辑配置文件
找到:#ServerName www.example.com:80
修改为:ServerName localhost:80
找到:DirectoryIndex index.html
修改为:DirectoryIndex index.html index.php
找到:Options Indexes FollowSymLinks
修改为:Options FollowSymLinks #不显示目录结构
vi /etc/profile #添加apache服务系统环境变量
在最后添加下面这一行
export PATH=$PATH:/usr/local/apache2/bin
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd #把apache加入到系统启动
vi /etc/init.d/httpd #编辑文件
在#!/bin/bash下面添加以下两行
chkconfig:2345 10 90
descrption:Activates/Deactivates Apache Web Server
chown daemon.daemon -R /usr/local/apache2/htdocs
chmod -R 700 /usr/local/apache2/htdocs #更改apache网站目录权限
chkconfig httpd on #设置开机启动
/etc/init.d/httpd start
service httpd restart
=====================================================================
6、安装php
cd /usr/local/src
tar -zvxf php-5.2.17.tar.gz
cd php-5.2.17
mkdir -p /usr/local/php5 #建立php安装目录
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt
make
make install
cd /usr/local/php5/
mkdir etc
cp /usr/local/src/php-5.2.17/php.ini-dist /usr/local/php5/etc/php.ini #复制php配置文件到安装目录
vi /usr/local/php5/etc/php.ini #编辑
找到:;open_basedir =
修改为:open_basedir = .:/tmp/ #防止php木马跨站,重要!!
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC
找到:expose_php = On
修改为:expose_php = OFF #禁止显示php版本的信息
找到:display_errors = On
修改为:display_errors = OFF #关闭错误提示
=====================================================================
7、安装ZendOptimize
cd /usr/local/src
mkdir /usr/local/zend #建立Zend Optimizer安装目录
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz #解压安装文件
cp /usr/local/src/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend #拷贝文件到安装目录
vi /usr/local/php5/etc/php.ini #配置php支持Zend
在最后位置添加以下三行内容
[Zend Optimizer]
zend_optimizer.optimization_level=15
zend_extension="/usr/local/zend/ZendOptimizer.so"
/etc/init.d/httpd restart #重启apache
=====================================================================
8、配置apache支持php
vi /usr/local/apache2/conf/httpd.conf #编辑apache配置文件
在LoadModule php5_module modules/libphp5.so这一行下面添加
AddType application/x-httpd-php .php (注意:php .php这个点前面有一个空格)
=====================================================================
9、配置apache支持perl
vi /usr/local/apache2/bin/apxs #编辑
第一行修改为:
!/usr/local/perl/bin/perl -w
=====================================================================
service httpd restart #重启apache
service mysqld restart #重启mysql
#####################################################################
到此,Apache+MySQL+PHP+Zend基本运行环境搭建完成!
网站程序上传到/usr/local/apache2/htdocs目录里面,如果安装有问题,请检查目录权限
确保改目录为以下权限
chown daemon.daemon -R /usr/local/apache2/htdocs
chmod -R 700 /usr/local/apache2/htdocs
注意:如果要用于正式生产环境,还需要进一步详细的设置配置系统的安全等各个方面。