Apache和PHP已经在系统里面预装好了,只要你开启即可使用。这篇文章给大家介绍如何开启并设置好PHP开发环境。
1.开启默认Apache服务
打开终端命令行,输入如下命令就会开启Apache了.然后输入top命令查看进程是否含有http。
sudo apachectl start
2.修改Apache配置文件
在Finder右键点击“前往文件夹”后输入“/etc/apache2/ ”然后打开httpd.conf。我们要修改开启PHP组件和虚拟目录。
去掉在168、169行的#号
LoadModule rewrite_module libexec/apache2/mod_rewrite.so LoadModule php5_module libexec/apache2/libphp5.so
211行前面加上#号
#Require all denied
修改默认目录
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
#默认目录 <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>
3.修改HOSTS文件
在Finder右键点击“前往文件夹”后输入“/etc ”然后打开hosts。
#工具 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
4.安装MYSQL
到官网下载:http://dev.mysql.com/downloads/mysql/ 选DMG格式的就好了。他会帮你一键安装好。
复制出一份。php.ini
cp /etc/php.ini.default /etc/php.ini
创建mysql socket(不设置这个无法连接phpmyadmin)
sudo mkdir /var/mysql sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
然后修改php.ini中的内容(原因是连接时候php默认去找/var/mysql/mysql.sock了,但是MAC版本的MYSQL改动了文件的位置,放在/tmp下了。)
mysql.default_socket = /tmp/mysql.sock
设置别名和密码
alias mysql=‘/usr/local/mysql/bin/mysql‘ alias mysqladmin=‘/usr/local/mysql/bin/mysqladmin‘ mysqladmin -u root password "123456"
时间: 2024-10-14 17:52:09