美文网首页
Mac下PHP环境配置

Mac下PHP环境配置

作者: 和谐共处 | 来源:发表于2018-10-08 12:24 被阅读12次

Mac下httpd+php环境配置

Mac下默认配置了apache2使用默认的apache-httpd来完成配置
apache2的安装目录如下:

/etc/apache2

修改httpd.conf文件及httpd-vhosts.conf文件

文件位置:

/etc/apache2/httpd.conf

配置如下:

  • 加载php模块
#这里解注释
#LoadModule php7_module libexec/apache2/libphp7.so
LoadModule php7_module libexec/apache2/libphp7.so
  • 配置ServerName
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80 
#这里配置与httpd-vhosts.conf中ServerName配置要一致
ServerName locahost:80
  • 修改默认配置目录
#这里注释的是默认的配置
# DocumentRoot "/Library/WebServer/Documents"
# <Directory "/Library/WebServer/Documents">
DocumentRoot "/Users/hqmac/HqPHP/HqSites"
<Directory "/Users/hqmac/HqPHP/HqSites">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None
    #
    # Controls who can get stuff from this server.
    #
    Require all granted
    Options Indexes FollowSymLinks Includes ExecCGI
    Allow from all
</Directory>

  • 设置虚拟目录
    先在httpd.conf修改如下,在修改httpd-vhosts.conf文件
#这里解注释
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf

httpd-vhosts.conf文件位置:

/etc/apache2/extra/httpd-vhosts.conf

修改如下:

#添加一个VirtualHost标签,
#DocumentRoot的目录位置和httpd.conf中DocumentRoot
#配置的一致
# ServerName 你的服务器域名可以写成localhost
<VirtualHost *:80>
   DocumentRoot "/Users/hqmac/HqPHP/HqSites"
   #ServerName hqsite.com
   ServerName  localhost
   ErrorLog "/private/var/log/apache2/mysites-error_log"
   CustomLog "/private/var/log/apache2/mysites-access_log" common
</VirtualHost>

检查配置命令

#这个命令将会显示 Apache 是如何解析配置文件的。
#仔细检查 IP 地址与服务器名称可能会帮助你发现配置错误

httpd -S 

开启服务测试

在你的自定义目录下添加index.php

<?php
echo 'Hello PHP';
phpinfo();
?>

服务器操作命令

#开启
sudo apachectl start
#关闭
sudo apachectl stop
#重启
sudo apachectl restart

访问http://localhost:80

php.png

相关文章

网友评论

      本文标题:Mac下PHP环境配置

      本文链接:https://www.haomeiwen.com/subject/fdgdaftx.html