Home > Backend Development > PHP Tutorial > Mac OSX 1010 build nginx+mysql+php-fpm environment

Mac OSX 1010 build nginx+mysql+php-fpm environment

WBOY
Release: 2016-07-30 13:30:46
Original
1009 people have browsed it

Abstract: This article is based on homebrew to build the nginx+mysql+php-fpm environment. I am also a newbie. If there is anything wrong with the settings, I hope you can correct me.

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:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Copy after login
Common commands for homebrew:

brew update #更新可安装包的最新信息,建议每次安装前都运行下
brew search pkg_name #搜索相关的包信息
brew install pkg_name #安装包
Copy after login
For more information, please see homebrew

Install nginx

Install

brew search nginx
brew install nginx
Copy after login
The current latest version is 1.8.0

Configuration

cd /usr/local/etc/nginx/
mkdir conf.d
vim ./conf.d/default.conf
Copy after login
default.conf file content

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

}
Copy after login
configuration

cd /usr/local/etc/nginx/
vim nginx.conf
Copy after login
nginx.conf content:

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;
}
Copy after login

Install php-fpm

Mac OSX 10.9 system comes with PHP and php-fpm, eliminating the need to install php-fpm trouble.
You need to simply modify the configuration of php-fpm here, otherwise an error will be reported when running php-fpm.

sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf
vim /private/etc/php-fpm.conf
Copy after login
Modify the error_log item in the php-fpm.conf file. By default, this item is commented out. You need to comment it out and change 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

Install

brew install mysql
Copy after login
Common commands

mysql.server start #启动mysql服务
mysql.server stop #关闭mysql服务
Copy after login
Configure
Run the mysql_secure_installationscript in the terminal, the script will step by step You are prompted to set a series of security-related parameters, including: Set root password, Turn off anonymous access, Do not allow root users to access remotely, Remove test database. Of course, remember to start the mysql service before running this script.

Test the 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:

<?php phpinfo(); ?>
Copy after login
Start the nginx service, sudo nginx;
Modify the configuration file, restart the nginx service, sudo nginx -s reload
Start the php service,sudo php-fpm;

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


References

  1. Chen Shan’s blog post: Installing Nginx and PHP-FPM on Mac OS X
  2. English information: Installing Nginx, PHP-FPM and APC on Mac OS -fpm
  3. Environment

Added:Quickly stop or shut down Nginx: nginx -s stopNormal stop or shut down Nginx: nginx -s quitConfiguration file modification reload command: nginx - s reload

The above introduces the establishment of nginx+mysql+php-fpm environment on Mac OSX 1010, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template