Use homebrew to install and configure Nginx, MySQL, PHP environment tutorials

Source: Internet
Author: User
Tags fpm memcached mkdir php and mysql php cli


The installation of homebrew is outlined in the "Mac OS X Mavericks 10.9 Installation and configuration homebrew". We can use it here. Mac defaults to Apache, PHP, but these versions are older. And if you want to use the Nginx, the new version of PHP and MySQL, using homebrew to install is a good choice. And these software versions in the constant update, so some configuration is also changing, but according to homebrew in the installation process prompts always smooth installation of this configuration.

Install Nginx


mac-mini:~ weiz$ Brew Install Nginx
...
Docroot is:/usr/local/var/www

The default port has been set in/usr/local/etc/nginx/nginx.conf to 8080
Nginx can run without sudo.

To have launchd start nginx at login:
Ln-sfv/usr/local/opt/nginx/*.plist ~/library/launchagents
Then to load Nginx now:
Launchctl Load ~/library/launchagents/homebrew.mxcl.nginx.plist
Or, if you don ' t want/need Launchctl, can just run:
Nginx

mac-mini:~ weiz$ ln-sfv/usr/local/opt/nginx/*.plist ~/library/launchagents
/users/weiz/library/launchagents/homebrew.mxcl.nginx.plist->/usr/local/opt/nginx/homebrew.mxcl.nginx.plist
mac-mini:~ weiz$ sudo chown root:wheel/usr/local/cellar/nginx/1.4.4/bin/nginx
Password:
mac-mini:~ weiz$ sudo chmod u+s/usr/local/cellar/nginx/1.4.4/bin/nginx
mac-mini:~ weiz$ vim/usr/local/etc/nginx/nginx.conf
mac-mini:~ weiz$ sudo nginx

installing MySQL


mac-mini:~ weiz$ Brew Info MySQL
Mysql:stable 5.6.14 (bottled)
http://dev.mysql.com/doc/refman/5.6/en/
Conflicts with:mariadb, Mysql-cluster, Percona-server
Not installed
From:https://github.com/mxcl/homebrew/commits/master/library/formula/mysql.rb
==> dependencies
Build:cmake✘
==> Options
--enable-debug
Build with Debug support
--enable-local-infile
Build and local infile loading support
--enable-memcached
Enable innodb-memcached Support
--universal
Build a Universal Binary
--with-archive-storage-engine
Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
Compile with the Blackhole storage engine enabled
--with-embedded
Build the embedded server
--with-tests
Build with Unit tests
==> Caveats
A "/etc/my.cnf" from another install could interfere with a homebrew-built
Server starting up correctly.

To connect:
Mysql-uroot

To have launchd start MySQL at login:
Ln-sfv/usr/local/opt/mysql/*.plist ~/library/launchagents
Then to load MySQL now:
Launchctl Load ~/library/launchagents/homebrew.mxcl.mysql.plist
Or, if you don ' t want/need Launchctl, can just run:
Mysql.server start
mac-mini:~ weiz$ Brew Install MySQL
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.1
...
==> Pouring mysql-5.6.14.mavericks.bottle.tar.gz
==>/usr/local/cellar/mysql/5.6.14/bin/mysql_install_db--verbose--user=weiz
==> Caveats
A "/etc/my.cnf" from another install could interfere with a homebrew-built
Server starting up correctly.

To connect:
Mysql-uroot

To have launchd start MySQL at login:
Ln-sfv/usr/local/opt/mysql/*.plist ~/library/launchagents
Then to load MySQL now:
Launchctl Load ~/library/launchagents/homebrew.mxcl.mysql.plist
Or, if you don ' t want/need Launchctl, can just run:
Mysql.server start

Configure MySQL random start service:

mac-mini:~ weiz$ ln-sfv/usr/local/opt/mysql/*.plist ~/library/launchagents
/users/weiz/library/launchagents/homebrew.mxcl.mysql.plist->/usr/local/opt/mysql/homebrew.mxcl.mysql.plist

Start MySQL:

mac-mini:~ weiz$ mysql.server Start
Starting MySQL
. success!

Installing PHP


mac-mini:~ weiz$ Brew tap homebrew/dupes &&brew tap homebrew/php
mac-mini:~ weiz$ Brew Install php55--with-debug--with-fpm--with-gmp--with-homebrew-openssl--with-imap--with-intl-- With-libmysql--without-bz2--without-mysql--without-pcntl--without-pear
...
==> Installing PHP55
...
==> Caveats
The php.ini file can is found in:
/usr/local/etc/php/5.5/php.ini

✩✩✩✩extensions (Note: Configure PHP According to the following prompts) ✩✩✩✩

If you are have issues with custom extension compiling, ensure that
You are are using the brew version, by Placing/usr/local/bin Before/usr/sbin in your PATH:

Path= "/usr/local/bin: $PATH"

PHP55 Extensions'll always be compiled against this PHP. Please install them
Using--without-homebrew-php to enable compiling against system PHP.

✩✩✩✩php Cli✩✩✩✩

If you are wish to swap the PHP with the command line, you should add the following to ~/.BASHRC,
~/.ZSHRC, ~/.profile or your shell ' s equivalent configuration file:

Export Path= "$ (Brew--prefix josegonzalez/php/php55)/bin: $PATH"

✩✩✩✩fpm✩✩✩✩

To launch PHP-FPM (Configure the PHP-FPM random boot service According to the following prompts) on startup:
* If is your-a-install:
Mkdir-p ~/library/launchagents
Cp/usr/local/cellar/php55/5.5.6/homebrew-php.josegonzalez.php55.plist ~/library/launchagents/
Launchctl load-w ~/library/launchagents/homebrew-php.josegonzalez.php55.plist

* If This is a upgrade and you already have the Homebrew-php.josegonzalez.php55.plist loaded:
Launchctl unload-w ~/library/launchagents/homebrew-php.josegonzalez.php55.plist
Cp/usr/local/cellar/php55/5.5.6/homebrew-php.josegonzalez.php55.plist ~/library/launchagents/
Launchctl load-w ~/library/launchagents/homebrew-php.josegonzalez.php55.plist

The control script is located at/usr/local/cellar/php55/5.5.6/sbin/php55-fpm

Mountain Lion comes with php-fpm pre-installed, to ensure your are using the brew version you need to make sure/usr/local/ Sbin is before/usr/sbin in your PATH:

Path= "/usr/local/sbin: $PATH"

You may also need to edit the plist to use the correct "UserName".

Please note that the plist is called ' org.php-fpm.plist ' in old versions
of this formula.
Add PHP to the random start service:
To have launchd start php55 at login:
Ln-sfv/usr/local/opt/php55/*.plist ~/library/launchagents
Then to load Php55 now:
Launchctl Load ~/library/launchagents/homebrew.mxcl.php55.plist
==> Summary
/usr/local/cellar/php55/5.5.6:306 files, 39M, built in 4.6 minutes

Configure the PHP environment based on installation information


mac-mini:~ weiz$ Vim ~/.profile
Export Path= "$ (Brew--prefix josegonzalez/php/php55)/bin: $PATH"
mac-mini:~ weiz$ Source ~/.profile
mac-mini:~ weiz$ Vim ~/.BASHRC
Export Path= "$ (Brew--prefix josegonzalez/php/php55)/bin: $PATH"
mac-mini:~ weiz$ Source ~/.BASHRC
mac-mini:~ weiz$ mkdir-p ~/library/launchagents
mac-mini:~ weiz$ cp/usr/local/cellar/php55/5.5.6/homebrew-php.josegonzalez.php55.plist ~/Library/LaunchAgents/
mac-mini:~ weiz$ launchctl load-w ~/library/launchagents/homebrew-php.josegonzalez.php55.plist
mac-mini:~ weiz$ ln-sfv/usr/local/opt/php55/*.plist ~/library/launchagents
/users/weiz/library/launchagents/homebrew-php.josegonzalez.php55.plist->/usr/local/opt/php55/ Homebrew-php.josegonzalez.php55.plist

Configure Nginx


mac-mini:~ weiz$ vim/usr/local/etc/nginx/nginx.conf

#user nobody;
Worker_processes 1;
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info;
#pid Logs/nginx.pid;

Events {
Worker_connections 1024;
}

HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Client_max_body_size 20m; # #可以根据自己的实际需要去定义上传附件的大小
#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 Logs/access.log Main;

Sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
Keepalive_timeout 65;

#gzip on;

server {
Listen 80;
server_name localhost;

#charset Koi8-r;

#access_log Logs/host.access.log Main;

Location/{
root HTML;
Index index.php index.html index.htm;
}

#error_page 404/404.html;

# REDIRECT Server error pages to the static page/50x.html
#
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}

# Proxy The PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# Proxy_pass http://127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
Location ~ \.php$ {
root HTML;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Fastcgi_param Script_filename/usr/local/var/www$fastcgi_script_name;
Include/usr/local/etc/nginx/fastcgi_params;
}
# Deny access to. htaccess files, if Apache ' s document Root
# concurs with Nginx ' s one
#
#location ~/\.ht {
# Deny All;
#}
}
# Another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# Listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;
# location/{
# root HTML;
# index index.html index.htm;
#    }
#}
# HTTPS Server
#
#server {
# Listen 443;
# server_name localhost;

# SSL on;
# ssl_certificate Cert.pem;
# Ssl_certificate_key Cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers high:!anull:! MD5;
# ssl_prefer_server_ciphers on;

# location/{
# root HTML;
# index index.html index.htm;
#    }
#}

}
mac-mini:~ weiz$ nginx-s Reload #重启nginx

Here, the installation is basically finished, if you need to manage some of the client tools to manage MySQL, open source free Sequelpro is a very good choice.

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.