centos安装apache2 https php

centos安装apache2 https+php

apache2的安装包叫httpd

apche2下的配置文件都在/etc/httpd/conf。例如:httpd.conf是http的配置文件。php.conf是php的配置文件。ssl.conf是https的配置文件。

1, 安装

有时候安装anaconda的时候是顺带安装了httpd的。

shell 复制代码
yum list installed httpd # 查看是否安装

yum install httpd* -y # 一路yes安装
 
yum list httpd # 查看所有可安装版本

yum list updates httpd # 查看可否更新

yum update httpd*
2, 查看配置
shell 复制代码
cat /etc/httpd/conf/httpd.conf

# 端口 Listen 80
# 根目录 ServerRoot "/etc/httpd"
# 网页存放目录 DocumentRoot "/var/www/html"


# 自己设置一个访问内容
cd /var/www/html
mkdir test
vim hello.html
3,启动
shell 复制代码
systemctl start httpd.service # 启动httpd

systemctl status httpd.service # 查看状态

curl http://ip/test/hello.html #不加端口,收到html代码表示成功

安装php

1,安装php
shell 复制代码
yum list installed php # 查看是否安装

yum install php
2,配置apache2使用php
shell 复制代码
vim /etc/httpd/conf.d/php.conf

# 在<FilesMatch \.php$>下面的内容追加
AddHandler application/x-httpd-php .php
3,测试访问php文件
shell 复制代码
cd /var/www/html
vim hello.php 
# 如下内容
shell 复制代码
<html>
  <head>
    <title>hello world</title>
    <meta charset="UTF-8">  
  </head>
  <body>
    <?php 
     $msg = '这里是hello.php!!!!';
    ?>
    <h2> <?php echo $msg; ?></h2>
  </body>
</html>

访问 http:ip/hello.php

设置https

如果已经安装mod_ssl,那么apache2已经支持https方式访问。

shell 复制代码
yum install -y mod_ssl
systemctl restart httpd
相关推荐
damoluomu3 天前
挑 PHP CMS 之前,先学会看它的协议
php
2501_916007473 天前
苹果商店iOS应用上架费用全面解析:开发者计划与审核费用计算
android·ios·小程序·https·uni-app·iphone·webview
Lsetea3 天前
证书没到期却报certificate has expired:OpenSSL定位中间证书与系统时间
运维·https·ssl证书·openssl·证书链
2501_916008893 天前
如何实现iOS App代码混淆:SwiftShield使用指南
android·ios·小程序·https·uni-app·iphone·webview
SDWAN_Cheap3 天前
HTTPS到底加密了什么?
https·数据加密
子非鱼a3 天前
【WEB】Online ToolWEB
php
PHP实战开发录3 天前
Nginx上传大文件为什么报413
nginx·php·开发
2501_916008893 天前
怎么用 Godot 导出 iOS 应用并上架 App Store?签名字段该填什么?
android·ios·小程序·https·uni-app·iphone·webview
damoluomu4 天前
国产企业级 PHP CMS:哪些能免费商用
php
郑州光合科技余经理4 天前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程