Mac MAMP 开发环境

2018-1-1.jpg

MAMP MAMP is meaning Mac Apache MySql Php

一、Apache 的配置(Mac 自带)

  1. 常用命令
 sudo apachectl start  //开启apache服务,检查是否真的开启了,可在浏览器输入localhost, 界面显示 It works!
 sudo apachectl stop  //停止apache服务
 sudo apachectl restart  //重启服务 
 httpd -v  //查看版本

在浏览器输入 localhost 可以看见

2018-2-27
  1. 更改程序目录
$ cd  /Users/emily/   //Emily是我自己的用户名,这里要改成自己的
$ open .  //打开这个目录,在这个目录下新建一个文件夹Sites
$ cd /etc/apache2/users/
$ ls  //查看该目录下的文件,有两个文件,有一个为用户名.conf
$ sudo vim emily.conf  //这里要改成自己的
<Directory "/Users/emily/Sites/">
        Options Indexes MultiViews
        Require all granted
</Directory>
$ sudo chmod 644 emily.conf //修改这个文件的权限为644 
  1. 修改 httpd.conf 文件
$ cd /etc/apache2/
$ open .
$ sudo vim httpd.conf

找到 httpd.conf 文件,用 Sublime 打开,找到下面这两行把前面的#去掉

# LoadModule userdir_module libexec/apache2/mod_userdir.so 
# Include /private/etc/apache2/extra/httpd-userdir.conf 

找到 httpd-userdir.conf 文件,找到'' # Include /private/etc/apache2/users/*.conf ''这行把#去掉

$ cd /etc/apache2/extra/
$ open .
$ sudo vim httpd-userdir.conf 

结果:

sudo apachectl restart //重启apache

浏览器输入: loacal/~Emily/

2018-2-27

二、MySql 的配置

$ brew info mysql
$ brew install mysql
$ brew tap homebrew/services
$ brew services start mysql
$ brew services list
$ mysql -V
mysql  Ver 14.14 Distrib 5.7.20, for osx10.13 (x86_64) using  EditLine wrapper
$ mysqladmin -u root password 'yourpassword'

配置 root 密码时遇到的问题

$ mysqladmin -u root password '123456'
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)
$ mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
$ ALTER USER 'rooot'@'localhost' IDENTFIED BY '123456'
-bash: ALTER: command not found

解决方法

mac-mini:~ emily$ mysql
-bash: mysql: command not found
mac-mini:~ emily$ mysql -v
-bash: mysql: command not found
mac-mini:~ emily$ brew uninstall mysql
Uninstalling /usr/local/Cellar/mysql/5.7.21... (323 files, 233.9MB)
mac-mini:~ emily$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.21.high_sierra.bo
Already downloaded: /Users/emily/Library/Caches/Homebrew/mysql-5.7.21.high_sierra.bottle.tar.gz
==> Pouring mysql-5.7.21.high_sierra.bottle.tar.gz
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql/5.7.21: 323 files, 233.9MB
mac-mini:~ emily$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

三、Php配置

$ cd /etc/apache2/
 $ open .
用 Sublime 打开文件,找到下面这一行,去掉#
#LoadModule php7_module libexec/apache2/libphp7.so   //把#去掉即可,7不是固定的,看你的版本是多少
$ cd
$ sudo apachectl restart
2018-2-27

四、PhpMyAdmin的配置

  1. 下载
  2. 解压文件夹命名为PhpMyAdmin,并存储到/Users/emily/Sites/目录下
$ cd  /Users/emily/Sites/PhpMyAdmin
$ mkdir config
$ chmod o+w config 

打开浏览器,输入http://localhost/~emily/phpmyadmin/setup/

2018-2-27

保存配置之后,删除 config 文件在浏览器输入http://localhost/~emily/phpmyadmin/

2018-2-27

五、我踩过的那些坑

  1. phpMyAdmin登录问题
 #2002 - No such file or directory &mdash; 服务器没有响应(或本地服务器的套接字没有正确设置)

解决方法:

cd /Users/emily/Sites/phpmyadmin/  //Emily是我的用户名
open .

打开之后找到config.inc.php,这句
cfg['Servers'][i]['host'] = 'localhost';
改成
cfg['Servers'][i]['host'] = '127.0.0.1';
进入phpmyadmin下面的libraries文件夹,打开config.default.php,
cfg['Servers'][i]['host'] = 'localhost';
改成
cfg['Servers'][i]['host'] = '127.0.0.1';

  1. 我装好了 phpMyAdmin后,遇见了 MAMP pro。只想说不走过弯路是不会遇见捷径的。

  2. mysql 命令行不熟悉的,可以下载Sequel pro做辅助。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,948评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,371评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,490评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,521评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,627评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,842评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,997评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,741评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,203评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,534评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,673评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,339评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,955评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,770评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,000评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,394评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,562评论 2 349

推荐阅读更多精彩内容