Fedora 40服务器安装后,如果想用该服务器托管网站则还需要搭建一个可靠的服务器环境LAMP。主要由Linux、Apache、MariaDB和PHP组成。
首先需更新Fedora系统的软件包,保证有最新安全补丁和软件更新:
sudo dnf update
然后开始安装Apache,Apache是Linux系统中受欢迎且可靠的web服务器,可以为网络中多个网站和基于web应用程序提供支持,有许多附加模块可以增强不同类别功能,含安全模块、服务器访问模块等。安装Apache:
sudo dnf install httpd
配置Apache的自动启动:
sudo systemctl enable httpd.service
再启动服务:
sudo systemctl start httpd.service
为保证服务运行:
sudo systemctl status httpd.service
通过HTTP/HTTPS访问web服务器,需要用系统防火墙启用对它的访问:
udo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
再重新加载系统防火墙配置:
sudo systemctl reload firewalld
完成后,Apache的默认根目录是/var/www/html,可以把web文件放在这个位置,需要检查Apache安装索引页是否可在Web浏览器中正常打开:
http://服务器IP地址
如果不清楚服务器IP地址,可以查询:
ip a | grep“inet”
Fedora上安装MariaDB:
sudo dnf install mariadb-server
设置自启动:
sudo systemctl enable mariadb.service
启动服务:
sudo systemctl start mariadb.service
检查服务是否在运行:
sudo systemctl status mariadb.service
保护MariaDB安装:
sudo mysql_secure_installation
然后就可以开始安装PHP:
sudo dnf install php php-common
安装PHP所需模块:
sudo dnf install php-mysqlnd php-gd php-cli php-mbstring
重启Apache web服务器使全部更改保存生效,获取到完整工作的LAMP堆栈:
sudo systemctl restart httpd
进行测试,使用编辑器在Apache根目录中创建文件:
sudo vi /var/www/html/info.php
添加以下内容并保存退出:
<?php
phpinfo()
?>
再打开web浏览器输入以下URL:
http://server-ip-address/info.php
完成后会看到PHP信息,这样就可以开始在Fedora服务器上使用LAMP。