美文网首页PHP
mac上brew安装Apache+MySQL+PHP7

mac上brew安装Apache+MySQL+PHP7

作者: misaka去年夏天 | 来源:发表于2019-05-21 14:55 被阅读0次

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

brew install mysql@5.6
brew install php@7.2

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

export PATH="/usr/local/opt/php@7.2/bin:$PATH"
export PATH="/usr/local/opt/php@7.2/sbin:$PATH"

安装配置Apache稍许麻烦一些

brew install httpd

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

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

LoadModule php7_module /usr/local/Cellar/php@7.2/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配置虚拟主机

<VirtualHost *:80>
    ServerName xxx
    DocumentRoot xxx
    <Directory "xxx">
        DirectoryIndex index.html index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    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]
</VirtualHost>

最后重启Apache

sudo apachectl restart

Apache开机自启

brew services start httpd

相关文章

网友评论

    本文标题:mac上brew安装Apache+MySQL+PHP7

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