所需资料:
apr-1.5.2.tar.gz、
apr-util-1.5.4.tar.gz、
pcre-8.36.tar.gz、
httpd-2.4.25.tar.gz、
libxml2-2.7.4.tar.gz
php-5.6.30.tar.gz
如果要按照下面安装,请首先将上述文件都上传至/usr/local
一、安装Apache安装依赖环境(为Apache准备)
第一步:安装apr-1.5.2.tar.gz
[root@localhost local]# mkdir -p apr
[root@localhost local]# tar -zxf apr-1.5.2.tar.gz
[root@localhost local]# cd apr-1.5.2
[root@yahoo apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@yahoo apr-1.5.2]# make
[root@yahoo apr-1.5.2]# make install
第二步:安装apr-util-1.5.4.tar.gz
[root@localhost local]# mkdir -p apr-util
[root@localhost local]# tar -zxf apr-util-1.5.4.tar.gz
[root@localhost local]# cd apr-util-1.5.4
[root@yahoo apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
[root@yahoo apr-util-1.5.4]# make
[root@yahoo apr-util-1.5.4]# make install
第三步:安装pcre-8.36.tar.gz
[root@localhost local]# mkdir -p pcre
[root@localhost local]# tar -zxf pcre-8.36.tar.gz
[root@localhost local]# cd pcre-8.36
[root@yahoo pcre-8.36]# ./configure --prefix=/usr/local/pcre
[root@yahoo pcre-8.36]# make
[root@yahoo pcre-8.36]# make install
注:在安装PCRE时可能会出现:configure: error:You need a C++ compiler for C++ support.
通过下面的方式解决
(1)命令:sudo apt-get install gcc;
(2)命令:sudo apt-get install g++;
二、安装Apache
1、安装
[root@localhost local]# mkdir -p /usr/local/apache2
[root@localhost local]# tar zxvf httpd-2.4.25.tar.gz
[root@localhost local]# cd httpd-2.4.25
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/apache2--with-pcre=/usr/local/pcre --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util
[root@localhost httpd-2.4.25]# make
[root@localhost httpd-2.4.25]# make install
[root@localhost httpd-2.4.25]# /usr/local/apache2/bin/apachectlstart
用浏览器访问http://localhost,看到It works!,说明CentOS Apache安装成功了,恭喜您!
2.启动
第一种方法[root@localhostapache2]# /usr/local/apache2/bin/apachectl start 一定要是绝对路径
第二种方法[root@localhostapache2]#service httpd start
第二种方法[root@localhostapache2]#/etc/init.d/httpd start
3、配置apache,最后修改httpd.conf,使apache能使用php
增加如下参数
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
AddType image/x-icon .ico
DirectoryIndex index.php index.html index.html.var
4、安装出现的问题
(1)configure: error: no acceptable cc foundin $PATH
解决办法:yum install gcc gcc-c++
(2)configure: error: APR not found. Pleaseread the documentation.
解决方法:安装Apache的关联软件
如上安装apr-1.4.6.tar.gz
(3)configure: error: APR-util not found.Please read the documentation
解决方法:安装apr-util
如上安装apr-util-1.5.1.tar.gz
(4)configure: error: APR version 1.3.0 orlater is required
主要是因为apr版本过低造成的,应该卸载相关旧版本
(5)启动时报错:
AH00558: httpd: Could not reliably determine the server's fully qualifieddomain name, using 127.0.0.1. Set the 'ServerName' directive globally tosuppress this message
解救办法:绝对路径即可:/usr/local/apache2/bin/apachectlstart
要想彻底不显示此行解决方法:
apache/conf/httpd.conf
首先找到ServerName(约213行),将其设置为localhost:80,并将前面的井号删除,虽然这一步如果不修改的话也可以正常运行,但启动Apache服务时会有一条烦人的提示(AH00558: httpd.exe: Could not reliably determine the server'sfully qualified do main name, using fe80::fc76:abca:e24b:d490. Set the'ServerName' directive globally to suppress this message)
(6)安装完apache时,访问时Index of /,为什么不是it works
让别人知道你的网站目录结构直接查看你目录下的所有文件是很危险的一个事情。
下面介绍解决方法
apache/conf/httpd.conf
找到:
Options indexes FollowSymLinks
改为:
Options FollowSymLinks
当直接访问某个目录时显示下图就表明设置成功了。
(7)重启apache时,报:DocumentRoot must be a directory
原因:apache/confi/httpd.conf里面有DocumentRoot配置文件,但实际目录中又没有这个目录,注释此配置即可。
(8)[root@localhost conf]#/usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fullyqualified domain name, using localhost.localdomain. Set the 'ServerName'directive globally to suppress this message
(98)Address already in use: AH00072: make_sock: could not bind to address[::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
解决方法:apache2/conf/httpd.conf Listener 80改为其它的端口号即可。
5、重要配置文件目录
/etc/httpd/conf/httpd.conf 最主要的配置文件
/usr/lib/httpd/modules:apache 支持很多的模块,所以你想要使用的模块默认都放置在此目录
/var/log/httpdapache默认的log
/var/www/html cenos默认的首页所在目录
三、安装php安装环境依赖
将下载的libxml2-2.7.4.tar.gz文件上传至/usr/local
[root@vm15 local]# mkdir -p libxml2
[root@vm15 local]# tar -zxvf libxml2-2.7.4.tar.gz
[root@vm15 local]# cd libxml2-2.7.4
[root@vm15 libxml2-2.7.4]# ./configure --prefix=/usr/local/libxml2
[root@vm15 libxml2-2.7.4]# make
[root@vm15 libxml2-2.7.4]# make install
如果安装成功以后,在/usr/local/libxml2/目录下将生成bin、include、lib和share四个目录。在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上"--with-libxml-dir=/usr/local/libxml2"选项,用于指定安装libxml2库文件的位置。
四、安装php
1、安装php
将下载的php-5.6.30.tar.gz文件上传至/usr/local
[root@vm15 local]# mkdir -p php
[root@vm15 local]# tar -zxvf php-5.6.30.tar.gz
[root@vm15 local]# cd php-5.6.30
[root@vm15 php-5.6.30]#./configure --prefix=/usr/local/php --with-mysql--with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2
出现以下信息表示编译成功
..
checking for external oniguruma... no
checking for mcrypt support... no
checking for MSSQL support via FreeTDS... no
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket... no
configure: error: Cannot find MySQL header files under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!
creating libtool
appending configuration tag "CXX" to libtool
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for usingPHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
[root@vm15php-5.6.3]#make
[root@vm15php-5.6.3]#make install
安装成功。
2、配置php
配置php.ini,只需要把php-5.6.3安装包中的php.ini-production拷贝到/usr/local/php/lib/下:
[root@vm15 php-5.6.3]#cp php.ini-production /usr/local/php/lib/php.ini
注:cp php.ini-production /usr/local/php/lib/php.ini是一个操作
3、重启Apache
(一定要重启)
4、测试php是否成功安装
写一个php测试页info.php,放到/usr/local/apache2/htdocs中。
<?php
phpinfo();
?>;
在浏览器中输入:服务器地址/info.php。通过phpinfo()可以查看很多信息,比如php.ini的存放路径,以及所有扩展组件等,很强大。
如果能正常显示出php的信息,则说明Apche+Mysql+PHP安装成功!