在RHEL 8上安装 Apache HTTPD

安装软件包

sudo dnf install httpd

apache的配置文件

所有Apache配置文件如下:

/etc/httpd/– Apache主配置目录
/etc/httpd/conf/httpd.conf– Aapache主配置文件。
/var/log/httpd/– Apache错误和访问日志文件
/etc/httpd/conf.modules.d– Apache模块(比如代理模块、php模块)配置目录

在系统启动时启动httpd服务

sudo systemctl enable httpd.service

启动/停止/重启httpd的命令

## 启动apache
sudo systemctl start httpd.service
## 重启apache
sudo systemctl restart httpd.service
## 停止apache
sudo systemctl stop httpd.service
## 重新加载apache配置
sudo systemctl reload httpd.service
## 查看apache状态
sudo systemctl status httpd.service

查看端口是否正常

sudo ss -tulpn
sudo ss -tulpn | grep 80

如何使用firewalld打开防火墙端口80

sudo firewall-cmd --permanent --add-service=http --zone=public
sudo firewall-cmd --permanent --add-service=https --zone=public
sudo firewall-cmd --reload
sudo firewall-cmd --list-services --zone=public

测试apache

使用浏览器打开 http://服务器ip地址

如何查看Apache服务器的日志文件

ls -l /var/log/httpd/
sudo tail -f /var/log/httpd/access_log
sudo grep 'foo' /var/log/httpd/error_log

在RHEL 8上安装PHP 7

安装PHP 7.2,以及一些必须的模块

sudo dnf install php php-mysqlnd php-mbstring php-opcache php-gd

必须重新启动httpd服务才能访问PHP:

sudo systemctl restart httpd.service

测试php

在网站的根目录创建一个php文件

/var/www/html/test.php

<?php
   phpinfo();
?>

使用浏览器打开 http://服务器ip地址/test.php将可以看到PHP的信息。

搜索并安装其他PHP模块

搜索mysql安装包

sudo dnf search php- | grep -i mysql

查看php-mbstring安装包的信息:

sudo dnf info php-mbstring

如何在RHEL (Red Hat Enterprise Linux) 8上安装LAMP?

如何在RHEL 8上安装Mariadb

MariaDB作为Oracle MySQL服务器的替代品。是一款开源的社区版mysql数据库软件。

sudo dnf install mariadb-server

启动/停止/重启MariaDB服务

设置开机启动MariaDB服务

sudo systemctl enable mariadb.service
## 启动mariadb数据库
sudo systemctl start mariadb.service
## 重启mariadb数据库
sudo systemctl restart mariadb.service
## 停止mariadb
sudo systemctl stop mariadb.service
## 查看mariadb的状态
sudo systemctl status mariadb.service

运行mariadb安全脚本

sudo mysql_secure_installation

更新系统

sudo dnf update
如何在RHEL 8上安装Linux,apache,mysql和PHP(LAMP)

LAMP技术栈就是一组用于构建和运行动态网站和应用程序的流行软件。包括Linux ,Apache,Mysql(或者mariadb),PHP。

日期:2019-04-29 03:18:27 来源:oir作者:oir