这是我装apache2.4的步骤。红色文字的是ubuntu要用到的。apache 2.4需要三个组件pcre、apr、apr-util,装起来比较麻烦点。 先安装必须的组件 centos yum -y install gcc gcc-c++ automake autoconf libtool make wget zlib zlib-devel ubuntu,最好切换到root用户下,不然每次都输sudo很麻烦。 apt-get install make gcc libtool build-essential zlib1g-dev autoconf 装pcre wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz tar zxvf pcre-8.32.tar.gz cd pcre-8.32 ./configure --prefix=/usr/local/pcre make make install 下载和解压apr和apr-util wget http://mirrors.cnnic.cn/apache/apr/apr-1.4.6.tar.gz tar xzvf apr-1.4.6.tar.gz wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.2.tar.gz tar zxvf apr-util-1.5.2.tar.gz wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.4.tar.gz tar zxvf httpd-2.4.4.tar.gz 将apr和apr-util放到apache目录里 mv apr-1.4.6 httpd-2.4.4/srclib/apr mv apr-util-1.5.2 httpd-2.4.4/srclib/apr-util 开始安装apache cd httpd-2.4.4 ./configure --prefix=/usr/local/apache --with-apr --with-apr-util --with-pcre --enable-so --with-included-apr --with-pcre=/usr/local/pcre make make install 编辑配置文件的一行,不然无法启动 vi /usr/local/apache/conf/httpd.conf ServerName localhost:80 centos设置开机启动 cp /usr/local/apache/bin/apachectl /etc/init.d/httpd 编辑完成后,保存退出,执行下列命令: chkconfig httpd on [如果出现 service httpd does not support chkconfig ,的情况.. 解決方法是vi /etc/init.d/httpd,在第二行加入以下兩句,也就是#!/bin/sh后面,主要不要删除#号 # chkconfig: 2345 10 90 # description: Activates/Deactivates Apache Web Server ubuntu设置开机启动 ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd update-rc.d -f httpd defaults 然后启动apache 2.4 service httpd start
先安装必须的组件 centos yum install libxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel freetype freetype-devel libpng libpng-devel libjpeg libjpeg-devel ubuntu apt-get install libxml2 libxml2-dev libbz2-dev libcurl3-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev libfreetype6 libfreetype6-dev libmcrypt4 libmcrypt-dev 装libmcrypt wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz tar libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make make install 开始安装PHP 5.4了 wget http://cn2.php.net/distributions/php-5.4.15.tar.gz tar zxvf php-5.4.15.tar.gz cd php-5.4.15 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --with-mysqli --with-pdo-mysql --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-freetype-dir --with-libxml-dir --with-mcrypt --with-curl --with-xmlrpc --with-gettext --with-bz2 --with-zlib --with-mhash --enable-mbstring --enable-calendar --enable-ftp --enable-xml --enable-sockets --enable-soap --enable-exif --enable-zip --enable-gd-native-ttf make make install configure里要按自己的实际情况装,我装的这些可以满足绝大部分php程序了。 复制配置文件 cp /root/php-5.4.15/php.ini-development /usr/local/php/lib/php.ini 修改配置文件的这两行,时区和邮件发送 date.timezone = Asia/Chongqing sendmail_path = /usr/sbin/sendmail -t -i 当然你服务器要有sendmail,没有的话yum install sendmail / sudo apt-get install sendmail 现在要修改apache的配置文件让它支持PHP了 vi /usr/local/apache/conf/httpd.conf 下面这行装PHP的时候就自动加上了,在那一堆LoadModule后面,没加上的话自己加 LoadModule php5_module modules/libphp5.so 加入下面三行,这种写法是2.2以后的,网上的老写法也可以 <FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> 修改下面三行加上index.php,让apache可以找到php的首页文件 <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> 重启apache service httpd restart 现在测试PHP是否正常,apache默认的网站在 /usr/local/apache/htdocs 里,建一个PHP文件 vi /usr/local/apache/htdocs/php.php PHP: <?php phpinfo(); ?> 然后输入http://ip地址/php.php 测试是否成功。