Skip to content

Instantly share code, notes, and snippets.

@nzajt
Last active February 2, 2016 08:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nzajt/cfe7c5514ed662adda4b to your computer and use it in GitHub Desktop.
Save nzajt/cfe7c5514ed662adda4b to your computer and use it in GitHub Desktop.
Magento on osx Mavricks with nginx, php-fmp

#Magento on osx Mavricks with nginx, php-fmp

##Step 1

###Make sure that brew is up to date and installed.

If you do not have home brew installed, go to the link below and install it.

Install Home Brew

Make Sure that brew is working run brew doctor and fix any issues that come up

Now that brew is working you will need to tap a few packages to install php correctly.

Execute the following terminal.

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

You are almost ready to install php, nginx and php-fpm

Now run

brew update

This will make sure you have the most current packages

##Step 2

###install

Now run the following to install php with the packages you need.

brew install --without-apache --with-fpm --with-mysql --whith-mcrypt php55

after you run this command it will give you instructions, you must follow them.

You need mcrypt to run magento and you need fpm to run fpm. We don't want apache because it can cause issues with Nginx and PHP-FPM.

Now for NGinx

brew install nginx

after you run this command it will give you instructions, you must follow them.

Lets see if it worked.

Run

which php

it should output /usr/local/bin/php

Run

which php-fpm

it should say /usr/sbin/php-fpm

Run

which nginx

it should say /usr/local/bin/nginx

If you fail one or more of these test it is most likely because you didn't set you paths correctly in your .bashrc or .zshrc file.

Open your .bashrc or .zshrc and make sure you have something like this.

export PATH=/usr/local/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin

##Step 3

###Configure it

At this point you have nginx and php-fpm working, I use ubuntu in production so I set up nginx and php-fpm to work the same way.

I also want nginx to work on port 80 and 443. I will show you how to do that in this section.

You will want to update the default nginx.conf

Run

wget -O /usr/local/etc/nginx/nginx.conf https://gist.githubusercontent.com/nzajt/a4c7b9feaf26595fde76/raw/b5fc7b36764dab87333bc3655b47ce9542b6aba1/nginx.conf

Some people think they can make Nginx faster by increasing the number of worker_processes or worker_connections That isn't the case. Making those numbers too high will make Nginx slower

worker_processes should be the number of cores in your computer and no more. Run sysctl -n hw.ncpu to find out the number of cores on your computer.

Leave worker_connections where it is.

##Step 4

Link It and start it

We are going to add a host file for your magento site.

Here is a common nginx config file for a magento site.

Magento Nginx Config

Add it to the root of your magento site. Update the paths in the file to your computer.

Now link it

Run

ln -s PATH TO NGNIX HOST FILE YOU JUST ADDED /usr/local/etc/nginx/sites-enabled/lgl.conf

Restart Nginx

sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

You have to run as sudo to use port 80 and 443.

Now go to your host file.

Run

sudo vim /etc/hosts

If you don't know how to use vim you can use nano

sudo nano /etc/hosts

Add this line 127.0.0.1 www.YOURSITE.com to the hosts

Go to the host and it should be working.

If you get a 500 error it means there is something wrong with php-fpm.

Make sure it is running correctly.

to restart php-fpm Run

to stop launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

to start launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

check if it is working by runing

lsof -Pni4 | grep LISTEN | grep php

You should see something like this

php-fpm   87099 NAME    6u  IPv4 0x58c37d3516174305      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   87130 NAME    0u  IPv4 0x58c37d3516174305      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   87131 NAME    0u  IPv4 0x58c37d3516174305      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   87132 NAME    0u  IPv4 0x58c37d3516174305      0t0  TCP 127.0.0.1:9000 (LISTEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment