欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

LAMP环境搭建+配置虚拟域名

程序员文章站 2022-04-29 13:05:28
Centos下PHP,Apache,Mysql 的安装 安装Apache yum -y install httpd systemctl start httpd 添加防火墙 firewall-cmd --permanent --add-port=80/tcp systemctl restart fir ......

centos下php,apache,mysql 的安装

安装apache

    yum -y install httpd
    systemctl start httpd

添加防火墙

    firewall-cmd --permanent --add-port=80/tcp
    systemctl restart firewalld

安装php7.2

    yum install epel-release -y
    rpm -uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
    systemctl restart httpd
    systemctl enable php-fpm.service
    systemctl start php-fpm.service

安装mysql

    yum -y install wget
    wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    rpm -ivh mysql57-community-release-el7-9.noarch.rpm
    cd yum.repos.d
    yum install -y mysql-server
    service mysqld start

mysql密码配置

  新版本的mysql会为root用户创建一个初始密码,需要更改
  查看默认密码

    sudo grep 'temporary password' /var/log/mysqld.log
    2020-01-16t01:47:12.600702z 1 [note] a temporary password is generated for root@localhost: nym>co+s7ok2

更改mysql密码

    cd /etc
    vi my.cnf
    新增 skip-grant-tables
    不用密码直接登录mysql : mysql
    修改密码(5.7版本已经不再使用password来作为密码的字段了  而改成了authentication_string)
    update mysql.user set authentication_string=password("123456") where user="root" and host="localhost";
    刷新表格
    flush privileges;
    退出mysql: exit;
    systemctl restart mysqld

在本机浏览器访问 http://192.168.23.130/ 

LAMP环境搭建+配置虚拟域名

配置虚拟域名

查看apache主配置文件,确保存在以下配置

    vim  /etc/httpd/conf/httpd.conf 
    includeoptional conf.d/*.conf

新增虚拟主机配置文件

    cd /etc/httpd/conf.d/
    vim cyy.conf

添加虚拟机

    <virtualhost *:80>
        servername lamp.cyy.com
        serveralias lamp.cyy.com
        serveradmin lamp@cyy.com
        documentroot /var/www/html/lamp.cyy.com/

        <directory /var/www/html/lamp.cyy.com>
        options -indexes +followsymlinks
        allowoverride all
        </directory>

        errorlog /var/log/httpd/lamp.cyy.com-error.log
        customlog /var/log/httpd/lamp.cyy.com-access.log combined
    </virtualhost>

创建虚机主机目录及测试页面

/var/www/html/lamp.cyy.com/


 

创建info.php

    <?php
    phpinfo();

在/etc/hosts文件中新增

    192.168.23.130 lamp.cyy.com
    #虚拟机ip

检查配置文件是否正常

    httpd -t
    ah00558: httpd: could not reliably determine the server's fully qualified domain name, using localhost.localdomain. set the 'servername' directive globally to suppress this message
    syntax ok

重启httpd服务

    systemctl restart httpd

在本机我是win10,路径:c:\windows\system32\drivers\etc
hosts文件中新增

    192.168.23.130 lamp.cyy.com

浏览器访问:http://lamp.cyy.com/info.php

LAMP环境搭建+配置虚拟域名