Apache和PHP已经在系统里面预装好了,只要你开启即可使用。这篇文章给大家介绍如何开启并设置好PHP开发环境。
打开终端命令行,输入如下命令就会开启Apache了.然后输入top命令查看进程是否含有http。
| 
					 1  | 
						sudo apachectl start  | 
					
在Finder右键点击“前往文件夹”后输入“/etc/apache2/ ”然后打开httpd.conf。我们要修改开启PHP组件和虚拟目录。
去掉在168、169行的#号
| 
					 1 2  | 
						LoadModule rewrite_module libexec/apache2/mod_rewrite.so LoadModule php5_module libexec/apache2/libphp5.so  | 
					
211行前面加上#号
| 
					 1  | 
						#Require all denied  | 
					
修改默认目录
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  | 
						DocumentRoot "/Users/wise/site/default" <Directory "/Users/wise/site/default">     #     # Possible values for the Options directive are "None", "All",     # or any combination of:     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews     #     # Note that "MultiViews" must be named *explicitly* --- "Options All"     # doesn't give it to you.     #     # The Options directive is both complicated and important.  Please see     # http://httpd.apache.org/docs/2.4/mod/core.html#options     # for more information.     #     Options FollowSymLinks Multiviews     MultiviewsMatch Any     #     # AllowOverride controls what directives may be placed in .htaccess files.     # It can be "All", "None", or any combination of the keywords:     #   AllowOverride FileInfo AuthConfig Limit     #     AllowOverride All     #     # Controls who can get stuff from this server.     #     Require all granted </Directory>  | 
					
虚拟目录,修改文件/etc/apache2/extra/httpd-vhosts.conf
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  | 
						#默认目录 <VirtualHost *:80>     DocumentRoot "/Users/wise/site/default"     ServerName default </VirtualHost> #工具 <VirtualHost *:80>     DocumentRoot "/Users/wise/site/db"     ServerName db </VirtualHost> #个人项目 <VirtualHost *:80>     DocumentRoot "/Users/wise/site/jinzhe"     ServerName jinzhe     <Directory "/Users/wise/site/jinzhe">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost> <VirtualHost *:80>     DocumentRoot "/Users/wise/site/yckit"     ServerName yckit     <Directory "/Users/wise/site/yckit">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost> <VirtualHost *:80>     DocumentRoot "/Users/wise/site/dmku"     ServerName dmku     <Directory "/Users/wise/site/dmku">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost> #私人项目 <VirtualHost *:80>     DocumentRoot "/Users/wise/site/sms"     ServerName sms </VirtualHost> <VirtualHost *:80>     DocumentRoot "/Users/wise/site/icrobot"     ServerName icrobot     <Directory "/Users/wise/site/icrobot">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost> <VirtualHost *:80>     DocumentRoot "/Users/wise/site/lbdlq"     ServerName lbdlq     <Directory "/Users/wise/site/lbdlq">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost> <VirtualHost *:80>     DocumentRoot "/Users/wise/site/baidu"     ServerName baidu     <Directory "/Users/wise/site/baidut">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost> #公司项目 <VirtualHost *:80>     DocumentRoot "/Users/wise/site/fishernuts"     ServerName fishernuts     <Directory "/Users/wise/site/fishernuts">         Options FollowSymLinks         AllowOverride All         Require all granted     </Directory> </VirtualHost>  | 
					
在Finder右键点击“前往文件夹”后输入“/etc ”然后打开hosts。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  | 
						#工具 127.0.0.1 db #个人项目 127.0.0.1 jinzhe 127.0.0.1 dmku 127.0.0.1 yckit 127.0.0.1 yckit.api #私单项目 127.0.0.1 sms 127.0.0.1 icrobot 127.0.0.1 lbdlq 127.0.0.1 baidu 127.0.0.1 jcm #公司项目 127.0.0.1 fishernuts  | 
					
到官网下载:http://dev.mysql.com/downloads/mysql/ 选DMG格式的就好了。他会帮你一键安装好。
复制出一份。php.ini
| 
					 1  | 
						cp /etc/php.ini.default /etc/php.ini  | 
					
创建mysql socket(不设置这个无法连接phpmyadmin)
| 
					 1 2  | 
						sudo mkdir /var/mysql  sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock  | 
					
然后修改php.ini中的内容(原因是连接时候php默认去找/var/mysql/mysql.sock了,但是MAC版本的MYSQL改动了文件的位置,放在/tmp下了。)
| 
					 1  | 
						mysql.default_socket = /tmp/mysql.sock  | 
					
设置别名和密码
| 
					 1 2 3  | 
						alias mysql='/usr/local/mysql/bin/mysql' alias mysqladmin='/usr/local/mysql/bin/mysqladmin' mysqladmin -u root password "123456"  |