Brew Nginx



Seeking a satisfactory solution to create a local web server for programming in macOS with PHP and MySQL, I was disappointed that the turnkey solutions were far from equaling the WAMP that may exist on Windows.

But I forgot macOS is a Unix system, and unlike Windows, it’s perfectly possible to create a customized local server with some packages.

But even though 'sudo brew services stop nginx', stops it, I don't want to have to keep running that every time I restart my machine. Terminal homebrew startup services. Nginx resources site has a full list of web server applications which you can use to run various applications on Windows PC. Nginx is one of the leading web server companies which is expected to overshadow Apache in the future. Also, it is faster, can handle more concurrent issues and is.

We will see how to install Nginx, PHP-FPM and MariaDB (MySQL) on macOS High Sierra thanks to Homebrew package manager.

Homebrew

HomeBrew is a package manager for macOS, that allows to easily install various Unix applications.

To install, simply execute the command shown on the official website:

If you do not already have them, macOS will prompt you to first install Xcode Command Line Tools.

Nginx

Although Apache is natively included with macOS, we propose here to install Nginx, particularly lightweight and easily configurable.

Installation

To install and launch Nginx on startup, we use: Siliten input devices driver.

Although we musn’t use sudo with brew install, it is necessary to use it to launch Nginx if we want to use the the default port 80.

Configuration

Brew

We want to store our web site in the folder of our choice, and access to the URL http://localhost/.

To begin, we will have to give to Nginx the permission to access our files and avoid a nasty 403 Forbidden error. To do so, we change the first line, where <user> is your username:

Then, to add a new website, we will add a new section inside the http directive:

We then restart Nginx in order to take this changes into account:

PHP

In order to use PHP with Nginx we will use PHP-FPM.Here, we will use PHP 7.2, but you can easily choose any other version: Microsoft remote desktop for macos.

Then, we re-edit the configuration file, and modify the line starting with index by:

Finally, add in the section server the following lines to run PHP for all files with the extension .php:

To avoid a File not found. error, we also need to give the right permissions to PHP:

At last, we restart Nginx to activate the changes, and we don’t forget to launch PHP, to avoid a 502 Bad Gateway:

MySQL

We will now install and launch MariaDB:

Finally, complete the installation by choosing a root password for MySQL:

Brew Start Nginx

The article logs my process of using Nginx1.19 + php7.3 + MySQL8 to build the test environment of Magento on my MacBook(macOS Big Sur 11.2.1), I hope it is helpful for you.

Before starting the installation, you need homebrew installed on the computer.

Nginx Part:

Firstly, install Nginx and start the service

Pitney bowes port devices driver download. MySQL Part:

Secondly, install MySQL8, start the service and create the database

Edit my.cnf to run MySQL8 with native password authentication

Save then restart MySQL service

Change MySQL password

Create new Magento database:

Mysql has been installed successfully and configured properly. Now let us install PHP.

PHP Part:

The default PHP version is PHP8 by brew however Magento2 doesn’t support it so we need to install a downgraded PHP7.3 version and start the service for php-fpm mode which will be occupying port 9000.

Nginx

After installed, open a new terminal to confirm the latest php7.3 has been installed:

There are some configures you need to set in php.ini

then update following settings:

remember to restart PHP services after updated php.ini

Install composer as the PHP package management tool

Magento Part:

Install elasticsearch and start the service which relied on Magento.

Download Magneto source code to a new folder, I name it as “magento-community” and you can use any name.

Brew Nginx Not Starting

You will be asked to provide the name and password for downloading from repo.magento.com, access https://marketplace.magento.com/ , register a new user or login, then, click “My Profile” on your username at the right top of the page.

After downloading successfully, go to the Magento folder,

Install Magento:

Brew Nginx Restart

Magento has been installed successfully, remember to turn off two-step authentication or you will get an email notification to confirm login.

now let us configure Nginx.

Brew Nginx Config

Configure Nginx to support PHP

Brew Nginx Stop

Now Magento has been installed successfully on Macbook, you can access it at http://127.0.0.1:8001