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

转载于:https://blog.51cto.com/14202983/2351509

Centos7.2 / Linux的下搭建LAMP环境的搭建和配置虚拟主机相关推荐

  1. ubutnu16.04搭建LAMP环境(搭建wordpress博客)

    本次讲的是ubuntu的16.04版,通过搭建Lamp环境来建立wordpress博客网站.其他的linux版本也可以参考. 安装之前最好先更新一下系统软件库.命令:sudo apt-get upda ...

  2. linux下的lamp环境的搭建!!!

    本篇文章转自http://hx100.blog.51cto.com/44326/359296 如果涉及侵权请作者及时通知!!感谢作者的分享!! Centos5.5下安装LAMP完整版 Centos5. ...

  3. Centos7(linux)下hbase的伪分布式搭建以及eclipse远程连接

    本博客是在VMware15.5pro.hadoop-2.7.5.jdk1.8.0.hbase-1.2.10,下进行的 hbase-1.2.10-bin.tar.gz下载地址:Index of /dis ...

  4. Linux系统下 Apache+PHP 环境安装搭建

    一.安装Apache2.2.22 1.到官网下载  http://httpd.apache.org/download.cgi ,选择相应的版本 可以先下载到windows系统中,上传到linux, 也 ...

  5. CentOS下Apache配置虚拟主机

    这篇是进阶篇,对Apache不熟悉的话可以先看看我这篇博客:LAMP(CentOS)环境详细配置步骤 有时候我们往往一个服务器会运行多个应用,此时就需要给每个应用创建虚拟主机了,这里我创建三个文件夹, ...

  6. linux如何搭建lamp环境,Linux操作系统下搭建LAMP环境

    准备:先在目录home/csy/下建website代码目录,然后新建php文件,命名为test.php. 在test.php编写代码如下: php phpinfo(); ?> 保存并退出. 一. ...

  7. Linux的安装与Linux下PHP开发环境的搭建(LAMP)

    Linux的安装以及PHP环境的搭建 引言: 对于沉迷于windows数年的用户(比如笔者)来说,Linux中的红帽和utunbu虽然看起来和windows比较像,但是操作起来却是大不相同,需要一个适 ...

  8. 生产环境下的LAMP环境搭建

    生产环境下的LAMP环境搭建 V20 学习猿地  ww.lmonkey.com 一.LAMP环境介绍 Web服务器的主要功能是提供网上信息浏览服务.所有网页的集合被称为网站,网站也只有发布到网上才能被 ...

  9. Redhat Linux通过RPM安装搭建LAMP环境

    LAMP就是Linux+Apache+MySql+PHP搭建的动态网站环境,是目前互联网上非常流行的一个网页服务组合. 网上有很多教程搭建LAMP环境,基本上都是编译安装的,其实对新手来说只需要了解L ...

  10. PHP学习记录第一篇:Ubuntu14.04下LAMP环境的搭建

    PHP学习记录第一篇:Ubuntu14.04下LAMP环境的搭建 最近一段时间会学习一下PHP全栈开发,将会写一系列的文章来总结学习的过程,以自勉. 第一篇记录一下LAMP环境的安装 0. 安装Apa ...

最新文章

  1. Java快速教程--vamei 学习笔记(基础篇)
  2. 中兴f477v2超级管理员_中兴F650光猫修复
  3. ue4 怎么修改骨骼动画_UE4换装系统(合并骨骼模型)
  4. 读债务危机0824:随笔
  5. python 关键字 with_Python 中的with关键字使用详解
  6. Matlab 读取excel文件提示服务器出现意外情况或无法读取问题解决
  7. 耶鲁博弈论 第2节 学会换位思考
  8. OPPO Find X5系列领衔OPPO春季新品发布会,多款产品亮相
  9. asp.net在前台web页面中使用Javascript调用RTX腾讯通的聊天窗口
  10. Python自动化办公:xlwt万字教程
  11. 小程序列表倒计时使用wxs实现
  12. STM8S系列Option Byte问题:AFx在STVP中显示Reserved无法配置
  13. 在C语言中使用中文,本地化全攻略
  14. ShenYu网关数据同步源码分析
  15. golang flag
  16. Kunbernetes——二进制单节点部署
  17. Real-Time Rendering Chapter 1~6 读书笔记
  18. Android刘海屏、水滴屏全面屏适配详解,androidui基础教程
  19. 8421码、5421码、2421码与余三码
  20. numpy中的ndarray与array的区别、不同

热门文章

  1. AngularJs 隔离作用域
  2. 《哈利·波特》作者曾有自杀念头
  3. python爬虫学习研究
  4. 一键关闭 openwrt路由器的led灯
  5. Windows Server 2008 R2入门之FTP服务器
  6. MagicZoom bug-Strict Standards: Only variables should be assigned by reference Error
  7. 解决VIM打开U盘文件中文乱码的问题以及VIM有用的配置
  8. Ceph块设备(RBD)常用命令
  9. 常见消息部件(Common Message Components)
  10. Linux内核学习笔记(一)CFS完全公平调度类