博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mac nginx 安装教程
阅读量:7050 次
发布时间:2019-06-28

本文共 3432 字,大约阅读时间需要 11 分钟。

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 .

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 updatebrew 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 
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 
;

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/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 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 5
th Januar
你可能感兴趣的文章
MySQL单机多实例安装并配置主从复制
查看>>
awk调用shell命令的两种方法:system与print
查看>>
网络对抗技术 20164320 王浩 Exp 9 Web安全基础
查看>>
谷歌开源第二代机器学习系统 TensorFlow
查看>>
juqery模板 Templates
查看>>
eclipse 自动创建web.xml
查看>>
python 基础回顾2
查看>>
Servlet 示例
查看>>
十一.单表更新及多表更新
查看>>
深入理解DOM节点类型第三篇——注释节点和文档类型节点
查看>>
32位64位操作系统基本数据类型字节大小
查看>>
linux高级编程day04 笔记
查看>>
CF848C:Goodbye Souvenir(CDQ分治)
查看>>
BZOJ 1006: [HNOI2008]神奇的国度
查看>>
PHP+mysql系统报错:PHP message: PHP Warning: Unknown: Failed to write session data (files)
查看>>
反向代理负载均衡之APACHE
查看>>
Django 安装
查看>>
jQuery用unbind方法去掉hover事件及其他方法介绍
查看>>
Centos Git1.7.1升级到Git2.2.1
查看>>
linux修改PS1,自定义命令提示符样式
查看>>