Installing nginx and php-fpm on Mac OSX 10.8 using ports

This guide will guide you through the process of setting up PHP-FPM and nginx on your Mac OSX 10.8 Mountain Lion using MacPorts.

Installing XCode

For starters, you need MacPorts installed. This requires XCode and XCode’s Command Line tools. You can get XCode off the Apple Store. Once installed, go to preferences and install the Command Line tools.

Next install MacPorts. Just go to this page and download the pkg for your version of OSX.

Once that’s done, we’re ready to start.

Installing PHP-FPM

First, let’s install PHP-FPM:

sudo port install php54-fpm

Now we’ll also need to copy the config file:

sudo cp /opt/local/etc/php54/php-fpm.conf.default /opt/local/etc/php54/php-fpm.confsudo cp /opt/local/etc/php54/php.ini-development /opt/local/etc/php54/php.ini

That’s PHP sorted. If you want to install any PHP extensions, just use port install php54-EXTENSION.

Installing nginx

Next, we install nginx and copy the config files into the right place.

sudo port install nginx
 sudo cp -p /opt/local/etc/nginx/fastcgi.conf.example /opt/local/etc/nginx/fastcgi.conf
 sudo cp /opt/local/etc/nginx/fastcgi_params.example /opt/local/etc/nginx/fastcgi_params
 sudo cp /opt/local/etc/nginx/mime.types.example /opt/local/etc/nginx/mime.types
 sudo cp /opt/local/etc/nginx/nginx.conf.example /opt/local/etc/nginx/nginx.conf
 sudo mkdir /opt/local/etc/nginx/conf.d

Configuration

That’s it. Now you can go ahead and configure nginx to your liking by editing the file:

/opt/local/etc/nginx/nginx.conf

I have also changed some configuration files to make PHP work properly off my ~/Sites/ folder.

Edit /opt/local/etc/php54/php.ini:

cgi.fix_pathinfo=0

This will help with the nginx config.

Edit the fastcgi_params file:

sudo vi /opt/local/etc/nginx/fastcgi_params

It should look like this:

fastcgi_param   QUERY_STRING            $query_string;
fastcgi_param   REQUEST_METHOD          $request_method;
fastcgi_param   CONTENT_TYPE            $content_type;
fastcgi_param   CONTENT_LENGTH          $content_length;

fastcgi_param   SCRIPT_FILENAME         $request_filename;
fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
fastcgi_param   REQUEST_URI             $request_uri;
fastcgi_param   DOCUMENT_URI            $document_uri;
fastcgi_param   DOCUMENT_ROOT           $document_root;
fastcgi_param   SERVER_PROTOCOL         $server_protocol;

fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

fastcgi_param   REMOTE_ADDR             $remote_addr;
fastcgi_param   REMOTE_PORT             $remote_port;
fastcgi_param   SERVER_ADDR             $server_addr;
fastcgi_param   SERVER_PORT             $server_port;
fastcgi_param   SERVER_NAME             $server_name;

fastcgi_param   HTTPS                   $https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS         200;

And finally, add a location to your nginx configuration for PHP:

sudo vi /opt/local/etc/nginx/nginx.conf

Here’s my config:

        location ~ \.php$ {
            root   /Users/florian/Sites;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }

That’s it for the configuration.

Tweaking .bash_profile

Lastly, we’ll add some lines to your .bash_profile to make it easier to start and stop nginx and php_fpm.

vi ~/.bash_profile

And then add the following:

# nginx
 alias nginx_start='sudo launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist'
 alias nginx_stop='sudo launchctl unload -w /Library/LaunchDaemons/org.macports.nginx.plist'
 alias nginx_restart='nginx_stop; nginx_start;'
#php-fpm
alias fpm_start=’sudo launchctl load -w /Library/LaunchDaemons/org.macports.php54-fpm.plist’
 alias fpm_stop=’sudo launchctl unload -w /Library/LaunchDaemons/org.macports.php54-fpm.plist’
 alias fpm_restart=’fpm_stop; fpm_start’
Boom! That’s it. You’ve now got nginx and php-fpm running on your Mac.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值