osx启动nginx
Warning: this post is old and might not reflect the current state of the art
警告:此帖子过时,可能无法反映当前的最新状态
I’ll cover installing PHP on OSX via Homebrew on Nginx and PHP-FPM.
我将介绍如何通过Nginx和PHP-FPM上的Homebrew在OSX上安装PHP。
Homebrew is the best package manager for OSX and it will help keeping everything up to date.
Homebrew是OSX最好的软件包管理器,它将有助于使所有内容保持最新。
安装自制软件 (Install Homebrew)
First install Homebrew if you don’t have it installed.
如果尚未安装Homebrew ,请先安装它。
安装Nginx (Install Nginx)
In the terminal type
在终端类型
brew install nginx
brew install nginx
The default settings are:
默认设置为:
Config: /usr/local/etc/nginx/nginx.conf
Servers info: /usr/local/etc/nginx/servers/
Docroot: /usr/local/var/www
Port: 8080
Add it to the Launch Agents to be started when starting up the system:
将其添加到启动系统时要启动的启动代理:
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Now launch it
现在启动
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
All should be fine.
一切都应该没事。
Add this to /usr/local/etc/nginx/nginx.conf. Make sure to change /Users/flavio/www to your sites root folder. This allows access to all the sites, which will be accessible via subfolders.
将此添加到/usr/local/etc/nginx/nginx.conf。 确保将/ Users / flavio / www更改为您的站点根文件夹。 这样可以访问所有站点,这些站点可以通过子文件夹访问。
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
include sites-enabled/*; # load virtuals config
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
# gzip on;
# gzip_disable "MSIE [1-6]\.(?!.*SV1)";
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /Users/flavio/www;
try_files $uri $uri/ /index.php?$args ;
index index.php;
#root html;
index index.html index.htm;
}
# configure *.PHP requests
location ~ \.php$ {
root /Users/flavio/www;
try_files $uri $uri/ /index.php?$args ;
index index.html index.htm index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_intercept_errors on;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
}
Restart with sudo nginx -s reload
and access http://localhost:8080/
and you should see Nginx running. PHP sites will fail at this point.
重新启动sudo nginx -s reload
并访问http://localhost:8080/
,您应该看到Nginx正在运行。 PHP网站此时将失败。
安装PHP 7 (Install PHP 7)
brew install php70
brew install php70
Add it to the Launch Agents to be started when starting up the system:
将其添加到启动系统时要启动的启动代理:
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
Now launch it
现在启动
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
All should be fine.
一切都应该没事。
Refresh http://localhost:8080/
and access a PHP site, PHP should be running fine!
刷新http://localhost:8080/
并访问一个PHP站点,PHP应该运行良好!
安装Opcache (Install Opcache)
brew install php71-opcache
brew install php71-opcache
安装APCu (Install APCu)
brew install php71-apcu
brew install php71-apcu
允许使用端口80 (Allow using port 80)
sudo chown root:wheel ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
sudo chown root:wheel ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Nginx日志 (Nginx Logs)
/usr/local/var/log/nginx/
/usr/local/var/log/nginx/
osx启动nginx