MAC使用brew安装Nginx+PHP+MySql环境

MAC使用brew安装Nginx+PHP+MySql环境

  1. 安装HomeBrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. 安装 Nginx
    搜索Nginx版本 brew search nginx (一般最新版)
    安装 brew install nginx
    brew 执行完成后,nginx 就安装成功了。

    打开 nginx
    sudo nginx

    重新加载配置|重启|停止|退出 nginx
    nginx -s reload|reopen|stop|quit

    测试配置是否有语法错误
    nginx -t

    启动 nginx 后,默认的开启的是8080端口,可以通过修改配置文件来设置端口:
    vim /usr/local/etc/nginx/nginx.conf

    默认访问的目录:
    /usr/local/Cellar/nginx/1.4.7/

    设置 nginx 开机启动:

    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/nginx/1.12.2_1/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

    设置权限:
    sudo chown root:wheel /usr/local/Cellar/nginx/1.12.2_1/bin/nginx
    sudo chmod u+s /usr/local/Cellar/nginx/1.12.2_1/bin/nginx

    Nginx配置文件:
    /usr/local/etc/nginx/nginx.conf

  2. 安装MySql
    搜索MySql版本 brew search nginx (若不选择,默认最新版本)
    安装 brew install mysql
    配置mysql数据库:(文件路径要符合本机)

mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
MySql 启动
cd /usr/local/Cellar/mysql/5.7.21/bin/
./mysql.server start

如果配置了环境变量,则可以在终端根目录下执行:mysql -uroot -p(输入密码)
如果没有,则需要在mysql服务所在目录执行,

设置 mysql 开机启动:
mkdir -p ~/Library/LaunchAgents/ (如果该目录已经创建,则不用再执行)
cp /usr/local/Cellar/mysql/5.7.17/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

mysql 配置文件:
/usr/local/etc/my.cnf
  1. 安装PHP
    搜索PHP版本 brew search php(选择PHP版本)
    安装 brew install php55

    PHP 启动 php55-fpm start
    设置 PHP 开机启动:

mkdir -p ~/Library/LaunchAgents  (如果该目录已经创建,则不用再执行)
cp /usr/local/Cellar/php55/5.5.38_12/homebrew.mxcl.php55.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

以上全部安装结束
在 /usr/local/var/www 目录中创建, info.php文件 编写:

<?php
    phpinfo();
?>

保存,在浏览器中访问,验证是否配通。

几个问题:
1. 没有链接数据库
需要重新编译生成 mysql.so扩展文件,官网下载php源码包,并且解压缩
终端访问进入该目录中的ext/mysql目录 cd /Users/Yao/Downloads/php-5.6.29/ext/mysql/
执行:/usr/local/Cellar/php55/5.5.38_12/bin/phpize (该命令要在解压出的php源码包目录中执行)

以下两个命令不需要执行,为标识对应文件地址:
/usr/local/Cellar/php55/5.5.38_12/bin/php-config
/usr/local/Cellar/mysql/5.7.17/
执行以下命令:
./configure --with-php-config=/usr/local/Cellar/php55/5.5.38_12/bin/php-config --with-mysql=/usr/local/Cellar/mysql/5.7.17/  (文件地址要符合本机)
make && make install

新生成的mysql.so 文件所在地址,/usr/local/Cellar/php55/5.5.38_12/lib/php/extensions/no-debug-non-zts-20121212/

修改php.ini文件,添加mysql.so扩展配置,保存退出
extension=mysql.so
  1. mysql查询报错
    error:Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘nami0123.nash_community.servicecenter’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    终端进入mysql,执行以下命令:

mysql >  set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

mysql >  set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

将php添加到环境变量
sudo vim ~/.bashrc (如果没有该文件,则自动新建)
文件中编写: source $(brew –prefix php-version)/php-version.sh && php-version 5

保存退出后,执行 source .bashrc 重置环境变量
php55-fpm restart

但是发现,每次开机之后,都需要重置环境变量
以下:
MAC OS X 10.9.1 默认不会加载~/.bashrc,所以要自己在/etc/profile文件中增加以下内容(root权限):
sudo vim /etc/profile (已存在)
在文件最后中,加入
if [ -f ~/.bashrc ] ; then
. ~/.bashrc

f i(此行中间没有空格)
保存,退出

猜你喜欢

转载自blog.csdn.net/u013931660/article/details/79443225