美文网首页
MAC搭建服务器环境

MAC搭建服务器环境

作者: TRYao | 来源:发表于2018-05-18 19:49 被阅读0次

在本地搭建服务器环境有很多方法,一开始我用的XAMPP。过程中发现这个软件比较大,占内存。后来发现一种更轻量的方法,分享给大家。

  1. 运行Apache
    Mac OS系统自带Apache、Nginx和PHP。在终端输入如下命令开启Apache:
//开启Apache
sudo apachectl start
//关闭Apache
sudo apachectl stop
//重启Apache
sudo apachectl restart
//查看Apache版本
sudo apachectl -v

开启后,可以通过浏览器访问:http://localhost,页面显示“It works” 表示已经成功。

  1. 备份文件
sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.bak
sudo cp etc/apache2/extra/httpd-vhosts.conf etc/apache2/extra/httpd-vhosts.conf.bak
  1. 配置PHP
    编辑Apache的配置文件,终端输入:
sudo vim /etc/apache2/httpd.conf

在文件里找到 #LoadModule php5_module libexec/apache2/libphp5.so 这一行,然后去掉前面的“#”号注释,输入 :wq 保存退出

重启Apache,使其生效

sudo apachectl restart
  1. 查看本地服务器路径
    此时服务器已经配置成功,目录在/Library/WebServer/Documents下,在终端输入以下命令进入
cd /Library/WebServer/Documents
ls

文件index.html.en就是访问http://localhost所看到的页面。

通过finder的前往文件夹命令,输入/Library/WebServer/Documents可直接看到本地服务器中的文件。

  1. 修改本地服务器路径
sudo vim etc/apache2/httpd.conf

输入/DocumentRoot查找服务器路径,按下 i 进入编辑模式
可以看到有两个路径/Library/WebServer/Documents 把他们都改成你自己项目文件夹的路径 ,重启服务器

sudo apachectl restart
  1. 打开Apache目录浏览功能
sudo /etc/apache2/extra/httpd-vhosts.conf 
//在<VirtualHost *:80>虚拟目录里设置以下内容
 <Directory "/Users/lax/site">
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Require all granted
</Directory>
sudo vim /etc/apache2/httpd.conf

Options FollowSymLinks Multiviews
AllowOverride None

Options Indexes  FollowSymLinks Multiviews
AllowOverride None

参考文章:MacBook搭建服务器环境

相关文章

网友评论

      本文标题:MAC搭建服务器环境

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