Skip to content

Instantly share code, notes, and snippets.

@ejoful
Last active November 5, 2019 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejoful/8db029c093c329fac220914127b59b6f to your computer and use it in GitHub Desktop.
Save ejoful/8db029c093c329fac220914127b59b6f to your computer and use it in GitHub Desktop.
mac 安装lamp脚本
#!/bin/sh
## Upgrading MariaDB
## brew update
## brew upgrade mariadb
# 安装 Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
sudo chown -R $(whoami) /usr/local/share/man/man8
brew install cmake
# 安装 locate 命令
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
# 安装 mariadb
brew install mariadb
# 安装 phpmyadmin
brew install phpmyadmin
# 修改 mariadb 配置文件
sudo sed -i '.'$(date "+%Y-%m-%d")'.bak' \
-e "1i\\
# 添加编码配置\\
[mysql]\\
default-character-set=utf8\\
[mysqld]\\
# 设置时区为东八区\\
default-time-zone='+08:00'\\
" /usr/local/etc/my.cnf
# 启动 mariadb 并加入服务
brew services start mariadb
sudo apachectl -k stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
brew install php
brew services start php
brew install httpd24
brew services start httpd
current_user=$(whoami)
php7_module_path=$(find /usr/local/Cellar -name libphp7.so)
# 修改apache配置文件
sudo sed -i '.'$(date "+%Y-%m-%d")'.bak' \
-e "s/Listen 8080/Listen 80/g" \
-e 's#AllowOverride None#AllowOverride All#g' \
-e 's/#LoadModule rewrite_module/LoadModule rewrite_module/g' \
-e 's|#Include /usr/local/etc/httpd/extra/httpd-vhosts.conf|Include /usr/local/etc/httpd/extra/httpd-vhosts.conf|g' \
-e "s/User _www/User $current_user/g" \
-e 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' \
-e '/#ServerName www.example.com:8080/a\
ServerName localhost\
' \
-e '$a\
LoadModule php7_module '$php7_module_path'\
<FilesMatch \\.php$>\
SetHandler application/x-httpd-php\
</FilesMatch>\
Alias /phpmyadmin /usr/local/share/phpmyadmin\
<Directory /usr/local/share/phpmyadmin/>\
\ \ \ \ Options Indexes FollowSymLinks MultiViews\
\ \ \ \ AllowOverride All\
\ \ \ \ <IfModule mod_authz_core.c>\
\ \ \ \ \ \ \ \ Require all granted\
\ \ \ \ </IfModule>\
\ \ \ \ <IfModule !mod_authz_core.c>\
\ \ \ \ \ \ \ \ Order allow,deny\
\ \ \ \ \ \ \ \ Allow from all\
\ \ \ \ </IfModule>\
</Directory>\
# http://blog.sina.com.cn/s/blog_51ed54140100mlfe.html
# https://blog.csdn.net/u010444107/article/details/78849037
# https://my.oschina.net/ranxi/blog/1624075
# Sed使用的变量里含有转义字符的解决
# https://www.itranslater.com/qa/details/2113030174454318080\
# 注意php 7用户,将其添加到您的httpd.conf文件中:\
# PHP 7 specific configuration\
<IfModule php7_module>\
\ \ AddType application/x-httpd-php .php\
\ \ AddType application/x-httpd-php-source .phps\
\ \ <IfModule dir_module>\
\ \ \ \ DirectoryIndex index.html index.php\
\ \ </IfModule>
</IfModule>
\
\
' /usr/local/etc/httpd/httpd.conf
sudo sed -i '.'$(date "+%Y-%m-%d")'.bak' \
-e '$a\
<VirtualHost \*:80>\
\ \ \ \ DocumentRoot "/usr/local/var/www"\
\ \ \ \ ServerName localhost\
\ \ \ \ ErrorLog "/usr/local/var/log/httpd/localhost-error_log"\
\ \ \ \ CustomLog "/usr/local/var/log/httpd/localhost-access_log" common\
</VirtualHost>\
\
' /usr/local/etc/httpd/extra/httpd-vhosts.conf
# 设置文件权限
# 1.将您的用户添加到 _www。
sudo dscl . -append /Groups/_www GroupMembership $current_user
# 2.将 /usr/local/var/www 及其内容的组所有权更改到 _www 组
sudo chown -R $current_user:_www /usr/local/var/www
# 3.要添加组写入权限以及设置未来子目录上的组 ID,请更改 /usr/local/var/www 及其子目录的目录权限。
sudo chmod 2775 /usr/local/var/www
find /usr/local/var/www -type d -exec sudo chmod 2775 {} \;
# 4.要添加组写入权限,请递归地更改 /usr/local/var/www 及其子目录的文件权限:
find /usr/local/var/www -type f -exec sudo chmod 0664 {} \;
# 在用户主目录下创建到 /usr/local/var/www 的软链接
sudo ln -s /usr/local/var/www ~/html
# 测试您的 LAMP Web 服务器
sudo echo "<?php phpinfo(); " > ~/html/phpinfo.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment