Mac Nginx Installation Tutorial

Source: Internet
Author: User
Tags fpm php and mysql

Eeking a satisfactory solution to create a local Web server for programming in MacOS with PHP and MySQL, I was Disappointe D, the turnkey solutions were far from equaling the WAMP, the 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.

We'll see how to install Nginx, php-fpm and MariaDB (MySQL) on MacOS El Capitan thanks to homebrew Package Manager.

Homebrew

HomeBrew is a package manager for MacOS, which allows to easily install various Unix applications.

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

If you don't already have them, MacOS would prompt you to first install the Xcode Command line Tools.

After installation, the following command, if necessary, the would-tell-you-to-complete the installation:

brew doctor

Then updates all packages with:

brew updatebrew upgrade
Nginx

Although Apache is natively included with MacOS, we propose here to install Nginx, particularly Lightwei Ght and easily configurable. Its installation is do with:

brew install nginx

The following'll automatically launch Nginx at startup:

brew services start nginx

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

To does this, edit the configuration file:

nano /usr/local/etc/nginx/nginx.conf

To begin, we edit the line beginning and Nginx #user to give permission to access our files, to modify the Follo Wing line, where is <user> your username:

user <user> staff;

To use port, changing the line beginning with in listen :

listen 80;

Finally, it indicates the folder where you want to store your sites through the variable root :

root <chemin/vers/votre/site>;

We can now start Nginx:

sudo nginx
Php

Use PHP with Nginx we'll use PHP-FPM. To install PHP 7.0, launch the following commands:

Setup the homebrew taps which has dependencies we need:

brew tap homebrew/dupesbrew tap homebrew/versionsbrew tap homebrew/homebrew-php

Then we install:

brew install php70

Once installed, use the following commands to run only php-fpm on startup:

mkdir -p ~/Library/LaunchAgentscp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist

One can ensure the service runs well watching if the following command produces a result:

lsof -Pni4 | grep LISTEN | grep php

Finally, re-edit the configuration file:

nano /usr/local/etc/nginx/nginx.conf

We modify the line starting with by index :

index index.php;

Finally, add in the Section server  the following lines to run PHP For all files with the Extension .php :

  location ~ \.php { fastcgi_split_path_info ^ (. +? \.php) (/.*) $if  (!-f  $document _root$fastcgi_script_name{return 404} fastcgi_pass 127.0.0.1:9000 fastcgi_param script_filename  $request _filename include fastcgi_params;}      

Restart Nginx To activate the changes:

sudo nginx -s reload
Mysql

Rather than installing the version of MySQL by Oracle achieved, we'll install the free MariaDB fork WI Th the following commands:

brew install mariadb

The following lines is used to start of the server at startup:

brew services start mariadb

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

mysql_secure_installation

This is the perfect MAMP installation!

Reprint https://www.sylvaindurand.org/setting-up-a-nginx-web-server-on-macos/

Published on the 5th Januar

Mac Nginx Installation Tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.