Centos7.2 / Linux的下搭建LAMP环境的搭建和配置虚拟主机
admin
2023-04-19 07:04:11
0

LAMP环境:LINUX + Apahce的+ MYSQL + PHP的网络服务器环境。

(一)。准备工作

1.下载并安装CentOS7.2,配置好网络环境,确保centos能上网,可以获取到yum源(阿里云服务器已配置好,不需要自己动手)
2。配置防火墙,开启21,80,3306端口。 CentOS 7.0默认使用的是防火墙作为防火墙,这里改为iptables 防火墙停止防火墙服务输入命令systemctl stop firewalld.service 禁止防火墙开机启动输入命令systemctl disable firewalld.service 安装iptables 防火墙输入命令:yum install iptables-services 编辑防火墙配置文件输入命令vim / etc / sysconfig / iptables 打开后,在-A INPUT -p tcp -m state -state NEW -m tcp -dport 22 -j ACCEPT下方添加:-A INPUT -p tcp -m state -state NEW -m tcp -dport 80 -j ACCEPT -A INPUT -p tcp -m state -state NEW -m tcp -dport 3306 -j ACCEPT 保存退出,最后重启防火墙使配置生效systemctl restart iptables.service 设置防火墙开机启动systemctl启用iptables.service















  1. 关闭seinux(阿里云已配置好)
    修改配置文件
    vi / etc / selinux / config

SELINUX =强制#注释掉
SELINUXTYPE =有针对性#注释掉
SELINUX =禁用#增加
:wq!#退出保存
使配置|立即生效

setenforce 0

(二)。安装灯环境
1.安装apahce (http://www.1jaz.com)
yum install httpd 
设置apache开机启动
systemctl启用httpd.service 
重启apache服务系统
重启httpd.service

ps:可能会用到的:
systemctl start httpd.service#启动apache 
systemctl stop httpd.service #dail止apache 
systemctl restart httpd.service#重启apache 
systemctl enable httpd.service#settings置apache开机启动

2.安装mysql(可不安装)
由于yum源上没有mysql-server。所以必须去官网下载,这里我们用wget命令,直接获取。依次输入下方三条命令:    
wget http://dev.mysql.com/get /mysql-community-release-el7-5.noarch.rpm    http://www.1jaz.com
rpm -ivh mysql-community-release-el7-5.noarch.rpm 
yum install mysql-community-server

安装完成后重启mysql,输入命令:
systemctl restart mysqld.service

此时mysql的root用户没有密码:    
[root @linuxidc -web linuxidc] #mysql -u root

设置msyql密码为123456 
mysql>为'root'设置密码@'localhost'=密码('123456');

远程连接设置,所有以root账号连接的远程用户,设其密码为123456 
mysql>授予所有权限来自'123456'标识的@'%';

更新权限
mysql>刷新权限;

退出,mysql 
退回回车

3.安装php输入命令:
yum install php 
安装PHP组件,使用PHP支持mysql输入命令:
yum install php-mysql php-gd libjpeg * php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php -bcmath php- 
mhash 
重启对应服务systemctl重启mysqld.service 
systemctl restart httpd.service

(三。)配置虚拟主机
1.创建自定义网站根目录
mkdir / home / webroot 
2.打开httpd主配置文件
vim /etc/httpd/conf/httpd.conf 
3.找到以下代码


AllowOverride无

# Allow open access:Require all granted


将其改为:


AllowOverride All

# Allow open access:Require all granted


4.找到以下代码


# Possible values for the Options directive are "None", "All",# or any combination of:#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important.  Please see# http://httpd.apache.org/docs/2.4/mod/core.html#options# for more information.#Options Indexes FollowSymLinks## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:#   Options FileInfo AuthConfig Limit#AllowOverride None## Controls who can get stuff from this server.#Require all granted


改为[Options -Indexes为禁止访问目录列表]:


# Possible values for the Options directive are "None", "All",# or any combination of:#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All"# doesn't give it to you.## The Options directive is both complicated and important.  Please see# http://httpd.apache.org/docs/2.4/mod/core.html#options# for more information.#Options Indexes FollowSymLinksOptions -Indexes## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:#   Options FileInfo AuthConfig Limit#AllowOverride None## Controls who can get stuff from this server.#Require all granted


5.追加自动压缩网页代码功能,在主配置文件继续加入
添加Gzip


SetOutputFilter DEFLATE 
SetEnvIfNoCase Request_URI。(?:gif | jpe?g | png)$ no-gzip不变
SetEnvIfNoCase Request_URI。(?:exe | t?gz | zip | bz2 | sit | rar)$ no-gzip不变
SetEnvIfNoCase Request_URI。(?:pdf | mov | avi | mp3 | mp4 | rm)$ no-gzip不要改变
AddOutputFilterByType DEFLATE text / 
AddOutputFilterByType DEFLATE application / ms
 application / vnd * application / postscript application / javascript appliction / x-javascript 
AddOutputFilterByType DEFLATE application / x-httpd-php application / x-httpd-fastphp

6.建立一个项目目录
mkdir / home / webroot / demo 
7.进入apache子配置文件夹,建立对应的项目配置文件
cd /etc/httpd/conf.d 
vim demo.conf 
8.在打开的配置文件中,输入以下代码


DocumentRoot“/ home / webroot / demo” 
ServerName你的公网IP

ps:如果已经申请下域名,则输入以下代码(上方作者),允许r-collar.com www.hehaoke.com两种方式的域名访问,并禁止直接访问服务器IP的方式访问项目

ServerName你的公网IP

订单允许,拒绝
所有人拒绝



DocumentRoot“/ home / webroot / demo” 
ServerName r-collar.com

DocumentRoot“/ home / webroot / demo” 
ServerName www.hehaoke.com

9.重启apache 
systemctl重启httpd.service

注:此方式是基于端口实现的虚拟主机,如要添加新端口来访问新项目,还需要注意去主配置文件httpd.conf中给新端口添加监听,并在防火墙中允许新端口的访问。

更多:http://www.1jaz.com


相关内容

热门资讯

终于懂了“新九天牛牛可以开挂吗... 终于懂了“新九天牛牛可以开挂吗?”(太坑了果然有挂)您好,新九天牛牛这个游戏其实有挂的,确实是有挂的...
今日重大发现“新起点开挂神器?... 家人们!今天小编来为大家解答新起点透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买很多...
【第一财经】“新皇豪炸/金/花... 网上科普关于“新皇豪炸/金/花有没有挂”话题很是火热,小编也是针对新皇豪炸/金/花作*弊开挂的方法以...
终于明白“广西老友玩到底是不是... 家人们!今天小编来为大家解答广西老友玩透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买...
今日重大发现“网易棋牌开挂器?... 您好:网易棋牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏...
终于了解“人海牛牛可以开挂吗?... 有 亲,根据资深记者爆料人海牛牛是可以开挂的,确实有挂(咨询软件无需打开...
【第一财经】“蛮王炸/金/花开... 有 亲,根据资深记者爆料蛮王炸/金/花是可以开挂的,确实有挂(咨询软件无...
玩家攻略科普“友谊互娱辅助器?... 家人们!今天小编来为大家解答友谊互娱透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买很...
年末炸场!荣耀WIN系列硬核实... 2025年末的手机市场,被荣耀WIN系列的首秀彻底点燃。这款从GT系列全面升级而来的电竞旗舰,以“不...
【第一财经】“白金岛三打哈辅助... 【第一财经】“白金岛三打哈辅助器?”(必胜开挂神器)您好,白金岛三打哈这个游戏其实有挂的,确实是有挂...