服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > php教程 >

MAC下安装php7+mysql5.7+memcached+nginx等环境

时间:2016-06-12 13:29来源:未知 作者:最模板 点击:
安装brew /usr/bin/ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) 配置HOMEBREW_GITHUB_API_TOKEN 申请地址https://github.com/settings/tokens/new export HOMEBREW_GITHUB_API_TOKEN=your key brew常用

安装brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

配置HOMEBREW_GITHUB_API_TOKEN 申请地址https://github.com/settings/tokens/new

export HOMEBREW_GITHUB_API_TOKEN="your key"

brew常用命令 以PHP5.5为例

brew update                        #更新brew可安装包,建议每次执行一下
brew search php55                  #搜索php5.5
brew tap josegonzalez/php          #安装扩展<gihhub_user/repo>   
brew tap                           #查看安装的扩展列表
brew install php55                 #安装php5.5
brew remove  php55                 #卸载php5.5
brew upgrade php55                 #升级php5.5
brew options php55                 #查看php5.5安装选项
brew info    php55                 #查看php5.5相关信息
brew home    php55                 #访问php5.5官方网站
brew services list                 #查看系统通过 brew 安装的服务
brew services cleanup              #清除已卸载无用的启动配置文件
brew services restart php55        #重启php-fpm

升级一下mac的vim

brew install ctags macvim --env-std --override-system-vim

安装mysql

brew install mysql

MySQL开机启动:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

安装完成之后开启MySQL安全机制:

/usr/local/opt/mysql/bin/mysql_secure_installation

根据终端提示,输入root密码,然后依次确认一些安全选项。 我习惯本地的把root密码搞简单,所以设置完后进mysql改点东西,让密码安全验证的级别更低

mysql> SHOW VARIABLES LIKE 'validate_password%';
validate_password_number_count参数是密码中至少含有的数字个数,当密码策略是MEDIUM或以上时生效。

validate_password_special_char_count参数是密码中非英文数字等特殊字符的个数,当密码策略是MEDIUM或以上时生效。

validate_password_mixed_case_count参数是密码中英文字符大小写的个数,当密码策略是MEDIUM或以上时生效。

validate_password_length参数是密码的长度,这个参数由下面的公式生成

validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)

validate_password_dictionary_file参数是指定密码验证的字典文件路径。

validate_password_policy这个参数可以设为0、1、2,分别代表从低到高的密码强度,此参数的默认值为1,如果想将密码强度改若,则更改此参数为0。

更改密码长度
mysql> set global validate_password_length=0;

安装php

添加brew的PHP扩展库:

brew update
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php

安装php及扩展

brew install php70
brew install php70-memcached
brew install php70-xdebug

PHP编译过程中如果遇到configure: error: Cannot find OpenSSL's 错误,执行xcode-select --install

安装memcached时出了点小问题~~~ 提示缺少 zlib

brew install zlib

查看位置

locate zlib.h

你可能找到的位置如下

/usr/local/Cellar/zlib/1.2.8/include/zlib.h

再安装memcached

brew install --HEAD php70-memcached --with-zlib-dir=/usr/local/Cellar/zlib/1.2.8/include/zlib.h

然后查看php -v 报错Deprecated: PHP Startup: memcached.sess_lock_wait 因为php7弃用了一些函数 修改

vi /usr/local/etc/php/7.0/conf.d/ext-memcached.ini

memcached.sess_lock_wait
memcached.sess_lock_max_wait

被这个两个名字给取代了

memcached.sess_lock_wait_min
memcached.sess_lock_wait_max

添加常用环境变量

echo 'export PATH="$(brew --prefix php70)/bin:$PATH"' >> ~/.bash_profile  #for php
echo 'export PATH="$(brew --prefix php70)/sbin:$PATH"' >> ~/.bash_profile  #for php-fpm
echo 'export PATH="/usr/local/bin:/usr/local/sbib:$PATH"' >> ~/.bash_profile #for other brew install soft
source ~/.bash_profile

PHP-FPM开机启动:

ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

安装php composer

brew install composer
#检查一下情况
composer --version
Composer version 1.0.0-alpha8 2014-01-06 18:39:59

安装Nginx

brew install nginx --with-http_geoip_module

Nginx开机启动

ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

Nginx监听80端口需要root权限执行,因此:

sudo chown root:wheel /usr/local/Cellar/nginx/1.6.0_1/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.6.0_1/bin/nginx

配置nginx.conf

创建需要用到的目录:

sudo mkdir -p /var/www
sudo chown :staff /var/www
sudo chmod 775 /var/www

相关配置目录在 /usr/local/etc/nginx/

设置nginx php-fpm配置文件

vim /usr/local/etc/nginx/conf.d/php-fpm
#proxy the php scripts to php-fpm
location ~ \.php$ {
    try_files                   $uri = 404;
    fastcgi_pass                127.0.0.1:9000;
    fastcgi_index               index.php;
    fastcgi_intercept_errors    on;
    include fastcgi.conf;
}

来个虚拟站点玩玩

创建默认虚拟主机default
vim /usr/local/etc/nginx/sites-available/default输入:

server {
    listen       80;
    server_name  www.lvtao.net;
    root         /var/www/;

    access_log  off;

    location / {
        index  index.html index.htm index.php;
        autoindex   on;
        include     php-fpm;
    }
}

ssl配置

server {
    listen       443;
    server_name  www.lvtao.net;
    root       /var/www/;

    access_log  off;

    ssl                  on;
    ssl_certificate      ssl/localhost.crt;
    ssl_certificate_key  ssl/localhost.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
        include   php-fpm;
    }
}

创建ssl密钥

mkdir -p /usr/local/etc/nginx/ssl
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=State/L=Town/O=Office/CN=localhost" -keyout /usr/local/etc/nginx/ssl/localhost.key -out /usr/local/etc/nginx/ssl/localhost.crt

设置快捷服务控制命令

vi ~/.bash_profile
添加如下:
alias nginx.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
alias nginx.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
alias nginx.restart='nginx.stop && nginx.start'
alias php-fpm.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist"
alias php-fpm.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist"
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
alias mysql.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist"
alias mysql.restart='mysql.stop && mysql.start'
alias memcached.start="launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached.stop="launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
alias memcached.restart='memcached.stop && memcached.start'

使设置生效

source ~/.bash_profile
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(1)
100%
------分隔线----------------------------
栏目列表
热点内容