It is easy to build a lamp development environment under Mac, with XAMPP and mamp ready-made integrated environments. But an integrated environment can be cumbersome for developers who often need to customize some configuration, and the Mac itself comes with Apache and PHP, which is easy to manually build with the help of brew, and is highly controllable.
Brew
Brew for Mac, like Apt-get for Ubuntu, a good helper to install software, not more convenient ...
Brew is installed in the following ways:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
Brew Common options
brew install xxxbrew uninstall xxxbrew list brew update xxx
Apache | | Nginxapache
Apache words using Mac comes with basic enough, my system is 10.9, you can use the following command to control Apache
sudo apachectl startsudo apachectl restartsudo apachectl stop
The only thing to change is the home directory, Mac default in the home has a sites (site) directory, Access Path is
http://localhost/~user_name
This is not suitable for development, modify the /etc/apache2/httpd.conf
content
DocumentRoot< Span class= "PLN" > "/users/username/sites" < directory /> Options indexes multiviews allowoverride all Span class= "Typ" >order Allow,deny allow< Span class= "PLN" > from All</directory< Span class= "pun" >>
So the sites directory is the root directory of the site, the code to this head lost
Nginx
To use Nginx is also more convenient, first installed
brew install nginx
The command to start the Nginx shutdown is as follows (if you want to listen on port 80, you must run as Administrator)
#打开 nginxsudo nginx#重新加载配置|重启|停止|退出 nginxnginx -s reload|reopen|stop|quit#测试配置是否有语法错误nginx -t
Configure Nginx
cd /usr/local/etc/nginx/mkdir conf.d
modifying Nginx configuration Files
vim nginx.conf
The main modification location is the last include
Worker_processes1;Error_log/Usr/Local/Var/Log/Nginx/Error.Log warn;Pid/Usr/Local/Var/Run/Nginx.Pid;Events{Worker_connections256;}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< Span class= "pun". log main; Port_in_redirect off;; keepalive_timeout 65; include /usr/local /etc/nginx/ conf./*.conf;}
Modify a custom file
vim ./conf.d/default.conf
Add a listening port
Server{Listen80;server_name localhost;Root/Users/Username/Size=/; # This item needs to be changed to the path where you want to store the relevant pageLocation/ {Index Index.Php;AutoIndex on; } #proxy the PHP scripts to php-fpm location ~< Span class= "PLN" > \.php$ { include /usr< Span class= "pun" >/local/etc/ nginx/fastcgi. Conf; fastcgi_intercept_errors on;127.0. 0.1:9000; } } /span>
The PHP site cannot be accessed at this time because PHP-FPM is not yet open.
Although Mac 10.9 comes with PHP-FPM, we use PHP-FPM in PHP to keep the version consistent because we are using the latest php,php php-fpm.
The commands here are executed after the next PHP installation is completed.
sudo nginxsudo php-fpm -D
Php
PHP is installed by default under Mac, but it is not easy to control the version, the use of brew can be installed under the latest version of Mac, or even multiple versions, I installed php5.5
brew updatebrew tap homebrew/dupesbrew tap josegonzalez/homebrew-php# brew install php55 --with-fpm #Nginxbrew install php55 #Apache
Then modify the PHP CLI path and the PHP module used by Apache. Add the following in. bashrc or. ZSHRC
#export PATH="$(brew --prefix josegonzalez/php/php55)/bin:$PATH" export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
Replace the PHP version of the system default CLI with the PHP you just installed. Then /etc/apache2/httpd.conf
add it under the
LoadModule php5_module /usr/local/Cellar/php55/5.5.8/libexec/apache2/libphp5.so
This also modifies the PHP version used by Apache.
MONGO and MySQL are used later, so you can install the PHP module directly with the following command, and the other modules are similar
brew install php55-mysqlbrew install php55-mongo
Mysql
Mac does not own MySQL, here need to reinstall, the method is still very simple
Brew Install Mysqlunset tmpdirmysql_install_db--Verbose--user= ' whoami ' --basedir= "$ (brew--prefix MySQL)" --datadir=/usr/local/var/mysql --tmpdir=/tmpsudo chown -r your_user /usr/< Span class= "KWD" >local/var/mysql/
The first sentence is the installation, the following is to ensure normal use. And then the start command.
mysql.server start
It's a good idea to set a password for MySQL by:
mysqladmin -u root password ‘xxx‘
If you want to modify the configuration of MySQL, /usr/local/etc
create one under my.cnf
, for example, add log
[mysqld]general-loggeneral_log_file = /usr/local/var/log/mysqld.log
Mongodb
MongoDB can be said to be the simplest one, directly executed
brew install mongodb
Start method
mongod --fork
PHPMyAdmin
phpMyAdmin is almost the easiest web app to manage MySQL, and every time I put it on.
- Go to the official website to download the latest version
- Unzip to the ~/sites/phpmyadmin.
- Create a writable config directory under the phpMyAdmin directory
- Open Http://localhost/phpmyadmin/setup, install a service, last save (here only need to enter the account password is enough)
- Move the config.inc.php generated under Config to the phpMyAdmin root directory
- Delete Config
This will be installed, although it may be a little complicated, but once you get used to it.
This is likely to encounter 2002 errors, that is, the mysql.sock problem can not be found, the following method to solve
sudo mkdir /var/mysqlsudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Rockmongo
Rockmongo is a very useful Web application for MongoDB, and it is easy to install
- Go to the official website to download the latest version
- Unzip to the ~/sites/rockmongo.
- You can run Http://localhost/rockmongo
Complete
This will be configured under the Mac good one PHP development environment, enjoy it!
Reference
- Hot-to-install Nginx, php-fpm 5.5.6, MONGO and MYSQL on Mac with homebrew
- Mac OSX 10.9 Builds NGINX+MYSQL+PHP-FPM environment
Use Brew to build PHP (LNMP/LAMP) development environment under Mac