由于PHP版本,Apache中的PHPMyAdmin500内部服务器错误
版本:
- 操作系统
lsb_release -a:Ubuntu 18.04.5 LTS - PHP
php -v: 8.0.1 - 阿帕奇
apache2 -v:2.4.29 (Ubuntu) - MySQL
mysql --version: mysql Ver 14.14 Distrib 5.7.32
问题:
我正在尝试使用以下文章安装 LAMP Stack 。但是,我在从浏览器HTTP 500 Error访问时phpmyadmin得到了。
并使用以下命令安装 phpmyadmin。
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
试过:
因此,我检查了错误日志tail -f /var/log/apache2/error.log,发现 Phpmyadmin 运行在折旧版本的 PHP 上。
[Sat Jan 30 12:56:38.798871 2021] [php:error] [pid 17271] [client
103.25.169.179:28514] PHP Fatal error: Array and string offset access
syntax with curly braces is no longer supported in
/usr/share/phpmyadmin/libraries/Util.php on line 2087
[Sat Jan 30 12:56:38.798871 2021] [php:error] [pid 17271] [client 103.25.169.179:28514] PHP Fatal error: Uncaught ValueError:
mb_convert_encoding(): Argument #2 ($to_encoding) must be a valid
encoding, "" given in /usr/share/php/php-php-
gettext/gettext.inc:181nStack trace:n#0 /usr/share/php/php-php-
gettext/gettext.inc(181): mb_convert_encoding()n#1 /usr/share/php/php-
php-gettext/gettext.inc(278): _encode()n#2 /usr/share/php/php-php-
gettext/gettext.inc(285): _gettext()n#3
/usr/share/phpmyadmin/libraries/sanitizing.lib.php(179): __()n#4
/usr/share/phpmyadmin/libraries/Message.php(607): PMA_sanitize()n#5
/usr/share/phpmyadmin/libraries/Message.php(672):
PMAlibrariesMessage::decodeBB()n#6
/usr/share/phpmyadmin/libraries/Error.php(220): PMAlibrariesMessage-
>getMessage()n#7 /usr/share/phpmyadmin/libraries/ErrorHandler.php(193):
PMAlibrariesError->getHash()n#8
/usr/share/phpmyadmin/libraries/ErrorHandler.php(156):
PMAlibrariesErrorHandler->addError()n#9 [internal function]:
PMAlibrariesErrorHandler->handleError()n#10
/usr/share/phpmyadmin/libraries/session.inc.php(133): ini_set()n#11
/usr/share/phpmyadmin/libraries/common.inc.php(280): require('...')n#12
/usr/share/phpmyadmin/index.php(13): require_once('...')n#13 {main}n
thrown in /usr/share/php/php-php-gettext/gettext.inc on line 181
- 我通过删除with解决了数组和字符串偏移访问语法错误
{ }[ ] - 运行以下命令
sudo phpenmod mbstring
回答
重要的:
如果您将 phpMyAdmin 公开或需要较新 phpMyAdmin 版本的功能,请更改版本号以获得更高的安全性。
这是从聊天中截取的。有些事情可能不准确,但这解决了 OP 的问题
使用以下教程安装 PHPMyAdmin:
1.
apt purge phpmyadmin -y
cd /path/to/somefolder
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0-rc1/phpMyAdmin-5.1.0-rc1-all-languages.zip && unzip phpMyAdmin-5.1.0-rc1-all-languages.zip &&
cd phpMyAdmin-5.1.0-rc1-all-languages
apt install pwgen -y
- 记下此命令的输出,我将其称为pw
pwgen -s 32 1
cp config.sample.inc.php config.inc.php
- 用最喜欢的编辑器编辑 config.inc.php,并将密码粘贴到这一行:
. . .
$cfg['blowfish_secret'] = 'STRINGOFTHIRTYTWORANDOMCHARACTERS'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
. . .
vim /etc/apache2/conf-available/phpmyadmin-custom.conf
- 将以下内容粘贴到上一个命令中:
Alias /phpmyadmin /path/to/that/phpMyAdmin-5.1.0-rc1-all-languages
<Directory "/path/to/that/phpMyAdmin-5.1.0-rc1-all-languages">
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
Require all granted
</Directory>
- 使用保存上一个
:wq,运行以下命令
a2enconf phpmyadmin-custom && systemctl restart apache2 && mysql
- 替换
your_password_here为您自己的密码。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password_here';
systemctl restart mysql
它现在应该可以工作了。
补充说明:
要只允许您查看 phpMyAdmin,请尝试:
<Directory "/path/to/that/phpMyAdmin-5.1.0-rc1-all-languages">
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
Require local
# Or change it to
# Require ip 127.0.0.1
# change 127.0.0.1 to your personal computers ip address,
# not to the server ip
# if you want to access phpMyAdmin from a public server, but not allow others to access it
</Directory>