This article describes how to use brew to build a PHP (LNMPLAMP) development environment in Mac systems. This article describes how to use Brew to manually build a PHP development environment, including Apache, Nginx, PHP, MySQL, MongoDB, PHPMyAdm
This article describes how to use brew to build a PHP (LNMP/LAMP) development environment in Mac systems. This article describes how to use Brew to manually build a PHP development environment, including Apache, Nginx, PHP, MySQL, MongoDB, PHPMyAdm
It is easy to build a lamp development environment under Mac, and xampp and mamp are ready-made integrated environments. However, the integration environment is very troublesome for developers who often need to customize some configurations. In addition, the Mac itself comes with apache and php. With brew's help, it is very easy to set up manually and highly controllable.
Brew
Brew for mac, like apt-get for ubuntu, a good helper for installing software, cannot be more convenient...
The brew installation method is as follows:
The Code is as follows:
Ruby-e "$ (curl-fsSL https://raw.github.com/mxcl/homebrew/go/install )"
Brew common options
The Code is as follows:
Brew install xxx
Brew uninstall xxx
Brew list
Brew update xxx
Apache | Nginx
Apache
For Apache, mac is enough. My system is 10.9. You can use the following command to control Apache.
The Code is as follows:
Sudo apachectl start
Sudo apachectl restart
Sudo apachectl stop
The only change is the main directory. By default, mac has a directory named sites (SITE) under home. The access path is
The Code is as follows:
~ User_name
This is not suitable for development. Modify/etc/apache2/httpd. conf.
The Code is as follows:
DocumentRoot "/Users/username/Sites"
Options Indexes MultiViews
AllowOverride All
Order allow, deny
Allow from all
In this way, the sites directory is the root directory of the website, and all the code is lost.
Nginx
Nginx is easy to use. First, install
The Code is as follows:
Brew install nginx
Run the following command to disable Nginx: (To listen to port 80, run it as an administrator)
The Code is as follows:
# Enable nginx
Sudo nginx
# Reload Configuration | restart | stop | exit nginx
Nginx-s reload | reopen | stop | quit
# Test whether the configuration has syntax errors
Nginx-t
Configure Nginx
The Code is as follows:
Cd/usr/local/etc/nginx/
Mkdir conf. d
Modify Nginx configuration file
The Code is as follows:
Vim nginx. conf
The main modification location is the final include
The Code is as follows:
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;
}
Modify a custom file
The Code is as follows:
Vim./conf. d/default. conf
Add a listening port
The Code is as follows:
Server {
Listen 80;
Server_name localhost;
Root/Users/username/Sites/; # modify the path for storing the relevant webpage.
Location /{
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;
}
}
At this time, you cannot access the php site because php-fpm has not been enabled.
Although mac 10.9 comes with php-fpm, because we use the latest PHP and PHP comes with php-fpm, using PHP-fpm in php can ensure version consistency.
The command here is executed after the next php step is installed.
The Code is as follows:
Sudo nginx
Sudo php-fpm-D
PHP
PHP is installed on mac by default, but it is difficult to control the version. brew can be used to install the latest version on mac, or even multiple versions. I installed php5.5
The Code is as follows: