实验环境

uname -a

Linux tomato 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

步骤

安装

sudo apt-get update
sudo apt-get install php7. apache2 libapache2-mod-php7.0

修改配置

刚开始的时候我上网查询如何配置apache2和php,很多人都提到了“在httpd.conf中AddType和LoadModule”,然而我找了很久都没找到这个文件,其他各种答案也是没效果。可能这个httpd.conf要下载源码才有吧,用apt安装的没有。于是我去下载了源码,但又是一大堆的依赖包什么的,也是失败了。在图书馆搞了4个小时,感觉身体被掏空......

后来我从图书馆回到宿舍,平静了一下,打开了刚刚看过的配置文件:

cd /etc/apache2
less apache2.conf

我被注释里的目录数吸引了:

于是我认真地看了开头两页长的注释:

Summary of how the Apache 2 configuration works in Debian:

The Apache 2 web server configuration in Debian is quite different to
upstream's suggested way to configure the web server. This is because Debian's
default Apache2 installation attempts to make adding and removing modules,
virtual hosts, and extra configuration directives as flexible as possible, in
order to make automating the changes and administering the server as easy as
possible.

apache2在Debian中的配置不同,配置文件分成了几个文件。

apache2.conf is the main configuration file (this file). It puts the pieces
together by including all remaining configuration files when starting up the
web server

apache2.conf是主要的配置文件,将其他配置文件整合在一起。

Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
directories contain particular configuration snippets which manage modules,
global configuration fragments, or virtual host configurations,
respectively.

They are activated by symlinking available configuration files from their
respective *-available/ counterparts.

mods-enabled/、conf-enabled/和sites-enabled/这几个目录分别管理modules,
global configuration fragments和virtual host configurations。它们链接到相应的-available文件而起作用。

看到modules我马上就动了:

cd mods-available 
grep -d recurse "AddType"

mime.conf: # AddType allows you to add to or override the MIME configuration
mime.conf: #AddType application/x-gzip .tgz
mime.conf: AddType application/x-compress .Z
mime.conf: AddType application/x-gzip .gz .tgz
mime.conf: AddType application/x-bzip2 .bz2
mime.conf: AddType text/html .shtml
ssl.conf: AddType application/x-x509-ca-cert .crt
ssl.conf: AddType application/x-pkcs7-crl .crl

嘿嘿......

sudo vim mime.conf

在文件中定位到AddType的部分,加入这两行:

AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php

保存退出。再来找一下“LoadModule”的归处:

mime.load:LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
sudo vim mime.load

加入这一句:

LoadModule php7_module /usr/lib/apache2/modules/libphp7..so

重启apache2,使配置生效:

sudo service apache2 restart

测试

apache2的默认web根目录在/etc/apache2/sites-available/000-default.conf中设置:

DocumentRoot /var/www/html/

在该目录下添加测试文件info.php,内容为:

<?php
phpinfo();
?>

保存退出。

打开浏览器,在地址栏输入:

localhost/phpinfo.php

回车。成功跳出由php解释后的信息:

PHP logo
PHP Version 7.0.-0ubuntu0.16.04. System Linux tomato 4.4.--generic #-Ubuntu SMP Wed Jul :: UTC x86_64
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php/7.0/apache2
Loaded Configuration File /etc/php/7.0/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.0/apache2/conf.d
......

感动!

ubuntu下apache与php配置的更多相关文章

  1. [转]:Ubuntu 下Apache安装和配置

    [转]:Ubuntu 下Apache安装和配置_服务器应用_Linux公社-Linux系统门户网站  https://www.linuxidc.com/Linux/2013-06/85827.htm ...

  2. Ubuntu 下Apache安装和配置

    在Ubuntu上安装Apache,有两种方式:1 使用开发包的打包服务,例如使用apt-get命令:2 从源码构建Apache.本文章将详细描述这两种不同的安装方式. 方法一:使用开发包的打包服务—— ...

  3. Ubuntu 下Apache安装和配置2

    在Ubuntu上安装Apache,有两种方式:1 使用开发包的打包服务,例如使用apt-get命令:2 从源码构建Apache.本文章将详细描述这两种不同的安装方式. 方法一:使用开发包的打包服务—— ...

  4. Windows下Apache+mod_python+Django配置

    Windows下Apache+mod_python+Django配置 Apache 首先要安装Apache,我安装的版本是2.2.*: Python python肯定是要安装的,我安装的版本是2.5的 ...

  5. 分享:linux下apache服务器的配置和管理

    linux下apache服务器的配置和管理. 一.两个重要目录: Apache有两个重要的目录:1.配置目录/etc/httpd/conf:2.文档目录/var/www: 二.两种配置模式: Apac ...

  6. windows下apache+https环境配置

    windows下apache+https环境配置 转 https://www.cnblogs.com/sandaizi/p/7519370.html 1.修改配置文件conf/httpd.conf,去 ...

  7. ubuntu下安装mysql和配置远程访问

    ubuntu下安装mysql和配置远程访问   下载安装mysql sudo apt-get install mysql-client mysql-server 安装的时候会提示要设置root密码,如 ...

  8. [转载]Ubuntu下Git服务器安装与配置

    原文地址:Ubuntu下Git服务器安装与配置作者:F民抄 1. 安装 1.1 安装Git-Core: sudo apt-get install git-core 1.2 安装 Gitosis sud ...

  9. Linux下Apache虚拟主机配置

    Linux下Apache虚拟主机的三种配置.这样可以实现一台主机架构多个独立域名网站.其中基于域名的最为常见.性价比也最高.下面PHP程序员雷雪松详细的讲解下Linux下Apache虚拟主机配置的具体 ...

随机推荐

  1. 使用CSS为图片添加边框的几种方法

    css的应用十分广泛,即便用在图片的效果中也是方法多样,本文下面就介绍五种为图片添加特殊效果边框的CSS写法阴影效果 通过使用带有一些padding之的背景图来添加阴影效果. HTML <img ...

  2. Struts2的注解功能

    我们知道通常情况下,Struts2是通过struts.xml配置的.但是随着系统规模的加大我们需要配置的文件会比较大,虽然我们可以根据不同的系统功能将不同模块的配置文件单独书写,然后通过<inc ...

  3. 【转】设置SecureCRT会话的缓冲区大小

    原文网址:http://guanjianfeng.com/archives/1484 在使用SecureCRT操作设备时,默认的回滚行数为500行.可以通过打开[选项]->[会话选项]-> ...

  4. 【转】android中重复连接ble设备导致的连接后直接返回STATE_DISCONNECTED的解决办法---不错不错,重新连接需要花费很长的时间

    原文网址:http://bbs.eeworld.com.cn/thread-438571-1-1.html /*                         * 通过使用if(gatt==null ...

  5. 使用 virtualenv

    关于virtualenv的资料: http://virtualenv-chinese-docs.readthedocs.org/en/latest/ 用的python3,但是搭建 Robot Fram ...

  6. jxl对excel删除行

    简单记录下: package com.pingan; import java.io.File; import java.util.regex.Matcher; import java.util.reg ...

  7. bzoj4028: [HEOI2015]公约数数列

    Description 设计一个数据结构. 给定一个正整数数列 a_0, a_1, ..., a_{n - 1},你需要支持以下两种操作: 1. MODIFY id x: 将 a_{id} 修改为 x ...

  8. mybatis 关联对象mapper.xml的写法

    https://github.com/zfrHJ/mybaties/blob/master/mybaties/src/com/itheima/mybatits/mapper/OrdersMapperC ...

  9. Android下 scrollview的滚动停止事件的监听方法

    使用递归调用的方法,每隔5毫秒检查一下是否已经停止,如果已经停止,就拿到事件啦! 不扯蛋,直接上代码. scrollContent就是我的scrollview. [代码]java代码: ? 1 2 3 ...

  10. XMPPFrameWork IOS 开发(二)- xcode配置

    原始地址:XMPPFrameWork IOS 开发(二) 译文地址:   Getting started using XMPPFramework on iOS 介绍 ios上的XMPPFramewor ...