The majority of tools are installed via the Homebrew tool. We will refer the Homebrew root directory with <HOMEBREW_[package]>, which can be retrieved via the command
brew --prefix [package]
The default location of the nginx.conf
on macOS after installing with Homebrew is <HOMEBREW_[nginx]>/nginx.conf
.
Edit the configuration file and replace all content by: nginx.conf
To have different version of PHP upstream, we have created variables in the nginx.conf file, inside http
services.
upstream fastcgi_backend7.3 {
server unix:/var/run/php7.3-fpm.sock;
}
upstream fastcgi_backend7.4 {
server unix:/var/run/php7.4-fpm.sock;
}
If you install a new version of PHP, you will have to add a new variable to the file.
ie:
upstream fastcgi_backend<PHP_VERSION> {
server unix:/var/run/php<PHP_VERSION>-fpm.sock;
}
We will have to give to NGINX the permission to access our files and avoid a nasty 403 Forbidden error.
To do so, we will change the first line, where <USER>
is your username.
- To find your user, you can type the following command :
$ echo $USER
johndoe
Edit the file <HOMEBREW_[nginx]>/nginx.conf
- Change the following parameter to:
user <USER> staff;
or you can use this one line command:
sed -i "" "s/<USER>/${USER}/" $(brew --prefix nginx)/nginx.conf
The log directory is not created by default. We have to create it manually to avoid errors at startup.
mkdir -p $(brew --prefix nginx)/logs
Before starting NGINX, we can perform a test to see if everything is correct in the configuration with the following command:
sudo nginx -t
At last, we start NGINX to activate the changes:
NGINX must be started as root
(sudo)
to have the necessary permissions.
sudo brew services start nginx
Server Block
directory -><HOMEBREW_[nginx]>/servers
- Default config ->
<HOMEBREW_[nginx]>/nginx.conf
- Logs will be in ->
<HOMEBREW_[nginx]>/logs
You can either use the native command or the
Pleaz
CLI.
- Start service:
## Native
sudo brew services start nginx
## Pleaz CLI
pleaz service:start nginx
- Stop service:
## Native
sudo brew services stop nginx
## Pleaz CLI
pleaz service:restart nginx
- Restart service:
## Native
sudo brew services restart nginx
## Pleaz CLI
pleaz service:restart nginx
- Check configuration file
sudo nginx -t