Tutorial _php Example of building a NGINX+PHP+MYSQL development environment on Mac OS

Source: Internet
Author: User
Installing Homebrew

Homebrew is a very easy-to-use Package Manager for Mac that automatically installs dependent packages and frees you from cumbersome software dependencies.
Installing the homebrew is also very simple, just enter it in the terminal:

 
  Ruby-e "$ (curl-fssl https://raw.github.com/Homebrew/homebrew/go/install)"

Common commands for Homebrew:

 
  Brew Update #更新可安装包的最新信息, it is recommended that you run the brew search pkg_name #搜索相关的包信息brew install pkg_name before each installation #安装包

For more information, please refer to homebrew

Installing Nginx

Installation

 
  Brew Search Nginxbrew Install Nginx

The current latest version is 1.4.4.

Configuration

 
  Cd/usr/local/etc/nginx/mkdir Conf.dvim Nginx.confvim./conf.d/default.conf

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 "' c10/> ' "$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;   include/usr/local/etc/nginx/conf.d/*.conf;}

default.conf file Contents,

 
  server {  listen    8080;  server_name localhost;  root/users/user_name/nginx_sites/; # The item to be modified as you are ready to store the relevant page path 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;   }  }

Installing PHP-FPM

Mac OSX 10.9 After the system comes with PHP, PHP-FPM, eliminating the hassle of installing PHP-FPM.
Here you need to simply modify the next PHP-FPM configuration, or run PHP-FPM will error.

 
  sudo cp/private/etc/php-fpm.conf.default/private/etc/php-fpm.confvim/private/etc/php-fpm.conf

Modify the Error_log entry in the php-fpm.conf file, which is commented out by default, which needs to be commented and modified to Error_log =/usr/local/var/log/php-fpm.log. If you do not modify this value, the log file output path does not exist when you run PHP-FPM.

Install MySQL

Installation

 
  Brew Install MySQL

Common commands

 
  Mysql.server start #启动mysql服务mysql. server Stop #关闭mysql服务

Configuration
Run the Mysql_secure_installation script at the terminal, which prompts you to set up a series of security-related parameters, including: Setting the root password, turning off anonymous access, not allowing the root user to remotely access, removing the test database. Of course, remember to start the MySQL service before running the script.

Test Nginx Service

Create a test file under the folder corresponding to the root key set in the previous Nginx configuration file default.conf index.php:


 
  <?php phpinfo ();?>

Start the Nginx service,

Modify the configuration file, restart the Nginx service,

Start the PHP service,

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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.