主要针对 Apache2+PHP7.0+MariaDB

安装

1
2
sudo apt-get install apache2 mariadb-server php7.0 php7.0-mysql libapache2-mod-php7.0
sudo apt-get install php7.0-curl php7.0-mbstring php7.0-xml php7.0-bz2 php7.0-zip
组件名称 作用
php7.0-curl curl操作
php7.0-mbstring 字符操作?
php7.0-xml dom操作
php7.0-bz2 bzip2解压
php7.0-zip zip解压

常见问题

综合问题


Apache2

忽略路径大小写

解决方法

  1. 启用模块speling
    1
    
    sudo a2enmod speling
    
  2. 在配置文件中加入
    1
    
    CheckSpelling on
    
  3. 重启服务器
    1
    
    sudo service apache2 restart
    

参考文章


PHP

PHP运行报错

  • PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20121212/pdo_mysql.so’ PHP7也会出现相同的问题,解决方法也类似,更换包名即可。

    1
    
    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/pdo_mysql.so' - /usr/lib/php5/20121212/pdo_mysql.so: undefined symbol: pdo_parse_params in Unknown on line 0
    

    解决方法

    1. 卸载php5-common包,然后重新安装需要的php组件。卸载时注意卸载掉了哪些包。
      1
      
      sudo apt-get purge php5-common
      
    2. 重新安装php组件
      1
      
      sudo apt-get install php5 php5-curl php5-mysql libapache2-mod-php5
      

    参考文章


MySQL/MariaDB

root空密码登录

控制台中能登录,phpmyadmin,adminer中提示空密码

解决方法 控制台登录mysql,并修改root用户的认证方式。

  1. 登录mysql
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    sudo mysql -uroot
    MariaDB [(none)]> SELECT user,host,plugin FROM mysql.user;
    +------+-----------+-----------------------+
    | user | host      | plugin                |
    +------+-----------+-----------------------+
    | root | localhost | unix_socket           |
    | admin | localhost |                       |
    | user | localhost | mysql_native_password |
    +------+-----------+-----------------------+
    3 rows in set (0.00 sec)
    
  2. plugin的值修改成mysql_native_password
    1
    2
    
    UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root';
    FLUSH PRIVILEGES;
    
  3. 重启服务器
    1
    
    sudo service mysql restart
    
  4. 创建用户并授予权限
    1
    2
    3
    
    CREATE USER 'admin'@'localhost' IDENTIFIED BY '123456';
    REVOKE ALL PRIVILEGES ON *.* FROM 'admin'@'localhost';
    GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
    

参考文章

创建用户并给予权限

创建一个用户,并给与之同名或者以其名称作为前缀的数据库的所有权限。

1
2
3
4
5
6
CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password;
GRANT USAGE ON *.* TO 'user'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
SET PASSWORD FOR 'user'@'localhost' = '***';
CREATE DATABASE IF NOT EXISTS `user`;
GRANT ALL PRIVILEGES ON `user`.* TO 'user'@'localhost';
GRANT ALL PRIVILEGES ON `user\_%`.* TO 'user'@'localhost';