美文网首页
MAMP 开发环境

MAMP 开发环境

作者: 喜欢书的女孩 | 来源:发表于2018-02-28 19:18 被阅读383次
    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做辅助。

    相关文章

      网友评论

          本文标题:MAMP 开发环境

          本文链接:https://www.haomeiwen.com/subject/euesvxtx.html