Mac10.13.6下使用homebrew安装PHP+Apache开发环境

提前安装好homebrew

详见

删除Mac自带的Apache

停掉Apache服务

sudo apachectl stop

删除Mac自带的Apache

sudo rm /usr/sbin/httpd 
sudo rm -r /etc/apache2/

安装Apache

使用homebrew下载Apache

brew install apache2

保留下载后的使用提示

The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To have launchd start httpd now and restart at login:
  brew services start httpd
Or, if you don't want/need a background service you can just run:
  apachectl start

修改Apache配置文件

打开配置文件

sudo vim /usr/local/etc/httpd/httpd.conf

修改以下几项

修改端口

Listen 8080

修改服务名称

ServerName localhost:8080

修改访问权限

<Directory />
    AllowOverride None
    Require all denied
</Directory>

改为

<Directory />
    AllowOverride All
    Require all granted
</Directory>

修改网站访问目录

DocumentRoot "/var/www"
<Directory "/var/www">

启动Apache sudo apachectl start,打开浏览器输入localhost:8080将会看到 “It works!”,证明启动成功。

安装PHP5.6

下载php5.6

brew install php@5.6

保留下载后的使用提示

To enable PHP in Apache add the following to httpd.conf and restart Apache:
   LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so

   <FilesMatch \.php$>
       SetHandler application/x-httpd-php
   </FilesMatch>

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /usr/local/etc/php/5.6/

php@5.6 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have php@5.6 first in your PATH run:
  echo 'export PATH="/usr/local/opt/php@5.6/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/php@5.6/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@5.6 you may need to set:
  export LDFLAGS="-L/usr/local/opt/php@5.6/lib"
  export CPPFLAGS="-I/usr/local/opt/php@5.6/include"


To have launchd start php@5.6 now and restart at login:
  brew services start php@5.6
Or, if you don't want/need a background service you can just run:
  php-fpm

如上所述,修改httpd.confzshrc,加入环境变量,并开启php5.6和php-fpm
重启Apache,创建info.php,看是否成功

配置Apache多站点模式

打开配置文件

sudo vim /usr/local/etc/httpd/httpd.conf

#Include /usr/local/etc/httpd/extra/httpd-vhosts.conf前面注释去掉

# Virtual hosts 
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

修改httpd-vhosts.conf

<VirtualHost *:8080>
    ServerAdmin localhost
    DocumentRoot "/var/www/"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "/usr/local/var/log/httpd/dummy-host.example.com-error_log"
    CustomLog "/usr/local/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:8080>
    ServerAdmin beibei-test.com
    DocumentRoot "/var/www/idvert/beibei"
    ServerName beibei-test.com
</VirtualHost>

修改hosts,在其中加入127.0.0.1 beibei-test.com

sudo vim /etc/hosts

打开浏览器,输入beibei-test.com:8080即可看到配置好的网站

Mac下安装PHP开发环境

最近有点闲钱买Mac了,便果断换了个rmbp当工作本,折腾了小半天,终于把
Mac下PHP的开发环境搭好了,用的是nginx+php-fpm,特地记录一下如何在Mac(版本10.11.3)下从零开始安装PHP开发环境

在github上使用hexo搭建博客

前言

第一次萌生出写博客的想法还是大二那会,那时候技术还只是一般般,遂在博客园申请了一个帐号,P了张首页图,便开始了我的博客之旅。—— 短暂的第一个博客
到了大三下学期,PHP学得差不多了,心想作为一名未来的程序员,没有一个个人技术博客怎么行!找来wordpress在SEA上面搭建了个博客,七搞八搞,加了很多插件和特效,看起来很牛逼的样子,然而陆陆续续用了一年也不想写了。—— 难产的第二个博客

现在工作已有一年了,在工作之余,业余生活也渐渐丰富了起来,除了技术之外,总有一点生活感悟想写下来,但又苦于找不到写字的地方。直到有一天在知乎上看到有人说能在github上写博客,顿时惊为天人!一顿了解之下,立马拾起许久不用的github帐号,花了一天时间搭好了这个博客。Hexo给我的印象就是:简洁、快捷、符合程序员的操作风格。特别是还有一种跻身于世界大牛之间的错觉,~( ̄▽ ̄~)(~ ̄▽ ̄)~