CentOS搭建PHP+Apache环境+apache虚拟主机配置+apache非停状态删日志后异常+php开启openssl+php日志记录

来源:互联网 发布:php开发微信公众平台 编辑:程序博客网 时间:2024/06/16 15:57

下载文件

1、php下载地址:http://php.net/downloads.php  版本:php-5.6.3.tar.gz

2、libxml2下载地址:http://download.chinaunix.net/download/0007000/6095.shtml  版本:libxml2-2.7.4.tar.gz

3、apache2下载地址:http://httpd.apache.org/  版本:httpd-2.4.10.tar.gz

4、apr与apr-util下载地址:http://apr.apache.org   版本:apr-1.5.1.tar.gz / apr-util-1.5.4.tar.gz

5、pcre下载地址:http://sourceforge.net/projects/pcre/files/pcre/  版本:pcre-8.36.tar.gz

说明:

apache安装之前,需要安装APR、APR-Util和PCRE依赖包,因为apache是依赖于它们的。

安装php前需要有确保已经安装libxml2,

先检查是否安装了Apache 

如通是通过rpm包安装的话直接用下面的命令:rpm -q httpd

也可以使用如下两种方法:

httpd -v     

apachectl  -v

如果已安装了Apache,则会显示

一。准备环境
1.安装gcc
[root@localhost /]# yum install gcc gcc-c++

2.安装apr,apr-util
下载apr-1.4.6.tar.gz与apr-util-1.5.1.tar.gz,地址:http://apr.apache.org   ,上传至/usr/local,安装目录分别为/usr/local/apr 与/usr/local/apr-util

a.安装apr-1.4.6.tar.gz
[root@localhost local]# mkdir -p apr
[root@localhost local]# tar -zxf apr-1.4.6.tar.gz
[root@localhost local]# cd apr-1.4.6
[root@yahoo apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@yahoo apr-1.4.6]# make
[root@yahoo apr-1.4.6]# make install

b.安装apr-util-1.5.1.tar.gz
[root@localhost local]# mkdir -p apr-util
[root@localhost local]# tar -zxf apr-util-1.5.1.tar.gz
[root@localhost local]# cd apr-util-1.5.1
[root@yahoo apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
[root@yahoo apr-util-1.5.1]# make
[root@yahoo apr-util-1.5.1]# make install

3.安装pcre-8.20.tar.gz
下载地址:http://sourceforge.net/projects/pcre/files/pcre/ ,上传至/usr/local,安装目录为/usr/local/pcre
[root@localhost local]# mkdir -p pcre
[root@localhost local]# tar -zxf pcre-8.20.tar.gz
[root@localhost local]# cd pcre-8.20
[root@yahoo pcre-8.20]# ./configure --prefix=/usr/local/pcre
[root@yahoo pcre-8.20]# make
[root@yahoo pcre-8.20]# make install


二。安装apache
1.下载httpd-2.4.3.tar.gz,地址是:http://httpd.apache.org/ ,上传至/usr/local,安装目录为/usr/local/apache2

2.安装
[root@localhost local]# mkdir -p /usr/local/apache2
[root@localhost local]# tar zxvf httpd-2.4.3.tar.gz
[root@localhost local]# cd httpd-2.4.3
[root@localhost httpd-2.4.3]# ./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.3]# make
[root@localhost httpd-2.4.3]# make install

[root@localhost httpd-2.4.3]# /usr/local/apache2/bin/apachectl start
用浏览器访问http://localhost,看到It works!,说明CentOS Apache安装成功了,恭喜您!

3.启动
第一种方法[root@localhost apache2]# /usr/local/apache2/bin/apachectl start     一定要是绝对路径

第二种方法[root@localhost apache2]#service httpd start

第二种方法[root@localhost apache2]#/etc/init.d/httpd start

三。安装出现的问题
1.configure: error: no acceptable cc found in $PATH
解决办法:yum install gcc gcc-c++

2.configure: error: APR not found. Please read 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 or later is required
主要是因为apr版本过低造成的,应该卸载相关旧版本

5. 启动时报错:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
解救办法:绝对路径即可:/usr/local/apache2/bin/apachectl start

要想彻底不显示此行解决方法:

apache/conf/httpd.conf

首先找到ServerName(约213行),将其设置为localhost:80,并将前面的井号删除,虽然这一步如果不修改的话也可以正常运行,但启动Apache服务时会有一条烦人的提示(AH00558: httpd.exe: Could not reliably determine the server's fully 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 fully qualified 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 address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs

解决方法:apache2/conf/httpd.conf   Listener 80改为其它的端口号即可。

重要配置文件目录

/etc/httpd/conf/httpd.conf    最主要的配置文件
/usr/lib/httpd/modules:apache  支持很多的模块,所以你想要使用的模块默认都放置在此目录
/var/log/httpd          apache默认的log
/var/www/html          cenos默认的首页所在目录

四、安装libxml2 (安装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

将下载的php-5.6.3.tar.gz文件上传至/usr/local

[root@vm15 local]# mkdir -p php
[root@vm15 local]# tar -zxvf php-5.6.3.tar.gz 
[root@vm15 local]# cd php-5.6.3

[root@vm15 php-5.6.3]#./configure --prefix=/usr/local/php --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2

上面 --with-mysql一定要小写,这个博客也是醉了,怎么改显示都是大写红字。

出现以下信息表示编译成功

..
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 using PHP.

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@vm15 php-5.6.3]#make

[root@vm15 php-5.6.3]#make install

安装成功。

六、配置php

1、配置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

2、配置 httpd.conf 让apache支持PHP:

# vi /usr/local/apache/conf/httpd.conf

找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容

  AddType application/x-httpd-php .php      (.前面有空格)

  AddType application/x-httpd-php-source .phps        (.前面有空格)

3、在DirectoryIndex增加 index.php,以便Apache识别PHP格式的index

# vi /usr/local/apache/conf/httpd.conf

<IfModule dir_module>      DirectoryIndex index.html index.php  </IfModule> 

 

七、重启Apache

[root@vm15 mysql]#  /usr/local/apache2/bin/apachectl start

一定要重启

八、测试php是否成功安装

写一个php测试页info.php,放到/usr/local/apache2/htdocs中。

<?php 

 phpinfo(); 

?>; 

在浏览器中输入:服务器地址/info.php。通过phpinfo()可以查看很多信息,比如php.ini的存放路径,以及所有扩展组件等,很强大。

安装成功!

参考文献:

http://www.cnblogs.com/yangxia-test/p/4174372.html

http://www.cnblogs.com/yangxia-test/archive/2012/11/09/2762486.html

http://blog.csdn.net/charein/article/details/41408985

apache虚拟主机配置

一、修改httpd.conf

在httpd.conf中Listen 80下面增加一行,内容为:Listen 8080,即监听8080端口

打开appserv的安装目录,找到httpd.conf文件,分别去掉下面两行文字前面的#号。 

[plain] view plain copy
  1. #LoadModule vhost_alias_module modules/mod_vhost_alias.so  
去掉#意思是启用apache的虚拟主机功能。 

[plain] view plain copy
  1. #Include conf/extra/httpd-vhosts.conf  
去掉这一行的#意思是从conf/extra/httpd-vhosts.conf这个文件导入虚拟主机配置

二、修改httpd-vhosts.conf

打开该文件,看到以下类似内容。虚拟主机的配置也是参照以下内容配置。下面对该内容进行讲解

  1. <VirtualHost *:8080>  
  2.  ServerName fdipzone.demo.com  
  3.  DocumentRoot "/home/fdipzone/sites/www"  
  4.  DirectoryIndex index.html index.php  
  5.  ErrorLog "logs/fdipzone.demo.com-error_log"
  6.  CustomLog "logs/fdipzone.demo.com-access_log" common
  7.  <Directory "/home/fdipzone/sites/www">  
  8.   Options -Indexes +FollowSymlinks  
  9.   AllowOverride All  
  10.   Require all granted  
  11.  </Directory>  
  12.   
  13. </VirtualHost>  


apache非停状态删日志后异常。

没有正常停止的情况下,删除日志后,重启报错

(20014)Internal error: AH00058: Error retrieving pid file logs/httpd.pid

[root@localhost conf]# /usr/local/apache2/bin/apachectl -k restart
(20014)Internal error: AH00058: Error retrieving pid file logs/httpd.pid

AH00059: Remove it before continuing if it is corrupted.

由于不正当关闭服务造成的问题,删除  httpd.pid 

[root@localhost logs]# /usr/local/apache2/bin/apachectl -k restart
(20014)Internal error: AH00058: Error retrieving pid file logs/httpd.pid
AH00059: Remove it before continuing if it is corrupted.
[root@localhost logs]# ls
access_log  error_log  httpd.pid
[root@localhost logs]# rm -f httpd.pid 
[root@localhost logs]# /usr/local/apache2/bin/apachectl -k restart
httpd not running, trying to start
[root@localhost logs]# netstat -ant


php开启openssl的方法详解

php开启openssl的方法,大多数情况下openssl是没有开启的,要想启用需要进行下简单的设置:

windows下开启方法:

1: 首先检查php.ini中;extension=php_openssl.dll是否存在, 如果存在的话去掉前面的注释符‘;’, 如果不存在这行,那么添加extension=php_openssl.dll。

2: 讲php文件夹下的: php_openssl.dll, ssleay32.dll, libeay32.dll 3个文件拷贝到 WINDOWS\system32\ 文件夹下。

3:如果没有 php_openssl.dll ,点击下载 php_openssl.dll

下载下来有很多个php_openssl,找到你相应php版本下面的php_openssl。

查看php版本可以用如下代码:

<?phpphpinfo();?>

找到相应版本之后,按照上面讲的第二步来就可以了。

4: 重启apache或者iis

至此,openssl功能就开启了。

Linux下开启方法:

下面方案就以我的主机为例讲解为PHP添加openssl模块支持。

网上一些答案说要重新编译PHP,添加configure参数,增加openssl的支持。这里讲一个不需要重新编译的方法。

如果服务器上存在PHP安装包文件最好,如果已经删除,去下载和phpinfo页面显示版本一样的PHP安装文件,我这里是 php-5.5.7.tar.gz

用ssh工具连接到主机。

# 下载到/var/www/php5目录下cd /var/www/php5wget http://mirrors.sohu.com/php/php-5.5.7.tar.gz# 解压tar zxvf php-5.5.7.tar.gz# 进入PHP的openssl扩展模块目录cd php-5.5.7/ext/openssl//var/www/php5/bin/phpize # 这里为你自己的phpize路径,如果找不到,使用whereis phpize查找# 执行后,发现错误 无法找到config.m4 ,config0.m4就是config.m4。直接重命名mv config0.m4 config.m4/var/www/php5/bin/phpize./configure --with-openssl --with-php-config=/var/www/php5/bin/php-config #注意:这一步是在php-5.5.7/ext/openssl/目录下makemake install# 安装完成后,会返回一个.so文件(openssl.so)的目录。在此目录下把openssl.so 文件拷贝到你在php.ini 中指定的 extension_dir 下(在php.ini文件中查找:extension_dir =),openssl.so在我这里的目录是 var/www/php5/lib/php/extensions下。 (默认的话把openssl.so放到php.ini同级目录即可)# 编辑php.ini文件,在文件最后添加extension=openssl.so# 重启Apache即可/usr/local/apache2/bin/apachectl restart

好了,现在就成功添加openssl支持。

问题:如果报错Cannot find OpenSSL's <evp.h>

yum install openssl openssl-devel

php日志记录

需要在php.ini中修改的配置指令如下所示: 

1. error_reporting  =  E_ALL                   ;将会向PHP报告发生的每个错误   

2. display_errors = Off                            ;不显示 满足上条指令所定义规则的所有错误报告   

3. log_errors = On                             ;决定日志语句记录的位置   

4. log_errors_max_len = 1024                   ;设置每个日志项的最大长度   

5. error_log = syslog                          ;指定产生的错误报告写入操作系统的日志里  


阅读全文
1 0
原创粉丝点击