RaspberryPi 3B 搭建LAMP环境+phpMyAdm

2017-12-10  本文已影响0人  随心云

准备:

硬件:树莓派3B
系统:raspbian (2017-09版)

由于树莓派自带的官方源速度太慢,这里需要更换国内源

$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak  #备份为 sources.list.bak
$ sudo nano /etc/apt/sources.list     #编辑sources.list  文件

进入编辑页面,把原有的修改为

deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ wheezy main non-free contrib
deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ wheezy main non-free contrib

安装 LAMP 环境:

$ sudo apt-get update       #更新

$ sudo apt-get install apache2  #安装 LAMP 环境

$ sudo apt-get install mysql-server mysql-client

$ sudo apt-get install php7.0 php7.0-gd php7.0-mysql    

安装完毕后,网页存放路径为/var/www/html目录下,放入test.php文件测试一下是否可以 。

安装 phpMyAdmin

$ sudo apt-get install phpmyadmin

安装过程中弹出选择框
第一次的弹框有apachelightd两个选项,按空格选中Apache2,回车 。
第二次选择 No,除非你会手动配置phpmyadmin的一些设置。

$ sudo a2enmod rewrite     # 启用 apahce 的 mod_rewrite 模块

$ sudo ln -s /usr/share/phpmyadmin /var/www/html     #再把 phpmyadmin 链接到 /var/www/html 目录下

最后重启 Apache,测试是否可以

最后设置一下目录权限

$ sudo chown root:root /var/www/ -R
$ sudo find /var/www/ -type d -exec chmod 755 {} \;
$ sudo find /var/www/ -type f -exec chmod 644 {} \;

MySQL 配置

连接 mysql 数据时提示错误: “ERROR 1698 (28000): Access denied for user ‘root’@’localhost'
因为 mysql 启用了 plugin 功能

1、进入 mysql

$ sudo mysql

显示如下:

$ sudo mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.23-MariaDB-9+deb9u1 Debian 9.0
 
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MariaDB [(none)]>

2、查看 mysql 的 plugin 状态:

直接输入

 SELECT host,user,plugin FROM mysql.user;

显示如下:

MariaDB [(none)]> SELECT host,user,plugin FROM mysql.user;
+-----------+------+-------------+
| host      | user | plugin      |
+-----------+------+-------------+
| localhost | root | unix_socket |
+-----------+------+-------------+
1 row in set (0.00 sec)
 
MariaDB [(none)]>

3、更改 plugin 状态:

plugin 状态有: “mysql_old_password “, “mysql_native_password” , “unix_socket
这里我只需要本地能登陆,所以更改为 “mysql_native_password”。

直接输入

UPDATE mysql.user SET host='%',authentication_string=PASSWORD('新密码'), PLUGIN='mysql_native_password' WHERE USER='root';

显示如下:

MariaDB [(none)]> UPDATE mysql.user SET host='%',authentication_string=PASSWORD('新密码'), PLUGIN='mysql_native_password' WHERE USER='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [(none)]>

不要忘了最后输入FLUSH PRIVILEGES;

4、 重启mysql服务:

$ sudo /etc/init.d/mysql restart
上一篇 下一篇

猜你喜欢

热点阅读