从服务器登录LAMP网站根目录,yum 安装lamp环境配置根目录、别名、虚拟目录、用户认证登录,基于ip、域名、端口访问网站...

配置web服务器-搭建LAMP环境

修改web网站根目录-配置别名-虚拟目录

实现apache打开软链接功能-禁止显示目录列表-用户认证

apache虚拟主机基于-IP-域名-端口三种搭建方式

LAMP=linux apache Mysql PHP中的Apache (httpd)

1.LAMP工作原理

9b6df9718771

image.png

2.web服务器的工作模式和端口

工作模式是:B/S 模式

工作端口是:

正常端口:80/http

SSL 端口 443/https

3.安装:

yum 搭建LAMP环境

LAMP=linux + apache + mysql + php

yum -y install httpd mariadb mariadb-server php php-mysql

httpd配置文件

/etc/httpd/conf/httpd.conf

重启服务

systemctl start httpd

systemctl enable httpd

systemctl start mariadb

systemctl enable mariadb

查看端口

netstat -antp | grep httpd

netstat -antp| grep mysql

[root@localhost html]# netstat -antp | grep httpd

tcp6 0 0 :::80 :::* LISTEN 2709/httpd

[root@localhost html]# netstat -antp| grep mysql

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2558/mysqld

初始化数据库

mysql_secure_installation

登录测试

mysql -u root -p

mysql> show databases;

mysql>exit;

测试php

vim /var/www/htmlindex.php

phpinfo();

?>

配置

[root@localhost html]# vim /etc/httpd/conf/httpd.conf

DirectoryIndex index.html index.php

重启httpd

systemctl restart httpd

4.httpd配置文件详解

vim /etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd" #httpd服务的根目录

Listen 80 #监听端口,默认本地 IP,如果指定 ip 写上 IP:80

Include conf.modules.d/*.conf #当前目录下conf.modules.d 这个目录下所有conf文件都生效

Options FollowSymLinks #Options Indexes 目录浏览FollowSymLinks 用连接

浏览 #注释该行可避免index.php insex.html文件不存在时,客户端无法访问网站根目录而保护网站数据的安全

AllowOverride None #设置为 none,忽略.htaccess

Include conf.d/*.conf #conf.d 里面的 conf 文件也属有效配置文件

User apache #运行以哪个身份运行

Group apache #运行以哪个组的身份运行

ServerAdmin root@localhost #管理员邮箱

DocumentRoot "/var/www/html" #默认的主目录,如果改动要改动两处,Directory

Options Indexes FollowSymLinks AllowOverride None

LogLevel warn #日志等级

AddDefaultCharset UTF-8 #支持的语言,默认编码

DirectoryIndex index.html index.php #配置网站默认首页

5.指定网站默认根目录、配置网站别名及虚拟目录

指定网站默认根目录

DocumentRoot "/var/www/html/bbs/" #指定目录为/var/www/html/bbs

#

# Relax access to content within /var/www.

#

AllowOverride None

# Allow open access:

Require all granted

# Further relax access to the default document root:

使用别名,引用网站根目录以外的路径

/usr/local/phpdata/ 即访问ip/phpdata/指向/usr/local/phpdata/目录

[root@localhost bbs]# mkdir /usr/local/phpdata

[root@localhost bbs]# cd !$

cd /usr/local/phpdata

[root@localhost phpdata]# vim index.html

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

9b6df9718771

Alias /phpdata/ "/usr/local/phpdata/"

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

重启httpd服务测试

9b6df9718771

6.设置网站需登录才可访问

设置/usr/local/phpdata/目录,只能通过用户名密码方式访问。

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

Alias /phpdata/ "/usr/local/phpdata/"

Options Indexes FollowSymLinks

AllowOverride None

authtype basic

authname "my web site"

authuserfile /etc/httpd/conf/passwd.secret

require valid-user

[root@localhost ~]# htpasswd -cm /etc/httpd/conf/passwd.secret yundd

New password:

Re-type new password:

Adding password for user yundd

[root@localhost ~]# htpasswd -m /etc/httpd/conf/passwd.secret

spider #创建第二个用户时去掉-c参数,可通过htpasswd -L命令查看

New password:

Re-type new password:

Adding password for user spider'

9b6df9718771

添加允许登录的用户及密码

[root@localhost ~]# cat /etc/httpd/conf/passwd.secret

yundd:$apr1$fW6kv/Id$d.O6Mxa9tTR.4aMhaBs6t.

spider:$apr1$VbSzGLOm$ToOz.hRqIEEK16erGsteW1

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf

[root@localhost ~]# systemctl restart httpd

测试

9b6df9718771

7.基于域名-ip-端口访问网站

基于域名访问

windows客户端添加解析记录

C:\Windows\System32\drivers\etc

[root@localhost conf]# vim ip.conf

ServerAdmin webmaster@dummy-host-example.com

DocumentRoot /var/www/html/

ServerName www.yunko1.cn

ErrorLog logs/www.yunko1.cn-error_log

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot /var/www/html/yundd/

ServerName bbs.yunko1.cn

ErrorLog logs/bbs.yunko1.cn-error_log

CustomLog logs/bbs.yunko1.cn-access_log common

测试

9b6df9718771

9b6df9718771

基于ip访问

[root@localhost ~]# ifconfig ens33:1 10.0.0.12 netmask 255.255.255.0

[root@localhost ~]# mkdir /var/www/html/yundd

[root@localhost ~]# cd !$

cd /var/www/html/yundd

[root@localhost yundd]# vim index.html

[root@localhost yundd]# vim /etc/httpd/conf/ip.conf

配置ip.conf

ServerAdmin webmaster@dummy-host-example.com

DocumentRoot /var/www/html/

ServerName dummy-host.example.com

ErrorLog logs/dummy-host.example.com-error_log

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot /var/www/html/yundd/

ServerName dummy-host.example.com

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

测试

9b6df9718771

基于端口访问

[root@localhost conf]# vim ip.conf

ServerAdmin webmaster@dummy-host-example.com

DocumentRoot /var/www/html/

ServerName dummy-host.example.com

ErrorLog logs/dummy-host.example.com-error_log

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot /var/www/html/yundd/

ServerName dummy-host.example.com

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

[root@localhost conf]# vim httpd.conf

#

#Listen 12.34.56.78:80

Listen 10.0.0.6:8080

Listen 10.0.0.13:8082

#

测试

9b6df9718771

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值