LAMP環境搭建+配置虛擬域名

Centos下PHP,Apache,Mysql 的安裝php

安裝Apachehtml

    yum -y install httpd
    systemctl start httpd

添加防火牆mysql

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

安裝PHP7.2web

    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

安裝mysqlsql

    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密碼配置apache

  新版本的Mysql會爲root用戶建立一個初始密碼,須要更改
  查看默認密碼vim

    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/ php7

配置虛擬域名dom

查看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

相關文章
相關標籤/搜索