网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

LAMP之四PHP&APache之间的配置

用windows 主机通过 IP 地址访问已经安装了Apache 的主机,网页会反馈

创新互联公司-专业网站定制、快速模板网站建设、高性价比克什克腾网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式克什克腾网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖克什克腾地区。费用合理售后完善,10多年实体公司更值得信赖。

It works!

LAMP之四  PHP & APache 之间的配置

[root@OBird ~]# vim /usr/local/apache2/conf/httpd.conf 查看Apache 配置文件

DocumentRoot "/usr/local/apache2/htdocs"  这里保存网页访问的目录。“It works!”

[root@OBird htdocs]# vim 1.txt

在txt文本里写上一些内容,通过 http://192.168.31.170/1.txt  (后面补充的实验截图,虚机IP不一样) 访问,就可以看到里面的内容。

LAMP之四  PHP & APache 之间的配置

LAMP 是支持PHP ,那么我们可以写一简单的php 的文件。

[root@OBird htdocs]# vim 2.php  这是一个简单的php 脚本。

[root@OBird htdocs]# cat 2.php

echo 1212121212;

?>

通过网页访问 ,显示的结果并没有真正的解析出来

http://192.168.31.170/2.php

以下是显示的结果:

此时说明Apache 此时还不支持解析 PHP.需要去编辑配置文件。

LAMP之四  PHP & APache 之间的配置

如果是正真的解析应该是这样

[root@OBird htdocs]# /usr/local/php/bin/php 2.php

1212121212[root@OBird htdocs]#                     只显示一行“1212121212”

编译配置文件
vim /usr/local/apache2/conf/httpd.conf

找到:

AddType application/x-gzip .gz .tgz

在该行下面添加:

LAMP之四  PHP & APache 之间的配置

LAMP之四  PHP & APache 之间的配置



找到


    DirectoryIndex index.html 


改为下面


    DirectoryIndex index.html index.php


配置文件更改完以后检测一下配置文件有没有问题
[root@OBird htdocs]# /usr/local/apache2/bin/apachectl -t
Syntax OK

然后重新加载 Apache 

[root@OBird htdocs]# /usr/local/apache2/bin/apachectl graceful

此时再通过网页访问 http://192.168.31.170/2.php

可以看到2.php 的正确输出。

LAMP之四  PHP & APache 之间的配置

我们可以再多做一些测试,编辑一个info.php,这是php 的一个函数。

[root@OBird htdocs]# vim info.php

[root@OBird htdocs]# cat info.php

phpinfo();

?>

通过网页访问可以看一个页面,其实就是PHP 的信息。

http://192.168.31.170/info.php


LAMP之四  PHP & APache 之间的配置

[root@OBird htdocs]# /usr/local/php/bin/php -i |less  也可以达到上面的效果

可以查看到是怎么编译 PHP 。

PHP 可以做到,Apache 也同样可以

[root@OBird htdocs]# cat /usr/local/apache2/build/config.nice

#! /bin/sh

#

# Created by configure

"./configure" \

"--prefix=/usr/local/apache2" \

"--with-included-apr" \

"--enable-so" \

"--enable-deflate=shared" \

"--enable-expires=shared" \

"--enable-rewrite=shared" \

"--with-pcre" \

"$@"

同样的MySQL 也可查看它的编译参数

[root@OBird htdocs]# cat /usr/local/mysql/bin/mysqlbug  |grep -i config

# This is set by configure

CONFIGURE_LINE="./configure  '--prefix=/usr/local/mysql' '--localstatedir=/usr/local/mysql/data' '--libexecdir=/usr/local/mysql/bin' '--with-comment=MySQL Community Server (GPL)' '--with-server-suffix=' '--enable-thread-safe-client' '--enable-local-infile' '--with-pic' '--with-fast-mutexes' '--with-client-ldflags=-static' '--with-mysqld-ldflags=-static' '--with-zlib-dir=bundled' '--with-big-tables' '--with-ssl' '--with-readline' '--with-embedded-server' '--with-partition' '--with-innodb' '--without-ndbcluster' '--with-archive-storage-engine' '--with-blackhole-storage-engine' '--with-csv-storage-engine' '--without-example-storage-engine' '--with-federated-storage-engine' '--with-extra-charsets=complex' 'CC=/usr/local/gcc-4.3.2/bin/gcc -static-libgcc' 'CFLAGS=-g -O3' 'CXX=/usr/local/gcc-4.3.2/bin/gcc -static-libgcc' 'CXXFLAGS=-g -O3'"

`test -n "$CONFIGURE_LINE"  && echo "Configure command: $CONFIGURE_LINE"`

[root@OBird htdocs]#

PHP 的目录下没有配置文件

 [root@OBird htdocs]# ls /usr/local/php/etc

 pear.conf

可以去拷贝一个样例过来

[root@OBird htdocs]# cp /usr/local/src/php-7.0.8/php.ini-production /usr/local/php/etc/php.ini

[root@OBird htdocs]# /usr/local/apache2/bin/apachectl graceful  重新加载PHP,再重新刷新网页

可以看到 php 加载文件的路径Loaded Configuration File

Configuration File (php.ini) Path/usr/local/php/etc
Loaded Configuration File/usr/local/php/etc/php.ini 
LAMP之四  PHP & APache 之间的配置

也可以用命令查看源码

[root@OBird htdocs]# curl 192.168.31.170/info.php  输出看到的就是网页版的源码。


网站名称:LAMP之四PHP&APache之间的配置
链接地址:http://bjjierui.cn/article/igscch.html

其他资讯