Macbook PHP环境搭建

作者:LoveEmperor-王子様

这里主要讲解注意事项与坑

1.环境搭建

Mac自带Apache PHP

(1)所以你先开启它,就可以用

查看版本: sudo apachectl -v
开启Apache: sudo apachectl start  重启:sudo apachectl restart 
(2)配置PHP
环境默认目录:
Macbook PHP环境搭建_第1张图片
你可以在此目录下新建一个PHP文件,如test.php,用sudo vim操作
用localhost/test.php是可以访问的
。。。。。。
但这是root下,
我们应该切换到用户开发目录下,(不能是桌面,大坑坑你)
(3.更改PHP运行目录)
编辑Apache的配置文件,终端输入:
sudo vi /etc/apache2/httpd.conf

取消它的注释(#)LoadModule php7_module libexec/apache2/libphp7.so

LoadModule userdir_module libexec/apache2/mod_userdir.so



文件配置修改如下列

"/Users/xwz/PhpstormProjects"文件路径:非桌面文件

#new paths

    #AllowOverride none

    AllowOverride All

    #Require all denied

    Require all granted

    Allow from all

    Options FollowSymLinks




#DocumentRoot "/Library/WebServer/Documents"

DocumentRoot "/Users/xwz/PhpstormProjects"

#

    #

    # 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

    Options FollowSymLinks Multiviews Indexes

    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

    AllowOverride All


    #

    # Controls who can get stuff from this server.

    #

    Require all granted



#

    #AllowOverride None

    AllowOverride All

    #Options None

    #Options Indexes MultiViews

    Options Indexes FollowSymLinks

    Require all granted

    Allow from all

    Allow from 127.0.0.1

    Order Deny,Allow



反复认真读httpd.conf这个文件,注意看注释;




2.列坑

(1)forbidden 。。。。。

You don’t have permission to access / on this server

Server unable to read htaccess file, denying access to be safe

httpd.conf配置不对,可能文件路径不对,或文件是桌面文件

(2)URL 不在服务内,

要新建默认的index.php文件;

可以同目录下新建HTML文件运行试试;非点浏览器运行





有些忘了。。。

待补充




效果如下:


Macbook PHP环境搭建_第2张图片



Macbook PHP环境搭建_第3张图片




你可能感兴趣的:(PHP)