Build PHP's development environment in Mac
1. Apach----recommended with Mamp. You just have to put your PHP file/project into the Htdocs (/applications/mamp/htdocs) directory, start MAMP, enter localhost to see all the files in your directory directly. -because of this relatively simple, here no longer repeat, if any problem, welcome to contact the exchange.
2. Nginx----Because there is no inherited tool, the configuration of Nginx relative Apach is relatively complex. For example, you need to download MySQL, download php-fpm, and even use homebrew to install it. (My instructions below are based on the homebrew installation scenario) Here I briefly explain a few things that require special attention:
Configuration of 2.1 Nginx
What needs to be explained is the configuration of conf file server under/usr/local/etc/nginx , fastcgi_param option, note When adding $document_root, as shown below: Actually, the following $ Document_root$fastcgi_script_name is consistent with the values inside the fastcgi.conf.
server {Listen 80; server_name localhost; Specify your domain name #charset koi8-r; #access_log Logs/host.access.log Main; Location/{root/users/megan/www/;//Specify the path of your project index 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$ {# ProX Y_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 $document _root$fastcgi_script_name; Include Fastcgi_params; } # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #location ~/\.ht {# deny all; #} }
2.2 MySQL Configuration
This article is caused by MySQL, here is simple to talk about the simple MySQL command.
Start--Mysql.server start
Close--Mysql.server stop
Restart --mysql.server Restart
Connect--Mysql-uroot or mysql-uroot-p (here is the password)
Import data--Source: /*.sql
Configuration of the 2.3 php-fpm
The most depressing thing about this stuff is that I didn't find a good reboot and shutdown command. For example Nginx start with sudo nginx, close with sudo nginx-s-stop re-enable sudo nginx-s reload. But php-fpm I only use sudo php-fpm to start. The way off is simply rude.
I first use PS aux|grep php to see which PHP processes are running and then execute the kill PHP-FPM related process. For example, the following results are executed (sudo) kill 3870 3871 3872. Once again, you will see that these processes are gone. (If any colleague has a better approach and can show the way, than the woman will be greatly appreciated)
[[email protected]:~] $ps aux|grep phpmegan 1338 4.6 7.4 1824760 389504?? S 10:51am 23:40.56/applications/zend-eclipse-php/zend-eclipse-php.app/contents/macos/zend-eclipse-php-os MacOSX- WS Cocoa-arch x86-launcher/applications/zend-eclipse-php/zend-eclipse-php.app/contents/macos/zend-eclipse-php- Name Zend Eclipse for PHP developers--launcher.library/applications/zend-eclipse-php/zend-eclipse-php.app/contents/ macos//. /.. /.. /plugins/org.eclipse.equinox.launcher.cocoa.macosx_1.1.200.v20120522-1813/eclipse_1503.so-startup/applications /zend-eclipse-php/zend-eclipse-php.app/contents/macos//. /.. /.. /plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar--launcher.overridevmargs-showlocation-launcher/ applications/zend-eclipse-php/zend-eclipse-php.app/contents/macos/zend-eclipse-php-showlocation-data/users/ Megan/www-launcher/applications/zend-eclipse-php/zend-eclipse-php.app/contents/macos/zend-eclipse-php- Showlocation-keyring/users/megan/.ECLIPSE_KEYRING-SHOWLOCATION-VM/SYSTEM/LIBRARY/FRAMEWORKS/JAVAVM.FRAMEWORK-VMARGS-XMS128M-XMX512M- djava.awt.headless=true-xstartonfirstthread-dorg.eclipse.swt.internal.carbon.smallfonts-xdock:icon=. /resources/eclipse.icns-xx:maxpermsize=256mmegan 3981 0.4 0.0 2442000 628 s001 s+ 6:48pm 0:00.01 gr EP Phpnobody 3872 0.0 0.2 2481552 12008?? S 5:57pm 0:05.74 php-fpmnobody 3871 0.0 0.2 2481552 12748?? S 5:57pm 0:01.09 php-fpmroot 3870 0.0 0.0 2464912 592?? Ss 5:57pm 0:00.23 php-fpm
back to the question
In fact, the problem is very simple, just need to find your mysql.sock and then go back to your php.ini to modify a configuration just fine. The main is the following three lines of code.
Pdo_mysql.default_socket=/tmp/mysql.sock//If you are using zendframework, this needs to be configured
The following two items are configured if you are using OpenCart, etc. and do not use PDO. Mysql.default_socket =/tmp/mysql.sock Mysqli.default_socket =/tmp/mysql.sock
The only thing that's actually done is to configure the Mysql.sock to Default_socket.
In fact, the main problem here is how you find your mysql.sock, how to find your php.ini. Play so on the Mac, in addition to doing iOS development, whether it is playing Java or PHP or other, the most depressing thing is to find the relevant configuration file. What Whereis,locate,which and so on have used all over, often still can't find document, that kind of pain, don't want to say more.
The easiest way to find php.ini--to build a file, Phpinfo () will make the world a wonderful place.
Find Mysql.sock-You might use Mysqladmin viriables to see all of MySQL's parameters, and you may find that Mysql.sock's path points to/tmp/ Mysql.sock, but you can't find the file, even though you can't see the file in all the hidden files.
Then you can execute sudo find/-name mysql.sock It will tell you that in fact your mysql.sock is here in Private/tmp/mysql.sock. Then you might want to use this line of code to build a shortcut.
Ln-s/private/tmp/mysql.sock/tmp/mysql.sock
OK, yes, maybe it will remind you that the file already exists. It doesn't matter, ignore it, although you still can't see Mysql.sock in/tmp. You just have to use it. I don't know which corner I can't see anymore. In short, there is a mysql.sock shortcut under/tmp for you to use.
Mysql_connect (): [2002] No such file or directory