自己动手搭配一套LNMP,想装什么环境,随便搞~
环境配置:
HomeBrew 是 Mac 系统上一个包管理工具,官网链接
直接使用 ruby 命令运行完事:
Default
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
---|
Default
// 安装nginx brew install nginx
12 | // 安装nginxbrew install nginx |
---|
Shell
brew search nginx // 显示对号证明安装成功 ==> Formulae nginx ✔ homebrew/linuxbrew-core/nginx
12345 | brew search nginx // 显示对号证明安装成功==> Formulaenginx ✔ homebrew/linuxbrew-core/nginx |
---|
Default
brew info nginx // 下面是安装目录 nginx: stable 1.15.12 (bottled), HEAD HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server https://nginx.org/ /usr/local/Cellar/nginx/1.15.8 (23 files, 1.4MB) * <strong> // 在这一行!!!!</strong> Poured from bottle on 2019-01-21 at 20:30:20 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb ==> Dependencies Required: openssl ✔, pcre ✔ ==> Options --HEAD Install HEAD version ==> Caveats Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. nginx will load all files in /usr/local/etc/nginx/servers/. To have launchd start nginx now and restart at login: brew services start nginx Or, if you don't want/need a background service you can just run: nginx
1234567891011121314151617181920212223242526 | brew info nginx // 下面是安装目录nginx: stable 1.15.12 (bottled), HEADHTTP(S) server and reverse proxy, and IMAP/POP3 proxy serverhttps://nginx.org//usr/local/Cellar/nginx/1.15.8 (23 files, 1.4MB) * <strong> // 在这一行!!!!</strong> Poured from bottle on 2019-01-21 at 20:30:20From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb==> DependenciesRequired: openssl ✔, pcre ✔==> Options--HEAD Install HEAD version==> CaveatsDocroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so thatnginx can run without sudo. nginx will load all files in /usr/local/etc/nginx/servers/. To have launchd start nginx now and restart at login: brew services start nginxOr, if you don't want/need a background service you can just run: nginx |
---|
Default
mkdir -p ~/Library/LaunchAgents cp /usr/local/Cellar/nginx/1.15.8/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
123 | mkdir -p ~/Library/LaunchAgentscp /usr/local/Cellar/nginx/1.15.8/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist |
---|
Default
// 启动nginx sudo nginx // 重新加载配置|重启|停止|退出 nginx sudo nginx -s reload|reopen|stop|quit // 测试配置是否有语法错误 nginx -t
12345678 | // 启动nginxsudo nginx // 重新加载配置|重启|停止|退出 nginxsudo nginx -s reload|reopen|stop|quit // 测试配置是否有语法错误nginx -t |
---|
Shell
vim /usr/local/etc/nginx/nginx.conf
1 | vim /usr/local/etc/nginx/nginx.conf |
---|
Default
// 默认监听8080端口 server { listen 80; server_name localhost; # 设定网站根目录 root /Users/wanghuiyu/PhpstormProjects/stock/public; # 网站默认首页 index index.php index.html index.htm; #charset koi8-r; #access_log logs/host.access.log main; location / { # 修改为 Laravel 转发规则,否则PHP无法获取$_GET信息,提示404错误 try_files $uri $uri/ /index.php?$query_string; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /Users/wanghuiyu/PhpstormProjects/stock/public$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; } }
123456789101112131415161718192021222324252627282930313233343536373839 | // 默认监听8080端口server { listen 80; server_name localhost; # 设定网站根目录 root /Users/wanghuiyu/PhpstormProjects/stock/public; # 网站默认首页 index index.php index.html index.htm; #charset koi8-r; #access_log logs/host.access.log main; location / { # 修改为 Laravel 转发规则,否则PHP无法获取$_GET信息,提示404错误 try_files $uri $uri/ /index.php?$query_string; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /Users/wanghuiyu/PhpstormProjects/stock/public$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; } } |
---|
添加多个配置文件
Default
cd /usr/local/etc/nginx/servers vim zhaoshuai.me.conf
12 | cd /usr/local/etc/nginx/serversvim zhaoshuai.me.conf |
---|
Default
brew search mysql
1 | brew search mysql |
---|
Shell
brew install mysql@5.7
1 | brew install mysql@5.7 |
---|
Default
// 停止、启动、重启 mysql.server stop mysql.server start mysql.server restart
1234 | // 停止、启动、重启mysql.server stopmysql.server startmysql.server restart |
---|
Default
mysql -u root mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | school | | sys | | ziroom | +--------------------+ 6 rows in set (0.00 sec)
12345678910111213 | mysql -u rootmysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || school || sys || ziroom |+--------------------+6 rows in set (0.00 sec) |
---|
Default
$ mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
12 | $ mysql -u rootERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) |
---|
有可能是 mysql 没有启动,运行 mysql.server start
Shell
brew search php
1 | brew search php |
---|
Default
brew install php@7.2
1 | brew install php@7.2 |
---|
Shell
echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc
12 | echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrcecho 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc |
---|
Shell
brew services start php@7.2
1 | brew services start php@7.2 |
---|
Default
$ which php /usr/local/opt/php@7.1/bin/php // phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块 $ which phpize /usr/local/opt/php@7.1/bin/phpize // 指定php的配置 $ which php-config /usr/local/opt/php@7.1/bin/php-config
12345678910 | $ which php/usr/local/opt/php@7.1/bin/php // phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块$ which phpize/usr/local/opt/php@7.1/bin/phpize // 指定php的配置$ which php-config/usr/local/opt/php@7.1/bin/php-config |
---|
Default
cd /usr/local/etc/php/7.1 // php.ini vim /usr/local/etc/php/7.1/php.ini // php-fpm 配置文件 vim /usr/local/etc/php/7.1/php-fpm.d/www.conf
1234567 | cd /usr/local/etc/php/7.1 // php.ini vim /usr/local/etc/php/7.1/php.ini // php-fpm 配置文件vim /usr/local/etc/php/7.1/php-fpm.d/www.conf |
---|
Default
sudo -S /usr/local/opt/php@7.1/sbin/php-fpm
1 | sudo -S /usr/local/opt/php@7.1/sbin/php-fpm |
---|
示例,安装 phalcon 扩展:
Default
git clone git://github.com/phalcon/cphalcon.git cd cphalcon/ git checkout v3.0.3 cd build/php7/64bits which phpize(查看phpize地址) /usr/local/opt/php@7.0/bin/phpize sudo make #中间会出现 warning 忽略 需要等待一会 sudo make install
12345678 | git clone git://github.com/phalcon/cphalcon.gitcd cphalcon/git checkout v3.0.3cd build/php7/64bitswhich phpize(查看phpize地址)/usr/local/opt/php@7.0/bin/phpizesudo make #中间会出现 warning 忽略 需要等待一会sudo make install |
---|
如果你不想要开机就启动 “PHP + Mysql + Nginx”, 推荐一种一键启动脚本:
Default
#! /bin/zsh password={你的电脑密码} # mysql mysql.server start # nginx echo $password | sudo -S nginx # php-fpm echo $password | sudo -S /usr/local/opt/php@7.1/sbin/php-fpm
12345678 | #! /bin/zshpassword={你的电脑密码}# mysqlmysql.server start# nginx echo $password | sudo -S nginx# php-fpmecho $password | sudo -S /usr/local/opt/php@7.1/sbin/php-fpm |
---|
我们可以把这个脚本放在用户目录的 Scripts 下面,然后设置一下 快捷键 :
Default
vim ~/.zshrc // 加入下面这行 alias launch="~/Scripts/AutoLaunch.sh"
123 | vim ~/.zshrc// 加入下面这行alias launch="~/Scripts/AutoLaunch.sh" |
---|
在命令行运行 launch 即可~~
点个赞再走吧~~