Apache和PHP已经在系统里面预装好了,只要你开启即可使用.这篇文章用来记录我Mac Book上PHP+Mysql开放环境的配置.
1.开启默认Apache服务
打开终端命令行,输入如下命令就会开启Apache了.然后输入top命令查看进程是否含有http。
sudo apachectl start
2.创建站点目录
sudo mkdir ~/Sites
3.修改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/Tan/Sites"
<Directory"/Users/Tan/Sites">
#
# 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.
#
OptionsFollowSymLinksMultiviews
MultiviewsMatchAny
#
# 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
#
AllowOverrideAll
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
4.安装Mysql
http://dev.mysql.com/downloads/mysql/ 下下载最新的dmg文件.
下载后安装,安装后可以在 系统偏好设置-> Mysql 打开mysql设置.
复制出一份。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
设置别名和密码
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'
mysqladmin -u root password "root"
5.安装phpMyAdmin
从http://www.phpmyadmin.net/home_page/downloads.php 下载最新版本,将其解压到/Users/Tan/Sites。然后将文件夹名字修改为phpmyadmin.
然后浏览器输入:http://localhost/phpmyadmin/setup/, 点击“新建服务器”.打开“认证”Tab,在Config认证方式的密码处输入mysql的root用户密码,其它都默认。然后点击“应用”.
输入http://localhost/phpmyadmin/ 就可以看到登陆phpmyadmin的界面了。 phpMyAdmin搞定。