LAMP实验

发布时间 2023-12-21 11:31:28作者: qianyuzz

LAMP

确保CentOS系统已经安装了Apache、MySQL和PHP。可以使用以下命令检查它们是否已安装:

sudo yum list installed httpd mariadb-server php php-mysqlnd

如果它们没有安装,可以使用以下命令安装它们:

sudo yum install httpd mariadb-server php php-mysqlnd -y

Apache

httpd -t:语法检查

httpd -v:查看版本

httpd -m :查看模块

全局配置:

ServerName:对应域名

DocumentRoot:对应网站根目录

DirectoryIndex:网站默认首页

虚拟主机

<VirtualHost *:80>
    ServerAdmin webmaster@qziedu.cn
    ServerName www.qziedu.cn
    DocumentRoot /var/qziedu
    DirectoryIndex 学号.html

    Alias /学号 /var/学号 			#虚拟目录映射,访问 url/学号 对应的是/var/学号

    <Directory /var/qziedu>			#目录权限设置
        Options Indexes FollowSymLinks  #可以目录访问
        AllowOverride None
        Require all granted
    </Directory>

    <Directory /var/学号>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

phpmyadmin

安装EPEL存储库,因为phpMyAdmin包通常在EPEL存储库中:

sudo yum install epel-release -y

安装phpMyAdmin包:

sudo yum install phpmyadmin -y

编辑配置文件:

sudo vim /etc/httpd/conf.d/phpMyAdmin.conf

找出并注释掉带有"Require ip XXXX"字样的代码行。会有四处这样的代码行,用"Require all granted"取而代之。

vim快捷:%s/Require ip 127.0.0.1/Require all granted/g

修改完如下:

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   DirectoryIndex index.php
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
        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 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/libraries/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     Require all denied
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from None
   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/lib/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     Require all denied
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from None
   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/frames/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     Require all denied
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from None
   </IfModule>
</Directory>

重启服务 httpd 服务就完成了。