zoukankan      html  css  js  c++  java
  • CentOS7单机部署lamp环境和apache虚拟主机

    (1)apache介绍

    apache : httpd.apache.org 
    软件包:httpd 
    端口服务:80/tcp(http) 443/tcp(https,http+ssl)
    配置文件: 
    	/etc/httpd/conf/httpd.conf 
    	/etc/httpd/conf.d/*.conf 
    	/etc/httpd/conf.d/welcome.conf 			//默认测试页面
    

    (2)lamp环境安装

    1.关闭防火墙和selinux

    systemctl stop firewalld.service 
    systemctl disable firewalld.service
    sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux
    setenforce 0
    

    2.安装和启动apache

    yum install httpd -y 
    systemctl start httpd 
    systemctl enable httpd 
    

    3.安装php

    yum install php -y 			//php作为apache的模块
    yum install php-mysql -y	//安装php连接mysql扩展模块
    yum install gd php-gd -y 
    php -m 						//查看php有哪些扩展模块
    ll /etc/httpd/modules/libphp5.so 
    ll /etc/httpd/conf.d/php.conf 
    systemctl restart httpd
    

    4.安装mariadb

    yum install mariadb-server mariadb  -y 
    systemctl start mariadb
    systemctl enable mariadb 
    mysql_secure_installation 		//修改root默认密码
    mysql -uroot -p					//登录mariadb测试
    

    5.测试apache和php

    cd /var/www/html 
    #vim index.php
    <?php
    phpinfo();
    ?>
    

    http://192.168.1.2

    6.测试php和mariadb

    cd /var/www/html 
    #vim index.php
    <?php
    $link=mysql_connect('localhost','root','mysql密码')
    if($link)
    	echo "successfuly";
    else 
    	echo "Faile";
    mysql_close();
    ?>
    

    http://192.168.1.2

    7.apache目录介绍

    # ll /etc/httpd/
    conf										//配置文件目录
    conf.d										//配置文件目录
    conf.modules.d								//模块目录
    logs -> ../../var/log/httpd					//日志目录
    modules -> ../../usr/lib64/httpd/modules	//模块目录
    run -> /run/httpd							//httpd进程pid在这个文件
    

    8.apache配置文件详解

    ServerRoot "/etc/httpd"						//安装目录
    Listen 80									//监听端口
    User apache									//运行apache的用户
    Group apache								//运行apache的用户组
    DocumentRoot "/var/www/html"				//站点默认主目录
    IncludeOptional conf.d/*.conf				//包含conf.d/*.conf的文件
    <Directory "/var/www">						//设定访问控制权限,如果修改了站点主目录,这里也需要修改
        AllowOverride None
        # Allow open access:
        Require all granted						//允许所有主机访问
    </Directory>
    

    (3)虚拟主机:基于主机地址

    1.配置主机地址www.test.com的虚拟主机

    #vim /etc/httpd/conf.d/blog.conf
    <VirtualHost *:80>
        DocumentRoot "/var/www/blog"
        ServerName blog.test.com
        ErrorLog "/var/log/blog-error_log"
        CustomLog "/var/log/blog-access_log" common
    </VirtualHost>
    <Directory "/var/www/blog">
        AllowOverride None
        Require all granted
    </Directory>
    

    2.创建目录,修改属主,准备主页

    mkdir /var/www/blog
    chown -R apache.apache /var/www/blog
    echo "blog.test.com" >>/var/www/blog/index.html
    

    3.检查配置文件和重启服务

    httpd -t 
    systemctl restart httpd 
    

    4.修改windows的hosts文件

    编辑:C:WindowsSystem32driversetchosts添加一下记录
    192.168.111.151 blog.test.com
    

    5.使用浏览器测试访问

  • 相关阅读:
    【转】当你输入一个网址的时候,实际会发生什么?
    opencv 操作本地摄像头实现录像
    谷歌笔试题——排序,只允许0和其他元素交换
    判断素数的相关代码
    VS2010 代码自动对齐 快捷键
    谷歌的一道面试题
    各种排序算法代码汇总
    冒泡排序
    lua环境变量
    lua迭代
  • 原文地址:https://www.cnblogs.com/lovelinux199075/p/9049000.html
Copyright © 2011-2022 走看看