##########apache的安装####
yum install httpd -y ##安装服务
systemctl start httpd ##开启服务
systemctl stop firewalld
systemctl enable httpd ##开机服务自启动
systemctl disabled firewalld ##开机关闭
需要下载
phpMyAdmin-3.4.0-all-languages.tar.bz2
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html##解档文件
mv phpMyAdmin-3.4.0-all-languages.tar.bz2/ mysqladmin ##重命名,使操作方便
cd mysqladmin ##进入该目录
cp -p config.sample.inc.php config.inc.php ##复制文件模板
vim config.inc.php ##编辑配置文件
17 $cfg['blowfish_secret']='mysql';/* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
systemctl restart httpd
##########apache的基本信息####
1.apache的默认发布文件
index.html
2.apache的配置文件
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
3.apache的默认发布目录
/var/www/html
4.apache的默认端口
80
##########apache的基本配置####
1.修改默认发布文件
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos.html ##修改默认发布文件为westos.html
2.修改默认发布目录
##当selinux是disable状态
mkdir /westos/www/test -p ##建立出当前目录
vim /westos/www/test/westos.html ##测试文件
vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/westos/www/test" ##修改默认发布目录为/westos/www/test
Require all granted ##允许所有用户访问
systemctl restart httpd
##当selinux是enforcing状态
vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/westos/www/test" ##修改默认发布目录为/westos/www/test
Require all granted
systemctl restart httpd
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?' ##更改该目录的安全上下文
restorecon -RvvF /westos ##更新安全上下文
3.apache的访问控制
vim /etc/httpd/conf/httpd.conf
##允许所有人访问admin目录但是拒绝250主机
Order Allow,Deny
Allow from All
Deny from 172.25.254.250
##只允许250主机访问admin目录
Order Deny,Allow
Allow from 172.25.254.250
Deny from All
#######设定用户的访问#######
htpasswd -m /etc/httpd/accessuser admin
vim /etc/httpd/conf/httpd.conf
AuthUserFile /etc/httpd/accessuser ##用户认证文件
AuthName "Please input your name and password!" ##用户认证提示
AuthType basic ##认证类型
Require valid-user ##认证用户,认证文件中所有用户均可通过
[Require user admin] ##只允许认证文件中admin用户访问,二写一
测试结果:
###apache语言支持######
1.html语言 ##默认支持的语言
2.php语言
[root@test ~]# yum install php -y
[root@test ~]# vim /var/www/html/index.php
phpinfo();
?>
[root@test ~]# systemctl restart httpd
3.cgi语言
[root@test ~]# mkdir /var/www/html/cgi
[root@test ~]# cd /var/www/html/cgi
[root@test cgi]# vim index.cgi ##编辑测试文件
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
[root@test cgi]# vim /etc/httpd/conf/httpd.conf ##编辑主配置文件
Options +ExecCGI
AddHandler cgi-script .cgi
[root@test cgi]# chmod +x index.cgi ##添加可执行权限
[root@test html]# setenforce 0 ##安全上下文
[root@test cgi]# systemctl restart httpd
####apache的虚拟主机###
配置文件,及执行步骤:
[root@test html]# vim /etc/httpd/conf.d/default.conf
##虚拟主机开启的端口
DocumentRoot "/var/www/html" ##虚拟主机默认发布目录
CustomLog "logs/default.log" combined ##虚拟主机日志
~
[root@test html]# vim /etc/httpd/conf.d/news.conf ##指定域名news.westos.com访问到默认发布目录中
ServerName "news.westos.com"
DocumentRoot "/var/www/virtual/news.westos.com/html"
CustomLog "logs/news.log" combined
##默认发布目录的访问授权
Require all granted
~
[root@test html]# mkdir /var/www/virtual/news.westos.com/html -p ##建立测试页
[root@test html]# vim /var/www/virtual/news.westos.com/html/index.html ##显示的测试内容
news'page
~
[root@test html]# systemctl restart httpd
[root@test html]#
测试:
在浏览器所在主机中
vim /etc/hosts
172.25.254.106 www.westos.com news.westos.com
#####https服务以及自制证书###
[root@test html]# yum install mod_ssl -y ##https的服务
[root@test html]# yum install crypto-utils -y ##证书配置服务
[root@test html]# genkey www.westos.com ##自定义编辑证书
/usr/bin/keyutil -c makecert -g 1024 -s "CN=www.westos.com, OU=hello, O=westos, L=xi'an, ST=shannxi, C=CN" -v 1 -a -z /etc/pki/tls/.rand.3528 -o /etc/pki/tls/certs/www.westos.com.crt -k /etc/pki/tls/private/www.westos.com.key
cmdstr: makecert
cmd_CreateNewCert
command: makecert
keysize = 1024 bits
subject = CN=www.westos.com, OU=hello, O=westos, L=xi'an, ST=shannxi, C=CN
valid for 1 months
random seed from /etc/pki/tls/.rand.3528
output will be written to /etc/pki/tls/certs/www.westos.com.crt
output key written to /etc/pki/tls/private/www.westos.com.key
Generating key. This may take a few moments...
Made a key
Opened tmprequest for writing
/usr/bin/keyutil Copying the cert pointer
Created a certificate
Wrote 882 bytes of encoded data to /etc/pki/tls/private/www.westos.com.key
Wrote the key to:
/etc/pki/tls/private/www.westos.com.key
[root@test html]# vim /etc/httpd/conf.d/login.conf
[1]+ Stopped vim /etc/httpd/conf.d/login.conf
[root@test html]# fg
vim /etc/httpd/conf.d/login.conf
[1]+ Stopped vim /etc/httpd/conf.d/login.conf
[root@test html]# fg
vim /etc/httpd/conf.d/login.conf ##编辑配置文件
##https服务默认端口号443
ServerName "login.westos.com"
DocumentRoot "/var/www/virtual/login.westos.com/html"
CustomLog "logs/login.log" combined
SSLEngine on ##https服务引擎打开
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##证书
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##密钥
Require all granted
##网页重写实现自动访问https
ServerName "login.westos.com"
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
~
##^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
#^(/.*)$ 客户主机在地址栏中写入的所有字符,不包含换行符
#https:// 定向成为的访问协议
#%{HTTP_HOST} 客户请求主机
#$1 $1的值就表示^(/.*)$的值
#[redirect=301] 临时重定向,320永久重定向
[root@test html]# mkdir /var/www/virtual/login.westos.com/html -p
[root@test html]# vim /var/www/virtual/login.westos.com/html/index.html
login.page
[root@test html]# systemctl restart httpd
[root@test html]#
测试:
在浏览器所在主机中
vim /etc/hosts
172.25.254.106 login.westos.com