实验环境
centos7.6虚拟机
ApacheHTTP丶PHP丶MySQL
安装步骤
1、Apache安装
2、PHP和MySQL安装
第一步:先安装一个工具,叫wget
yum install wget -y
备份旧的yum源文件配置文件
cd etc/yum.repos.d/ //进入文件夹
mkdir repo-bak
mv ./* ./repo-bak
第二步:下载阿里云yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
第三步:下载epel源
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
下载ngnix
yum install ngnix -y
安装完后,看 80 有没被占:
netstat -anp | grep 80;
启动ngnix
systemctl start nginx
验证:如何检查进程信息和端口信息
检查ps
搜索grep
ps -ef | grep “nginx”
查看端口的用法(nginx应用程序,默认80端口)
netstat -tunlp | grep “nginx”
访问页面
查看网站信息
curl 网址 //可以直接将网页的前端代码展现
curl -I 网址
利用curl命令,发起http网络请求,并且验证,对方的网站信息
查看淘宝网的服务器信息
[root@localhost ~]# curl -I https://www.taobao.com
HTTP/1.1 200 OK
Server: Tengine
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Date: Sat, 25 Feb 2023 10:32:38 GMT
x-server-id: 28c3d6b2523ca52c32ad72931842b19acb999de0affee41a6639770087d55ead18860f5b9ea54579
x-air-hostname: air-ual033060212165.center.na610
x-air-trace-id: d35bf19c16773211580086734e
Vary: Accept-Encoding, Origin, Ali-Detector-Type, X-Host
Cache-Control: max-age=0, s-maxage=147
etag: W/“1547c-vpcxkc4s2lWKGoVyIUhF5GEwzrY”
x-readtime: 285
x-via: cn1182.l1, cache3.cn1182, l2st3-1.l2, cache39.l2st3-1, wormholesource033042161203.center.na610
x-air-source: proxy
x-xss-protection: 1; mode=block
EagleEye-TraceId: d35bf19c16773211580086734e
Strict-Transport-Security: max-age=31536000
Timing-Allow-Origin: *, *
Ali-Swift-Global-Savetime: 1677321158
Via: cache39.l2st3-1[468,468,304-0,M], cache1.l2st3-1[470,0], cache3.cn1182[0,0,200-0,H], cache6.cn1182[3,0]
X-Snapshot-Date: 1677306197366
backup-by-error: 500
backup-from: OSS
Age: 126
X-Cache: HIT TCP_MEM_HIT dirn:9:244559235
X-Swift-SaveTime: Sat, 25 Feb 2023 10:32:38 GMT
X-Swift-CacheTime: 147
x-air-pt: pt0
EagleId: d35bf19a16773212845004889e看看自己的linux web服务器信息
[root@localhost ~]# curl -I 192.168.8.129
HTTP/1.1 200 OK
Server: nginx/1.20.1
Date: Sat, 25 Feb 2023 10:32:32 GMT
Content-Type: text/html
Content-Length: 4833
Last-Modified: Fri, 16 May 2014 15:12:48 GMT
Connection: keep-alive
ETag: “53762af0-12e1”
Accept-Ranges: bytes对于网站的隐私信息需要保护
修改nginx首页
rpm -ql nginx //查看nginx的安装文件路径信息
//只找出index相关信息
[root@localhost ~]# rpm -ql nginx | grep “index”
/usr/share/nginx/html/index.html安装vim编辑器
yum install vim -y
vim修改首页
步骤一:打开文件
步骤二:按下dG,这个组合命令
步骤三:写一些新内容
企业架构LAMP
动态网站部署
linux+apache(nginx)+mysql
配置apache,关闭防火墙
//关闭nginx服务
systemctl stop nginx
netstat -tunlp | grep “nginx”//查看nginx
yum remove nginx -y//卸载nginx服务
iptables --helpiptables -F //清空
systemctl stop firewalld //防火墙
systemctl disable firewalld
yum install apache //报错
yum install httpd //下载这个httpd
systemctl start httpd
netstat -tunlp|grep “apache” //没有apache
netstat -tunlp|grep “httpd”配置mysql
yum install mariadb-server mariadb -y //下载mysql
systemctl start mariadb//启动mysql
netstat -tunlp|grep “mysql”//查看
mysql -uroot -p //这里不需要密码
部署PHP
1.//安装php的开发环境
yum install -y zlib-devel libxm12-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpeg-devel gd-devel libcurl-devel libxslt-devel libtool-ltdl-devel pcre pcre-devel apr apr-devel zlib-devel gc make
2.yum install php php-fpm php-mysql -y //安装php,以及和mysql连接驱动
3.//php和apache结合工作 ,php不需要修改,但需要修改apache配置文件,支持php脚本读取即可
4.//编辑apache配置文件
/DocumentRoot (回车,按下n,然后:set nu 显示行号)
5.在120行
TypesConfig /etc/mime.types
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
6.编写一个php脚本,看apache能否正确加载读取
//这个脚本需要放置在
vim /var/www/html/index.php
//
< meta charset=utf8 >我是新的首页
<?php phpinfo(); ?>//
7.重启apache 服务
部署一个论坛discuz
//下载论坛压缩代码
wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
2、通过unzip解压压缩包
//安装解压缩命令
yum install unzip -y
unzip Discuz_X3.3_SC_UTF8.zip
解压完后,会看到一个upload文件夹
3、配置Discuz
a、由于PHP默认访问 /var/www/html/ 文件夹,所以我们需要把upload文件夹里的文件都复制到 /var/www/html/ 文件夹
cp -r upload/* /var/www/html/
b、通过chmod设置/var/www/html目录及其子目录赋予权限
chmod -R 777 /var/www/html/*
c、Apache重启
systemctl restart httpd.service
4、Discuz安装向导,访问路径:
http://ip/install
后面的安装默认配置就可以