Mac OS使用brew安装Nginx、MySQL、PHP-FPM的LAMP环境
Mac OS 内置了Apache 和 PHP,我的系统版本是OS X 10.13.4,可以通过以下命令查看Apache和PHP的版本号:
httpd -v
Server version: Apache/2.2.26 (Unix)
Server built: Dec 10 2013 22:09:38
php --version
PHP 7.1.14 (cli) (built: Feb 19 2018 18:33:30)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2013 Zend Technologies

现在我们来自己动手来安装 Nginx和php。
我们可以不用管系统自带的环境,重新用brew来安装,系统自带的路径在/usr/bin,我们安装的路径在/usr/local/bin,这两个不影响。
安装brew的步骤我们就不写了,这里具体来看怎么安装lnmp吧。
-
安装nginx
brew install nginx
修改配置文件
sudo vim /usr/local/etc/nginx/nginx.conf #修改默认的8080端口为80
给予管理员权限
sudo chown root:wheel/usr/local/opt/nginx/bin/nginx sudo chmod u+s/usr/local/opt/nginx/bin/nginx
加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
运行nginx
sudo nginx #打开 nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx nginx -t #测试配置是否有语法错误
-
安装mysql
brew install mysql cd /usr/local/opt/mysql/
修改配置文件
sudo vim my.cnf #如果出现无法启动mysql,rm my.cnf
加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents/ cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist #取消启动 #launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
初始化 mysql
./bin/mysql_install_db
执行安全设置脚本,设置root账号密码
./bin/mysql_secure_installation
命令行连接mysql
mysql -uroot -p
-
安装php
brew 默认没有 php 安装包:
brew tap homebrew/dupes brew tap josegonzalez/homebrew-php
现在可以安装php了:
brew install php54 --with-imap --with-tidy --with-debug --with-mysql --with-fpm
将php路径加入PATH
sudo vim ~/.bash_profile
export PATH="$(brew --prefix php54)/bin:$PATH"
source ~/.bash_profil
e
加入launchctl启动控制
mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/php54/homebrew.mxcl.php54.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php54.plist
配置路径
/usr/local/etc/php/5.4/php.ini /usr/local/etc/php/5.4/php-fpm.conf
配置 Nginx 支持 PHP-FPM
sudo vim /usr/local/etc/nginx/nginx.conf
# 添加默认首页 php
index index.php index.html index.htm;
# 取消以下内容的注释,并做修改
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/Cellar/nginx/1.6.0_1/html$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
测试环境
sudo vim /usr/local/Cellar/nginx/1.6.0_1/html/index.php
#添加测试代码
< ?php
phpinfo();
我们的Nginx、MySQL、PHP-FPM三大软件已经安装好了,一般来说nginx,mysql的版本不会有什么问题,需要注意的是我们在安装php的时候,需要选择我们需要的php版本去安装。
MySQL 1364 错误提示:#1364 – Field “details” doesn’t have a default value问题修复 Laravel数据删除以及软删除的操作方法
当你决定坚持一件事情,全世界都会为你让路。
好文章,谢谢分享,我的博客,欢迎回访