Home > php教程 > php手册 > 为Mac自带的Apache配置PHP和虚拟机,macapache

为Mac自带的Apache配置PHP和虚拟机,macapache

WBOY
Release: 2016-06-13 08:47:49
Original
1143 people have browsed it

为Mac自带的Apache配置PHP和虚拟机,macapache

操作系统:os x 10.11.2

1、启动apache

打开终端(terminal),输入命令:sudo apachectl -k start ;

在浏览器地址栏中输入:http://localhost,显示如下信息则apache正常启动

 

 

apache相关命令:

启动:sudo apachectl start

停止:sudo apachectl stop

重启:sudo apachectl restart

查看版本号:sudo apachectl -v
Copy after login

2、添加PHP模块

在终端中输入命令:sudo vi /etc/apache2/httpd.conf ,打开httpd.conf

去掉PHP模块前面的注释 '#',重启apache,php添加成功

3、配置‘mysites’虚拟机

1.在终端输入命令:mkdir /Users/你的用户名/Sites ,添加此文件夹做为'mysites'虚拟机的物理存储位置。

2.打开httpd.config,去掉"# Include /private/etc/apache2/extra/httpd-vhosts.conf"前面的'#'。

3.选择 DocumentRoot "/Library/WebServer/Documents" "/Library/WebServer/Documents"> ... 之间的内容,复制这些内容到它的下方;修改黄色区域修改为 "/Users/你的用户名/Sites",保存退出。

在终端输入命令:sudo vi /etc/apache2/extra/httpd-vhosts.conf ,打开httpd-vhosts.conf。

注释两个默认的虚拟机,在每一行前面加'#'

接下来,添加如下代码,保存退出,重启apache

# 'localhost'虚拟机
<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/localhost-error_log"
    CustomLog "/private/var/log/apache2/localhost-access_log" common 
</VirtualHost>

# 'mysites'虚拟机
<VirtualHost *:80>
    DocumentRoot "/Users/你的用户名/Sites"
    ServerName mysites
    ErrorLog "/private/var/log/apache2/mysites-error_log"
    CustomLog "/private/var/log/apache2/mysites-access_log" common 
</VirtualHost>
Copy after login

 

在终端输入命令: sudo vi /etc/hosts ,添加 "127.0.0.1    mysites",保存退出

在终端输入命令:sudo vi /Users/你的用户名/Sites/info.php ,添加 "" ,保存退出

在浏览器中输入  http://mysites/info.php

 

到此结束,谢谢阅读!

浊水轻舟于2016.1.12写

参考文档:http://www.cnblogs.com/snandy/archive/2012/11/13/2765381.html

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template