Nginx Mac Os



  1. How to Install Nginx on MacOS Introduction. Nginx is a web server which can also be used as a HTTP cache, load balancer and reverse proxy.This was first created by Igor Sysoev and released in 2004 under the terms of BSD like license. In this tutorial, we will learn the steps involved in the installation of Nginx.
  2. Go back to the operating system / installation method selection menu. Table of contents. Step 1: install Passenger package. Step 2: enable the Passenger Nginx module and restart Nginx.

Installing NGINX on Mac. There are following steps to install the Nginx on Mac OS: Step 1: Download Homebrew. To install the Nginx on Mac OS, Homebrew must be installed on the system. Homebrew is a package manager for Mac operating system that allows us to install various Unix applications easily. This is not wise to do on a production server. On a new Mac dev setup, this is perfectly fine. Sudo killall php-fpm Nginx. Brew install nginx sudo nginx. Now, test the install is working. Now, change the default settings. Code /usr/local/etc/nginx/nginx.conf. This page shows how to install Nginx on Mac OS using 'brew' $ brew install nginx Incase if your system didnot recongize this command, then install homebrew first by running below command and rerun above command once again.

Heavily borrowed from: Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.

Install nginx

For enabling a site:

Start nginx:

Update /etc/hosts file:

My site config file:

My nginx.conf

UPDATES:

Despite following the above instructions, I was again caught with error issues while setting up my new Catalina OS.

The resolution steps after troubleshooting the problems were:

Make sure the last line in the above nginx.conf is updated to:

Note .. then *.*

Next, this was a REAL issue, I did everything perfectly but STILL the enabled was not getting picked up!!!

As mentioned here (https://stackoverflow.com/a/53528685), I needed to add listen [::]:80;to bind the site to IPv6 and my PC was on an IPv6 connection

Below is the exact site config:

Also, not to forget . my /etc/hosts/ file is:

Setup

Before starting you need xcode installed with the cli tools. Also, you will need VS Code installed with the codecommand in your system path.

And, homebrew.

OpenSSL

Install OpenSSL.

MySQL

Install MySQL.

Next, update your my.cnf

Now, secure using the password password and then restart.

Next, MySQL 8 authentication needs to be updated per user to mysql_native_password.

Postgres

Install postgresql (not the postgres app).

Now, you can check your user list.

PHP

Don’t use the default homebrew core tap for PHP. Use shivammathur/php.

Next, set PHP 7.4 as your default php CLI version.

Now, for each version update the php-fpm you will need a unique port. Change the ports of each php-fpm to match its php version number. For example, php@7.4 I use port 9074.

Also, you will want php-fpm to run with your user account and not _www.

Optionally, before starting php-fpm, if you want to make edits to a php.ini file now is the time. For example, you might want to increase the upload_max_filesize and post_max_size to 10M.

Once you are ready, start up php-fpm for each version.

Check that you have processes running and validate your ports are correct.

Next, and optionally, add some aliases for your CLI to use by adding the following and replacing <your_version> with the version homebrew installs. This will give you quick access to a specific version when needed.

If you want to change the default php CLI you can set it using brew or, if added, the bash function phpv 7.4.

PHP Errors

As time passes Homebrew is bound to break your PHP installations. When this happens you can reinstall the PHP version having the error. Keep in mind you may need to reconfigure that version of PHP but I’ve found your php.ini files remain the same.

Xdebug

Now, I like xdebug for development. But, this step is optional. To install xdebug for each version of php (cli and fpm) run the following.

For each version you installed update the php.ini. In our example, php@7.4.

Macos

You will need to remove the zend_extension='xdebug.so' that is added to the top of the file by the pecl install process. The new default xdebug port is 9003, it was port 9000.

Add the following to the bottom of your php.ini file.

When finished adding your xdebug configuration to each version you have installed kill all the currently running php-fpm processes. This is not wise to do on a production server. On a new Mac dev setup, this is perfectly fine.

Nginx

Install nginx.

Now, test the install is working.

Now, change the default settings.

Next, add a FastCGI gateway to php-fpm on the default server. The latest version of php installed is best. For other servers, you can set the version of PHP to the project requirement.

Next, add some basic security to your default server.

Then add the charset.

Now, you might want to allow for large file uploads.

Osx Nginx

Next, we edit the real index.html file used by nginx. So, replace the index.html with an index.php file. Then, and some php code to make sure everything is working.

Reload nginx.

To add more servers you can go to the nginx servers directory, /usr/local/etc/nginx/servers, and add them there as individual files. Here is a basic template.

To add SSL for your nginx server check out this post. I use these bash functions to make the process faster. To add a server I use the command nginxcreate my.test.x but you might want to modify the files to match your setup.

Dnsmasq

To save yourself the fuss of editing your hosts file constantly you can use dnsmasq. Download arduino llc (www.arduino.cc) driver.

Then we set up a custom hosts TLD *.x (or other hosts TLD like .test) that point to 127.0.0.1.

(customize the commands as needed)

Test that it is working.

MailHog

I like to have mailhog running as a development mail server. But, if you don’t want to take this step that is perfectly fine.

Now, you can access MailHog at http://localhost:8025/. However, you still need to connect MailHog to PHP and the mail mac command used by Postfix (Postfix comes with macOS Big Sur).

Add the following to the end of the file to connect MailHog to Postfix.

Send a test email and check MailHog.

Next, update each php.ini file with the following and then restart php-fpm. Note, test@localhost should be used but will be overridden by any PHP scripts that run.

Nginx For Mac

Redis

Install Radis. This will install Redis Server v6.

Mac Nginx Stop

Optionally, you can update your default dump.rdb file name in the redis.conf if you want.

Nginx Install Mac

Resources