mac nginx 安装教程

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

时间: 2024-10-25 17:27:10

mac nginx 安装教程的相关文章

Visual Studio for Mac离线安装教程

Visual Studio for Mac离线安装教程 可以在线安装,也可以离线安装(本次安装博主使用离线,在线安装失败了) 于是选择离线安装………… 离线安装步骤 下载离线安装包链接地址: VisualStudioForMac-7.0.0.3146.dmg文件 下载地址:  http://t.cn/RaJ15n6 百度网盘下载地址:链接:http://pan.baidu.com/s/1bYR8RG 密码:cw32 MonoFramework-MDK-5.0.0.100.macos10.xama

vm虚拟机VMware Fusion Pro 11 Mac中文版安装教程

VMWare Fusiono 11 mac 中文版是一款强大的Windows虚拟机,可以让您能够在Apple的macOS和Mac的硬件上无缝运行Windows,Solaris,Linux和Netware操作系统!VMWare Fusion mac版易于安装,您可以快速启动并运行Windows.Fusion专为需要快速,简单和可靠的虚拟机替代方案的临时用户和专业人士而设计. VMWare Fusion mac 版安装教程 VMWare Fusion mac 特别版镜像包下载完成后,打开镜像包,双击

nginx安装教程

nginx: Linux packages Currently, nginx packages are available for the following distributions and versions: RHEL/CentOS: Version Supported Platforms 5.x x86_64, i386 6.x x86_64, i386 7.x x86_64 Debian: Version Codename Supported Platforms 7.x wheezy

Jmeter在Mac下安装教程

Step1:官网下载Jmeter http://jmeter.apache.org/download_jmeter.cgi 下载Binaries中的 apache-jmeter-5.0.tgz Step2:解压下载的Jmeter文件 Step3:解压后进入目录/bin/,输入命令"sh jmeter"启动 原文地址:https://www.cnblogs.com/liangxc/p/10000492.html

centos7 源码编译安装nginx教程 nginx安装脚本

安装nginx需要pcre zlib openssl的库,下文都是在官网直接下载用作编译安装 该nginx安装教程,有安装maxmind IP 库 该nginx安装教程有安装openrestry 系统使用了centos 7 该教材有修改最大打开文件描述符数到最大 该教程是nginx安装的shell脚本 #!/bin/bash yum install epel-release -y yum install gcc gcc-c++ make automake autoconf libtool ipt

CG工具集Isotropix Clarisse iFX 4.0SP2b安装教程

isotropix clarisse ifx mac版是mac平台上一款强大专业的动画渲染软件,是一个集动画,一个合成软件和一个3D渲染引擎的融合体!可以和CG流水线结合一起进行动画实时预览,彻底改变了传统图像的创建方法.新版本将为我们带来更多人性化的功能,一些革命性的创新简直不能太赞了.不论是Layout布局.assemble装配.LookDev,灯光还是渲染,Clarisses 都将给你带来前所未有的速度和效果以及所见即所得的美好体验. clarisse ifx mac 版安装教程 clar

mac苹果电脑上Mathtype软件的安装教程

对于数学学习来将,Mathtype是一款非常不错的工具,在这里您可以方便快捷的计算出公式的结果,只需要将方程式填写进去就能出来结果.小编为大家准备了Mathtype安装教程,安装的过程是非常简单的,安装好了之后会让您的工作变得更加轻松,还能提升工作的效率哦! Mathtype安装教程介绍:第一步:打开下载的Mathtype文件 第二步:点击左边的安装文件,会得到提示,下图所示: 第三步:选择好,然后会在弹出提示窗口,点击继续,如下图所示: 第四步:因为暂时只有英文版的,所以选择英文版,点击继续安

Mac下安装LNMP(Nginx+PHP5.6)环境(转)

安装Homebrew 最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例,记录一下从零开始安装Mac下LNMP环境的过程 确保系统已经安装xcode,然后使用一行命令安装依赖管理工具Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 之后就可以使用 brew install FORMULA 来安装所需要的依赖了.

Mac下安装LNMP(Nginx+PHP5.6)环境

Mac下安装LNMP(Nginx+PHP5.6)环境 安装Homebrew 最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例,记录一下从零开始安装Mac下LNMP环境的过程 确保系统已经安装xcode,然后使用一行命令安装依赖管理工具Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 之后就可以使用 brew