eeking 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.

We will 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, 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.

After installation, the following command, if necessary, will tell you how to complete the installation:

brew doctor

Then updates all packages with:

brew update
brew upgrade

Nginx

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

brew install nginx

The following will 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 do this, edit the configuration file:

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

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

user <user> staff;

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

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

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

Setup the homebrew taps which has dependencies we need:

brew tap homebrew/dupes
brew tap homebrew/versions
brew 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/LaunchAgents
cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist

One can ensure that 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 index by:

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 will install the free MariaDB fork with the following commands:

brew install mariadb

The following lines are used to start the server at startup:

brew services start mariadb

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

mysql_secure_installation

Here is the perfect MAMP installation !

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


Published on the 5th Januar

mac nginx 安装教程的更多相关文章

  1. MATLAB R2018b Mac中文版安装教程

    MATLAB r2018b mac中文版是一款强大的可视化数学分析软件,专门用于在Mac上执行数值计算,编程和可视化任务时极大地提高您的工作效率.在MATLAB的帮助下,您可以分析数据,创建应用程序, ...

  2. Visual Studio for Mac离线安装教程

    Visual Studio for Mac离线安装教程 可以在线安装,也可以离线安装(本次安装博主使用离线,在线安装失败了) 据说翻个墙就可以,有条件的就翻吧 没条件的我于是选择离线安装………… 离线 ...

  3. nginx 安装教程

    Nginx 安装教程 本教程在CentOS6.7中安装nginx 1.8.0,Nginx中加入了taobao的concat模块,nginx-upload-module模块,pcre 以及nginx-u ...

  4. nginx安装教程(详细)

    所见即所得编辑器, editorhtml{cursor:text;*cursor:auto} img,input,textarea{cursor:default}.cke_editable{curso ...

  5. xmind2020 zen 10.2.1win/mac/linux安装教程

    xmind是一款优秀的思维导图软件,本文教大家如何安装xmind zen 2020 10.2.1版本,解锁使用全部功能,包括去掉xmind zen水印.上传图片等功能,支持windows/mac/li ...

  6. Linux中Nginx安装教程

    Nginx 是一个很强大的高性能Web和反向代理服务器,它具有很多非常优越的特性: 在连接高并发的情况下,Nginx是Apache服务器不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的 ...

  7. centos7.2下nginx安装教程

    1.准备工作 1)关闭iptables 关闭操作 iptables -t nat -F 查看操作 iptables -t nat -L 2)关闭selinux 查看操作 setenforce 关闭操作 ...

  8. nginx安装教程

    一.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 二.首先要安装 PCRE ...

  9. Windows、mac字体安装教程

    请问字体如何安装? Win7.8.10安装字体方法: http://jingyan.baidu.com/article/14bd256e27c517bb6c26127c.html mac安装字体方法: ...

随机推荐

  1. active在iphone上不起作用

    在js中加一个空的touchstart函数 $(function(){ document.body.addEventListener('touchstart',function(){ }); 或在&l ...

  2. 解决Myeclipse ctrl+h带来的困扰

    解决Myeclipse ctrl+h带来的困扰 myeclipse的ctrl+h搜索功能给我们来查找文件定位类的方便,但同时也给我们带来两个困扰:一是搜出来的结果往往带着svn文件,一大推svn隐藏的 ...

  3. IDA*(以The Ratotion Game POJ--2286 UVa1343为例)

    IDA*算法实质就是迭代加深搜索和A*算法的结合,通过迭代加深搜索来寻找答案,借由预估函数h()来进行估计与剪枝. 本题主框架如下: ;;maxd++) { ,maxd)) break; } 由1开始 ...

  4. Spark各个版本新特性

    后续会添加spark生态系统中各个组件的兼容支持情况... Spark2.0.0 * 2016-07-27正式发布 * 它是2.x版本线的上的第一个版本. * 300位contributors的超过2 ...

  5. 浅谈STM32L071硬件I2C挂死

    STM32的IIC问题一直存在,在网上也被很多人吐槽,然而FAE告诉我,硬件IIC的问题在F1,F3,F4系列单片机存在,而在L0上已经解决了,然而这几天调试加密芯片和显示芯片,都是IIC芯片,却再一 ...

  6. 《DSP using MATLAB》Problem 6.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  7. Linux 命令的20个实用范例,入门必看!

    Tips: 达内Linux云计算免费课程火热抢报中,点击文末“阅读原文”快速抢! Linux中一个基本命令是ls.没有这个命令,我们会在浏览目录条目时会遇到困难.这个命令必须被每个学习Linux的人知 ...

  8. 【BZOJ3894】文理分科

    最小割劲啊 原题:  文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠 结过)  小P所在的班级要进行文理分科.他的班级可以用一个n*m的矩阵进行 描述,每个格子代表一个同学的座位.每位 ...

  9. eclipse操作(备忘)

    myecplise破解   https://blog.csdn.net/by_xiaobai007/article/details/81177367 1.查看类路径 2.建立模板 window--pr ...

  10. export的变量另开一个终端失效解决方法

    有时候,我们需要把一个export的变量全局话,否则每开一个终端又需要重新export,很是麻烦 首先直接export某个变量的话就只能在当前子终端生效,另开一个终端就失效了 如果修改.bash_pr ...