一、概念
1、框架结构
LAMP:linux+apache+mysql+PHP
系统+服务器程序+数据管理软件+中间软件
二、静态站点
1、安装Apache
(1)[root@localhost ~]# yum -y install httpd
//安装
[root@localhost ~]# systemctl start httpd
//启动
[root@localhost ~]# systemctl enable httpd
//设置开机自启动
[root@localhost ~]# systemctl stop firewalld
//临时关闭
[root@localhost ~]# setenforce 0
//关闭防火墙
[root@localhost ~]# httpd -v
//查看版本
Server version: Apache/2.4.6 (CentOS)
Server built: Mar 24 2022 14:57:57
2、虚拟主机
服务器:
目的: 在一台物理服务器上运行多个网站
类型:基于域名(主机名)
www.a站点设置:
(1)准备网站源码(网页)目录
[root@localhost ~]# mkdir /var/www/html/a.org
[root@localhost ~]# vim /var/www/html/a.org/index.html
//写内容在www.a.org网页中
(2)创建a.org的网站配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/a.org.conf
//
ServerName www.a.org//虚拟网站的名称(用于区别)
DocumentRoot /var/www/html/a.org//网页根目录
(3)检测配置文件语法,重启服务
[root@localhost ~]# httpd -t
//检测
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@localhost ~]# systemctl start httpd
//重启
客户端:
(1)linux客户端域名解析
[root@localhost ~]# vim /etc/hosts
192.168.32.138 www.a.org
(2)linux客户端测试网站可用性
用客户端访问服务器域名
三、动态网站
部署论坛系统
1、安装LAMP
[root@localhost ~]# yum -y install httpd mariadb-server mariadb php php-mysql gd php-gd
[root@localhost ~]# systemctl start httpd mariadb
//重启
(1)创建网站源码
[root@localhost ~]# wget http://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip
//下载压缩包
--2022-08-21 16:06:56-- http://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip
正在解析主机 download.comsenz.com (download.comsenz.com)... 81.69.153.197, 150.158.237.100, 49.234.165.129, ...
正在连接 download.comsenz.com (download.comsenz.com)|81.69.153.197|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:https://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip [跟随至新的 URL]
--2022-08-21 16:06:56-- https://download.comsenz.com/DiscuzX/2.5/Discuz_X2.5_SC_UTF8.zip
正在连接 download.comsenz.com (download.comsenz.com)|81.69.153.197|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9509959 (9.1M) [application/zip]
正在保存至: “Discuz_X2.5_SC_UTF8.zip”
100%[=============================================>] 9,509,959 168KB/s 用时 50s
2022-08-21 16:07:46 (184 KB/s) - 已保存 “Discuz_X2.5_SC_UTF8.zip” [9509959/9509959])
[root@localhost ~]# mkdir -p /webroot/discuz
//创建文件夹/webroot/discuz
[root@localhost ~]# yum install -y unzip
//安装解压工具
[root@localhost ~]# unzip Discuz_X2.5_SC_UTF8.zip
//解压
[root@localhost ~]# cp -rf upload/* /webroot/discuz/
//把upload中的所有文件复制到/webroot/discuz中
[root@localhost ~]# chown -R apache.apache /webroot/discuz/
虚拟主机:
[root@localhost ~]# vim /etc/httpd/conf.d/discuz.conf
ServerName www.discuz.com
DocumentRoot /webroot/discuz
Require all granted
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database discuz;
Query OK, 1 row affect
[root@localhost ~]# vim /etc/hosts
192.168.32.138 www.discuz.com
通过域名访问