Home >Backend Development >PHP Tutorial >Tutorial on setting up Nginx PHP MySQL development environment on Mac OS, _PHP tutorial

Tutorial on setting up Nginx PHP MySQL development environment on Mac OS, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:31900browse

Tutorial on setting up Nginx PHP MySQL development environment on Mac OS,

Install homebrew

Homebrew is a very easy-to-use package manager for Mac. It will automatically install related dependency packages, freeing you from tedious software dependency installation.
Installing homebrew is also very simple, just enter:

in the terminal
<!-- lang: shell -->
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Common commands for homebrew:

<!-- lang: shell -->
brew update #更新可安装包的最新信息,建议每次安装前都运行下
brew search pkg_name #搜索相关的包信息
brew install pkg_name #安装包

For more information, please see homebrew

Install nginx

Installation

<!-- lang: shell -->
brew search nginx
brew install nginx

The current latest version is 1.4.4.

Configuration

<!-- lang: shell -->
cd /usr/local/etc/nginx/
mkdir conf.d
vim nginx.conf
vim ./conf.d/default.conf

nginx.conf content,

<!-- lang: shell -->
worker_processes 1; 

error_log    /usr/local/var/log/nginx/error.log warn;

pid    /usr/local/var/run/nginx.pid;

events {
  worker_connections 256;
}

http {
  include    mime.types;
  default_type application/octet-stream;

  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   /usr/local/var/log/nginx/access.log main;
  port_in_redirect off;
  sendfile    on; 
  keepalive_timeout 65; 

  include /usr/local/etc/nginx/conf.d/*.conf;
}

default.conf file content,

<!-- lang: shell -->
server {
  listen    8080;
  server_name localhost;

  root /Users/user_name/nginx_sites/; # 该项要修改为你准备存放相关网页的路径

  location / { 
    index index.php;
    autoindex on; 
  }  

  #proxy the php scripts to php-fpm 
  location ~ \.php$ {
    include /usr/local/etc/nginx/fastcgi.conf;
    fastcgi_intercept_errors on; 
    fastcgi_pass  127.0.0.1:9000; 
  }  

}

Install php-fpm

Mac OSX 10.9 and later systems come with PHP and php-fpm, eliminating the trouble of installing php-fpm.
Here you need to simply modify the configuration of php-fpm, otherwise an error will be reported when running php-fpm.

<!-- lang: shell -->
sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
vim /private/etc/php-fpm.conf

Modify the error_log item in the php-fpm.conf file. This item is commented out by default. You need to comment it out and modify it to error_log = /usr/local/var/log/php-fpm.log. If this value is not modified, an error that the log file output path does not exist will be prompted when running php-fpm.

Install mysql

Installation

<!-- lang: shell -->
brew install mysql

Common commands

<!-- lang: shell -->
mysql.server start #启动mysql服务
mysql.server stop #关闭mysql服务

Configuration
Run the mysql_secure_installation script in the terminal. The script will prompt you step by step to set a series of security-related parameters, including: setting the root password, turning off anonymous access, not allowing root users to access remotely, and removing the test database. Of course, remember to start the mysql service before running this script.

Test nginx service

Create the test file index.php:

in the folder corresponding to the root item set in the previous nginx configuration file default.conf


<!-- ~/nginx_sites/index.php -->
<&#63;php phpinfo(); &#63;>

Start nginx service,

sudo nginx; 

Modify the configuration file and restart the nginx service,

sudo nginx -s reload 

Start the php service,

sudo php-fpm; 

Enter localhost:8080 in the browser address bar. If the configuration is correct, you should be able to see the PHP related information page.

Articles you may be interested in:

  • Installing nginx and php under mac

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084578.htmlTechArticleTutorial on setting up Nginx PHP MySQL development environment on Mac OS. Install homebrew. Homebrew is a very useful package for mac. The manager will automatically install relevant dependency packages, freeing you from cumbersome software dependencies...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn