Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可能是目前最详细简明的CentOS7安装与管理教程(7):Apache & PHP & phpMyAdmin #9

Open
gaoac opened this issue Apr 6, 2020 · 0 comments
Labels
Linux linux服务器知识

Comments

@gaoac
Copy link
Owner

gaoac commented Apr 6, 2020

Apache

查看可安装版本
yum list httpd

image

这里我们直接安装最新版 2.4.6
yum install -y httpd

image

安装完毕,启动 Apache
systemctl start httpd

image

Apache 默认端口 80,所以在浏览器访问http://localhost,出现以下界面,说明 Apache 启动成功

image

设置开机自启
systemctl enable httpd

PHP

查看可安装版本
yum list php

image

显示版本为 5.4.16,想要使用 php7 的话,需要安装升级 PHP7 的 rpm 源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

查看 php7 安装包
yum list phpyum list php*w,可以看到目前可以安装的各版本

image

这里我们不是以 PHP 为主,就选系统默认版本 5.4.16
yum install php

image

安装完毕,查看 php 版本
php -v

image

重启 Apache
systemctl restart httpd
apache 默认根目录/var/www/html,添加文件 phpinfo.php,输入以下内容:

<?php
    phpinfo();
?>

访问http://localhost/phpinfo.php,查看 php 相关信息

image

安装 PHP 模块

查看已安装模块
php -m

image

这里我们需要再安装常用的一些模块,推荐使用 pecl 安装 php 扩展

PECL 的全称是 The PHP Extension Community Library ,是一个开放的并通过 PEAR(PHP Extension and Application Repository,PHP 扩展和应用仓库)打包格式来打包安装的 PHP 扩展库仓库。通过 PEAR 的 Package Manager 的安装管理方式,可以对 PECL 模块进行下载和安装。

安装 pecl:
yum install php-pear php-devel

安装模块:
pecl install dom mbstring mcrypt mysql mysqli PDO pdo_mysql pdo_sqlite posix sqlite3 sysvmsg sysvsem sysvshm wddx xmlreader xmlwriter xsl

如遇到 pecl 找不到的扩展模块,再尝试 yum 安装,如:
yum install php-gd php-mbstring php-mcrypt php-mysql php-mysqli php-pdo php-pdo_sqlite php-posix php-sqlite3 php-ldap

重启 Apache
systemctl restart httpd

查看新增 php 模块

image

安装 phpMyAdmin

phpMyAdmin 是一个以 PHP 为基础,以 Web-Base 方式架构在网站主机上的 MySQL 的数据库管理工具,让管理者可用 Web 接口管理 MySQL 数据库。借由此 Web 接口可以成为一个简易方式输入繁杂 SQL 语法的较佳途径,尤其要处理大量资料的汇入及汇出更为方便。其中一个更大的优势在于由于 phpMyAdmin 跟其他 PHP 程式一样在网页服务器上执行,但是您可以在任何地方使用这些程式产生的 HTML 页面,也就是于远端管理 MySQL 数据库,方便的建立、修改、删除数据库及资料表。也可借由 phpMyAdmin 建立常用的 php 语法,方便编写网页时所需要的 sql 语法正确性。

安装:
yum install -y phpmyadmin

phpMyAdmin 的默认安装目录是 /usr/share/phpMyAdmin,同时会在 Apache 的配置文件目录中自动创建虚拟主机配置文件 /etc/httpd/conf.d/phpMyAdmin.conf(区分大小写)。默认情况下,CentOS 7 上的 phpMyAdmin 只允许从回环地址(127.0.0.1)访问。为了能远程连接,你需要改动它的配置。

修改配置:
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>

作者:TyiMan
链接:https://www.jianshu.com/p/bc14ff0ab1c7
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

然后重启 Apache 服务器:
systemctl restart httpd
访问http://ip/phpmyadmin

image

开启连接远程服务器中数据库功能:

执行命令 vi /usr/share/phpmyadmin/libraries/config.default.php,

$cfg['AllowArbitraryServer']值修改为true;

$cfg['AllowArbitraryServer'] = true;

然后重启Apache服务器:
systemctl restart httpd

@gaoac gaoac added the Linux linux服务器知识 label Apr 6, 2020
@gaoac gaoac changed the title 可能是目前最详细简明的CentOS7安装与管理教程(7):Apache & PHP 可能是目前最详细简明的CentOS7安装与管理教程(7):Apache & PHP & phpMyAdmin Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux linux服务器知识
Projects
None yet
Development

No branches or pull requests

1 participant