Mac installs Nginx+php+mysql environment with brew

Source: Internet
Author: User
Tags fpm install php mkdir

These two days reinstall under the Mac system under the NGINX+PHP+MYSQL environment, today to clean up the installation steps:

1. Installation Homebrew

Ruby-e "$ (curl-fssl https://raw.github.com/Homebrew/homebrew/go/install)"
As simple as that, a single command can complete the homebrew installation.

References: http://brew.sh/index_zh-cn.html

2. Installation Nginx

Brew Install Nginx
After the brew execution completes, the Nginx is installed successfully.

Nginx Operation Command:

#打开 Nginx
sudo nginx
#重新加载配置 | reboot | stop | exit nginx
Nginx-s Reload|reopen|stop|quit
#测试配置是否有语法错误
Nginx-t
After starting the Nginx, the default is 8080 port, which can be set by modifying the configuration file:
Vim/usr/local/etc/nginx/nginx.conf
Default Access directory:
/usr/local/cellar/nginx/1.4.7/html
The Nginx version I installed here is 1.4.7.

After installing Nginx, Nginx will not start randomly, need to set up.

Setup Nginx Boot:

Mkdir-p ~/library/launchagents
Cp/usr/local/cellar/nginx/1.4.7/homebrew.mxcl.nginx.plist ~/library/launchagents/
Launchctl load-w ~/library/launchagents/homebrew.mxcl.nginx.plist
To set permissions:
sudo chown Root:wheel/usr/local/cellar/nginx/1.4.7/bin/nginx
sudo chmod u+s/usr/local/cellar/nginx/1.4.7/bin/nginx
OK, here we have successfully installed the Nginx and set the boot up.

3, install MySQL

Brew Install MySQL
To configure the MySQL database:
mysql_install_db--verbose--user= ' WhoAmI '--basedir= "$ (brew--prefix MySQL)"--datadir=/usr/local/var/mysql--tmpdir =/tmp
After the execution is complete, you can run the MySQL command in the terminal.

Here we need to pay attention to, we can enter MySQL without a password, you can use some security settings, set user password to ensure security.

Set up MySQL boot:

Mkdir-p ~/library/launchagents/
Cp/usr/local/cellar/mysql/5.6.17/homebrew.mxcl.mysql.plist ~/library/launchagents/
Launchctl load-w ~/library/launchagents/homebrew.mxcl.mysql.plist
MySQL configuration file:
/usr/local/cellar/mysql/5.6.17/my.cnf
At this point, MySQL installation is complete.

4. Install PHP

Mac was already with PHP, but many extensions were not installed, so you chose to reinstall PHP.

First, we need to install a Third-party package. Www.111cn.net

Brew Tap Homebrew/dupes
Brew Tap josegonzalez/homebrew-php
We can look at the next brew with those PHP versions
Brew Search PHP
Brew Install PHP54--with-imap--with-tidy--with-debug--with-pgsql--with-mysql--with-fpm
More PHP options can be viewed with the following command:
Brew Options PHP54
Because it is a reload of PHP, before the system pre-installed PHP has not been uninstalled, so in the terminal invoke PHP, or the system before the PHP version to do parsing, so here need to modify path, specify the resolution of PHP path. Add the last line to the ~/.BASHRC (not created):
Export Path= "$ (Brew--prefix php54)/bin: $PATH"
Execute source to make it effective
source./.profile
PHP configuration file:
/usr/local/etc/php/5.4/php.ini
PHP-FPM configuration file:
/usr/local/etc/php/5.4/php-fpm.conf
Start PHP-FPM the word directly in the terminal to perform "PHP-FPM", the default open PHP-FPM will show a state shell out, you can also php-fpm configuration file "daemonize = no" to "daemonize = yes", Will be started as a background daemon, for the configuration file just modified, you can perform "php-fpm-t" to detect the configuration has no problem.

Boot php-fpm:

Mkdir-p ~/library/launchagents
Cp/usr/local/cellar/php54/5.4.26/homebrew-php.josegonzalez.php54.plist ~/library/launchagents/
Launchctl load-w ~/library/launchagents/homebrew-php.josegonzalez.php54.plist
5, set the configuration of Nginx php-fpm

The following is the Nginx configuration file where you configure your virtual machine:

server {
Listen 80;
server_name www.test.com;

root/users/sumw/www/www.test.com;
Index index.html index.htm index.php;

Location/{
Try_files $uri $uri//index.php;
}

Location ~. php$ {
Try_files $uri = 404;

Include fastcgi.conf;
Fastcgi_pass 127.0.0.1:9000;
}

}
At this point, our nginx+php+mysql environment is complete.

But there seems to be a problem here, after the Mac reboot, PHP is back to its own version of PHP, the workaround:

Adjust the path order:

Www.111cn.net

ls-al/usr/local/bin/php
/usr/local/bin/php->. /cellar/php54/5.4.19/bin/php
Adjust the/usr/local/bin to the first place.
Cat ~/.bash_profile
Export Path=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

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.