osx10.9.4安装php开发环境(nginx1.6.0+mysql5.6.19+php5.5.14)

来源:互联网 发布:石破天 武功 知乎 编辑:程序博客网 时间:2024/06/06 17:16

Mac下已经为我们集成了php5.4、apache2。所以在Mac下开发PHP是一种不错的选择;

安装环境

osx10.9.4

xcode  Version 5.1.1 (5B1008)

如果您已经装好以上环境就可以跟着本文安装PHP开发环境了

老规矩,本文安装使用的Homebrew进行Mac软件包管理器来安装,方便以后升级和扩展.

这里我们不使用mac给我们提供的php和apache,我们来全新安装环境,当然我们也不要去删除自带的php和apache,以免出现系统不稳定(xcode要用到)。

首先,安装一下编辑器,这里推荐安装sublime3,方便等下修改配置文件

下载地址:SublimeOS X版本(10.7 or later is required)

安装完毕之后做一个链接,以后使用sublime直接可以使用subl
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /bin/subl

第二步,安装Homebrew 

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
安装过程有点漫长,由于国内网络复杂原因,建议安装homebrew的时候使用v p n

更新下brew

brew update

安装Nginx1.6.0

brew install nginxmkdir -p ~/Library/LaunchAgents#添加到开机启动ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents#下面这两句必须,否则开机自启动不会成功sudo chown root:wheel /usr/local/Cellar/nginx/1.6.0_1/bin/nginxsudo chmod u+s  /usr/local/Cellar/nginx/1.6.0_1/bin/nginxsudo chown -R $USER /usr/local/var/log/nginx/#等全部安装完环境在进行配置

安装php5.5.14

brew tap homebrew/dupesbrew tap josegonzalez/homebrew-php#以下命令必须执行,否则会出现找不到openssl的错误xcode-select --installbrew install --without-apache --with-fpm --with-mysql php55#替换pathvi ~/.bash_profileexport PATH="/usr/local/bin:/usr/local/sbin:$PATH"#测试一下版本php -v or php-fpm -v#安装完毕设置php-fpm自启动ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents

安装mysql5.6.19

brew install mysql#启动mysqlmysql.server start#设置root密码mysqladmin -u root password#mysql开机自启动ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

配置Nginx (开发环境配置,非生产环境)

#备份原始配置mv /usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/nginx.conf.bak#配置文件vi /usr/local/etc/nginx/nginx.conf#写入以下内容,user要改成你的当前登录账户user zhuzhenyu staff;worker_processes  2; #error_log  logs/error.log; #error_log  logs/error.log  notice; #error_log  logs/error.log  info;events {    worker_connections  1024;}http {#列目录,方便调试    autoindex on;    include       mime.types;    sendfile        on;    #keepalive_timeout  65;    # gzip  on;    # gzip_disable "MSIE [1-6]\.(?!.*SV1)";    include vhost/*.conf;}
#创建include_php.conf

vi /usr/local/etc/nginx/include_php.conf#写入以下内容fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include        fastcgi_params;fastcgi_param SERVER_NAME $host;fastcgi_intercept_errors on;

#创建虚拟主机配置目录

mkdir /usr/local/etc/nginx/vhost#这里做演示创建一个虚拟主机:blog.comsubl /usr/local/etc/nginx/vhost/blog.com.conf#写入以下内容server {    listen       80;    server_name  blog.com;    root /Users/zhuzhenyu/workspace/blog.com;    index index.php index.html index.htm;    location / {        if (!-e $request_filename) {            rewrite  ^(.*)$  /index.php?s=$1  last;            break;        }    }    location ~ \.php$ {        include include_php.conf;    }}#以后只要创建虚拟主机在/usr/local/etc/nginx/vhost/xxx.conf即可#创建web目录mkdir -p ~/workspace/blog.comsubl ~/workspace/blog.com/index.php#写入以下内容<?phpphpinfo();#操作nginx,(如果修改过nginx配置文件,切记一定要重启)nginx -t #检测nginx配置文件语法nginx start #启动nginx -s reload #平滑重启nginx restart #重启

配置php
subl /usr/local/etc/php/5.5/conf.d/test_load.ini#写入如下内容short_open_tag = Ondisplay_errors = Ondisplay_startup_errors = Onupload_max_filesize = 256Mdate.timezone = "Asia/Shanghai"error_reporting = E_ALL#保存即可
#为了测试,我们修改下本机的hostsudo vi /etc/hosts#添加一条记录127.0.0.1 blog.com

这时候,我们在浏览器输入http://blog.com会出现如下结果



0 0
原创粉丝点击