Mac下使用Homebrew安装apache+php+mysql

Mac下使用Homebrew安装apache+php+mysql

Mac下使用Homebrew安装apache+php+mysql

  1. 安装Command Line Tools

    $ xcode-select --install
  2. 安装Homebrew

    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. 安装apache&php

    $ brew install homebrew/apache/httpd24
    $ brew install php56 --with-apache
  4. 给apache配置php模块,在文件中写入

    $ vim /usr/local/etc/apache2/2.4/httpd.conf
    
    LoadModule php5_module        /usr/local/Cellar/php56/5.6.27_4/libexec/apache2/libphp5.so
    <IfModule mod_php5.c>
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
        <IfModule mod_dir.c>
            DirectoryIndex index.html index.php
        </IfModule>
    </IfModule>
  5. 配置php cli的php,在你的shell文件中写入,如果你用的是zsh
    $ vim ~/.zshrc
    export PATH="/usr/local/Cellar/php56/5.6.27_4/bin:$PATH"
  6. 配置虚拟目录,在文件中写入
    $ vim /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf
    <VirtualHost *:80>
    DocumentRoot "/usr/local/var/www/htdocs"
      ServerName localhost
      ErrorLog "/usr/local/var/log/apache2/localhost-error_log"
      CustomLog "/usr/local/var/log/apache2/localhost-access_log" common
    </VirtualHost>
  7. 重启apache
    $ sudo brew services restart httpd24
    --or
    sudo apachectl start
  8. 安装mysql
    $ brew install mysql
  9. 启动mysql
    $ mysql.server start

如果启动mysql失败,报错信息如下

ERROR! The server quit without updating PID file (/usr/local/var/mysql/localhost.pid).

执行

$ sudo chown -R 你的用户名 /usr/local/var/mysql


Tags

Back to top