phpmyadmin 500由于PHP版本的原因,在Apache中出现内部服务器错误

w46czmvw  于 2022-11-09  发布在  PHP
关注(0)|答案(5)|浏览(142)

版本:

  • 操作系统lsb_release -a:Ubuntu 18.04.5语言版本
  • PHP php -v:8.0.1
  • Apacheapache2 -v:2.4.29(Ubuntu语言)
  • MySQL mysql --version:mysql版本14.14分配5.7.32
    问题:

我正在尝试使用以下article安装LAMP Stack。但是,从浏览器访问phpmyadmin时,我得到了HTTP 500 Error
并使用下面的命令安装了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:181\nStack 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): 
PMA\\libraries\\Message::decodeBB()\n#6 
/usr/share/phpmyadmin/libraries/Error.php(220): PMA\\libraries\\Message-
>getMessage()\n#7 /usr/share/phpmyadmin/libraries/ErrorHandler.php(193): 
PMA\\libraries\\Error->getHash()\n#8 
/usr/share/phpmyadmin/libraries/ErrorHandler.php(156): 
PMA\\libraries\\ErrorHandler->addError()\n#9 [internal function]: 
PMA\\libraries\\ErrorHandler->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
  • 我已经解决了 * 数组和字符串偏移访问语法错误 *,方法是将{ }删除为[ ]
  • 运行以下命令sudo phpenmod mbstring
e5nszbig

e5nszbig1#

重要提示:

如果您的phpMyAdmin已公开或需要更新的phpMyAdmin版本的功能,请更改版本号以获得更高的安全性。

这是聊天录,有些东西可能不准确,但是解决了楼主的问题。
使用以下教程安装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

1.请记下此命令的输出,我将其称为 pw

pwgen -s 32 1
cp config.sample.inc.php config.inc.php

1.使用常用的编辑器编辑config.inc.php,并将 pw 粘贴到以下行中:

. . .
$cfg['blowfish_secret'] = 'STRINGOFTHIRTYTWORANDOMCHARACTERS'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
. . .
vim /etc/apache2/conf-available/phpmyadmin-custom.conf

1.将以下内容粘贴到上一个命令:

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>

1.使用:wq保存前一个文件,运行以下命令

a2enconf phpmyadmin-custom && systemctl restart apache2 && mysql

1.将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>
4nkexdtk

4nkexdtk2#

我的服务器配置:
| 详细信息|指令|输出量|
| - -|- -|- -|
| 操作系统|# lsb_版本-a| Ubuntu 18.04.5语言版本|
| PHP语言|# php -v字符串|PHP 8.0.3语言|
| Apache人|# apache2 -v|嵌入式系统(Ubuntu)|
| MySQL数据库|# mysql --版本号|mysql版本14.14分配5.7.33|
我通过修改以下两个文件解决了该问题:


# nano /usr/share/php/Symfony/Component/DependencyInjection/ContainerBuilder.php

如果您有一个新的示例,那么您就可以创建一个新的示例了。$r-〉新示例参数($个参数);

如果您有一个新的示例,那么您就可以创建一个新的示例了。数组值($个参数);
另一个文件CoreExtension.php


# nano -l /usr/share/php/Twig/Extension/CoreExtension.php

如果(isset($对象-〉$项)||\数组关键字存在((字符串)$item,$object)){

如果(isset($对象-〉$项)||数组关键字存在((字符串)$item,json_decode(json_encode($object),true))){
..最后重新启动服务器..


# service apache2 restart
gtlvzcf8

gtlvzcf83#

我想我应该添加一个简短的说明--如果你偶然安装了不止一个版本的PHP,不管是意外还是故意的,都有可能是有问题的PHP版本没有所有必要的模块。要确定你的活动版本,在命令行(终端)执行:

php -v

它将返回当前的活动版本。在我的情况下,这是v8.1,但我以前安装了版本8.0
为了快速解决这个问题,我只是重新安装了必要的软件包,如下所示:

sudo apt install php8.1 php8.1-cli php8.1-common php8.1-curl php8.1-gd php8.1-intl php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-xml php8.1-xsl php8.1-zip php8.1-bz2 libapache2-mod-php8.1 -y
6yjfywim

6yjfywim4#

如果您遇到array and string offset access syntax with curly braces is no longer supported phpmyadmin这样的错误-原因可能是您使用的是旧版本的Linux/Ubuntu和旧版本的phpMyAdmin,而PHP 8+版本是新版本。使用以下命令修复该问题:

apt --yes install php-mbstring php8.1-gettext
apt --yes purge phpmyadmin
rm -rf /usr/share/phpmyadmin
mkdir /usr/share/phpmyadmin
cd /tmp
wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip
unzip /tmp/phpMyAdmin-5.2.0-all-languages.zip
cp -a /tmp/phpMyAdmin-5.2.0-all-languages/* /usr/share/phpmyadmin
rm -rf /tmp/phpMyAdmin-5.2.0-all-languages.zip
rm -rf /tmp/phpMyAdmin-5.2.0-all-languages/

要使用命令创建符号链接,请执行以下操作:

注意/var/www/mysite.com/public_html/是一个示例,请将您的路径粘贴到服务器上的站点文件

ln -s /usr/share/phpmyadmin /var/www/mysite.com/public_html/phpmyadmin

可选。如果要使用登录名和密码作为HTTP基本身份验证来保护phpMyAdmin文件夹,请使用以下命令:

apt --yes install apache2-utils
htpasswd -c /var/www/mysite.com/public_html/.htpasswd-phpmyadmin yourlogingoeshere

# enter your password

最后,Nginx在您的站点配置上进行额外的设置

[...]

# phpmyadmin

location /phpmyadmin/ {
    auth_basic "Restricted";
    auth_basic_user_file /var/www/mysite.com/public_html/.htpasswd-phpmyadmin;
}

不要忘记重新启动Nginx service nginx restart

rqqzpn5f

rqqzpn5f5#

我的修正是升级phpmyadmin
以下是一个易于遵循指南:
https://devanswers.co/manually-upgrade-phpmyadmin/

相关问题