osx系统预装了apache,查看apache版本:
命令:
sudo apachectl -v
结果:
leifdeMacBook-Pro:~ leif$ sudo apachectl -v
Server version: Apache/2.4.16 (Unix)
Server built: Aug 22 2015 16:51:57
命令:
sudo apachectl start #打开
sudo apachectl stop #关闭
sudo apachectl restart #重启
默认项目路径为/Library/WebServer/Documents
apache的httpd默认配置文件为/etc/apache2/httpd.conf
编辑此配置文件,修改以下配置项,将路径修改为你要设置的路径
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Library/WebServer/Documents" #修改路径
<Directory "/Library/WebServer/Documents"> #修改路径
此时如果直接访问localhost会出现403错误,因为httpd.conf中默认禁止了读取其他路径,所以应将其配置为可读取其他路径。
将下列配置项注释掉
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none #注释掉
Require all denied #注释掉
</Directory>
2.通过vhosts修改路径
打开vhosts功能
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf #取消注释
通过/etc/apache2/extra/httpd-vhosts.conf配置虚拟主机
添加配置项:
<VirtualHost *:80>
DocumentRoot "/Users/leif/work"
ServerName localhost
ErrorLog "/private/var/log/apache2/localhost-error_log"
CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost>
此时如果直接访问localhost会出现403错误,因为httpd.conf中默认禁止了读取其他路径,所以应将其配置为可读取其他路径。
将下列配置项注释掉
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none #注释掉
Require all denied #注释掉
</Directory>
下载MySQL Community Server,dmg版的最好
链接:
http://dev.mysql.com/downloads/mysql/
下载完成后双击打开安装
**!!!!!!!!!!!!!!!!!!!!
安装完成后会弹出提示目前的临时密码,打开mysql workbench新建链接,用户名root,密码为此临时密码,连接后提示修改密码,输入旧密码(临时密码),然后设置新密码。
!!!!!!!!!!!!!!!!!!!**
安装成功后,在系统设置地步会出现一个mysql,可以用来打开关闭mysql。
php为系统自带,我们只要手动打开即可:
修改apache配置文件,/etc/apache2/httpd.conf
查找php载入文件,并取消注释
#LoadModule php5_module libexec/apache2/libphp5.so #取消注释
下载地址:
http://www.phpmyadmin.net/downloads/
下载压缩包,解压。
将解压后的文件夹重命名为phpmyadmin复制到localhost的目录,
将config.sample.inc.php改名为config.inc.php
修改
$cfg['Servers'][$i]['host'] = 'localhost';
为
$cfg['Servers'][$i]['host'] = '127.0.0.1';
如果不将localhost修改为127.0.0.1则有可能登录时会提示无法登录。
设置加密字符串
$cfg['blowfish_secret'] = '****'; #****处为加密使用的字符串,可自由设置,如“phphphp”等等。