Mac OS X Build NGINX+MYSQL+PHP-FPM Environment Tutorial

Source: Internet
Author: User
Tags curl fpm install php install brew install homebrew

Install homebrew

Homebrew is a very useful Package manager under the Mac, and automatically installs the dependent packages to free you from the cumbersome 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 #更新可安装包的最新信息, recommended to run before each installation
Brew Search Pkg_name #搜索相关的包信息
Brew Install Pkg_name #安装包
For more information, please refer to 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 _by Tes_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 contents,

<!–lang:shell–>
server {
Listen 8080;
server_name localhost;

root/users/user_name/nginx_sites/; # This item is to be modified for you to store the path to the relevant page

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 OS 10.9 's system has its own PHP and PHP-FPM, eliminating the hassle of installing PHP-FPM.
Here need to simply modify the configuration of the next php-fpm, otherwise run PHP-FPM will be an error.

<!–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, which is commented out by default, and it needs to be annotated 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 have an error when running PHP-FPM.

Close Php-fpm:sudo Killall php-fpm

Start: sudo php-fpm

installing MySQL

Installation

<!–lang:shell–>
Brew Install MySQL
Common commands

<!–lang:shell–>
Mysql.server Start #启动mysql服务
Mysql.server Stop #关闭mysql服务
Configuration

Running the Mysql_secure_installation script at the terminal, the script prompts you to set a series of security-related parameters, including setting the root password, turning off anonymous access, not allowing root users to remotely access, and removing the test database. Of course, before running the script, remember to start the MySQL service first.

Testing Nginx Services

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

<!–~/nginx_sites/index.php–>
<?php phpinfo ();?>
Start Nginx service, sudo nginx;

Modify the configuration file, restart the Nginx service, sudo nginx-s reload
Start PHP service, sudo php-fpm;
Enter localhost:8080 in the browser address bar, and if configured correctly, you should be able to see the pages of PHP-related information.

1, Brew search Nginx

2. Brew Install Nginx

Start Nginx, sudo nginx; visit localhost:8080 found Nginx Welcome page has appeared.

Remark: Ln-s/usr/local/sbin/nginx/usr/bin/nginx make a soft connection.
The common instructions are:
Nginx-v view version, and configuration file address
Nginx-v View Version
NGINX-C filename Specifies configuration file
Nginx-h Help

#重新加载配置 | reboot | stop | exit nginx

Nginx-s Reload|reopen|stop|quit

#打开 Nginx

sudo nginx

#测试配置是否有语法错误

Nginx-t

Additional attached Mac Install Brew command:

The installation commands are as follows:
CURL-LSSF Http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz-c/usr/local–strip 1

Once the brew has been successfully installed, you can install the software you want, such as wget, as follows:
sudo brew install wget
Uninstall, the command is as follows:
sudo brew uninstall wget
To view the installation software, the commands are as follows:
sudo brew search/apache*/
Note that the/apache*/is the regular expression used, used/split.

Related Article

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.