編碼的世界 / 優質文選 / 感情

centos7 安裝phpmyadmin


2022年5月17日
-   

前提 在CentOS上安裝phpMyAdmin,你第一步需要架設一台Web服務器(如Apache或nginx),安裝好MySQL/MariaDB數據庫和PHP。根據你的偏好和需求,你可以從LAMP和LEMP中選擇一種安裝。
 
先安裝epel,不然安裝pgpmyadmin時會出現找不到包。
yum install epel-release

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

安裝
sudo yum install phpmyadmin

在CentOS 7上配置phpMyAdmin 默認情況下,CentOS 7上的phpMyAdmin只允許從回環地址(127.0.0.1)訪問。為了能遠程連接,你需要改動它的配置。
用文本編輯器打開phpMyAdmin的配置文件(路徑:/etc/httpd/conf.d/phpMyAdmin.conf),找出並注釋掉帶有"Require ip XXXX"字樣的代碼行。會有四處這樣的代碼行,用"Require all granted"取而代之。重新改動過的配置文件如下所示。
sudo vi /etc/httpd/conf.d/phpMyAdmin.conf

修改後的文件內容
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
# Require ip 127.0.0.1 #注釋掉
# Require ip ::1 #注釋掉
Require all granted #新添加
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
#Require ip 127.0.0.1 #注釋掉
#Require ip ::1 #注釋掉
Require all granted #新添加
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>

 
最後,重啟httpd使改動生效。
sudo systemctl restart httpd

測試
ip/phpmyadmin
sudo
systemctl restart htt

熱門文章