mac上brew安装Apache+MySQL+PHP7

MySQL和PHP很好装,装好可以直接用

brew install [email protected]
brew install [email protected]

vim ~/.bash_profile可以配置php环境变量

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"

安装配置Apache稍许麻烦一些

brew install httpd

然后配置(去掉注释或添加注释)

Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

LoadModule php7_module /usr/local/Cellar/[email protected]/7.2.18/lib/httpd/modules/libphp7.so

AddHandler application/x-httpd-php .php

ServerName localhost:80

Listen 80

#伪静态配置
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

在extra/httpd-vhosts.conf配置虚拟主机


    ServerName xxx
    DocumentRoot xxx
    
        DirectoryIndex index.html index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    

    ErrorLog "/usr/local/var/log/httpd/error_log"
    CustomLog "/usr/local/var/log/httpd/access_log" common

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1$1 [L,R=permanent]

    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-f
    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-d
    RewriteRule "^" "/index.php" [L]

最后重启Apache

sudo apachectl restart

Apache开机自启

brew services start httpd

你可能感兴趣的:(mac上brew安装Apache+MySQL+PHP7)