首页 > 技术文章 > LAMP

summer2 2019-04-29 00:53 原文

环境准备:创建1台新的rhel7虚拟机

1,设IP,配置yum源
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
... ...
IPADDR=192.168.4.57 添加这行,设置IP为192.168.4.57
PREFIX=24 这行不知是否要添加,还是默认就有?

# vim /etc/yum.repos.d/rhel7.repo
[rhel7]
name=rhel7
baseurl=ftp://192.168.4.254/rhel7
gpgcheck=0


2,构建LAMP
# yum -y install httpd php php-mysql mariadb mariadb-server
# systemctl restart httpd
# systemctl enable httpd


3,编写网页文件并测试
# vim /var/www/html/test.html
test.html

# vim /var/www/html/test2.php
<?php
echo "hello";
?>

真机测试访问:
# firefox http://192.168.4.57/test2.php
#########################################################
50作为数据库服务器,为57提供服务,授权用户userweb从主机192.168.4.57上用密码123456访问数据库gamedb,拥有查询记录,插入记录的权限。
50主机上:
mysql> create database gamedb;
mysql> grant select,insert on gamedb.* to userweb@"192.168.4.57" identified by "123456";
mysql> show grants for userweb@192.168.4.57;

57主机上:
# mysql -h192.168.4.50 -uuserweb -p123456

MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gamedb |
+--------------------+

MySQL [(none)]> show grants;
+----------------------------------------------------------------+
| Grants for userweb@192.168.4.57 |
+----------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'userweb'@'192.168.4.57' |
| GRANT SELECT, INSERT ON `gamedb`.* TO 'userweb'@'192.168.4.57' |
+----------------------------------------------------------------+

在数据库服务器的gamedb库里,创建存储网站注册用户信息的表regtab

mysql> create table gamedb.regtab(
-> username char(15),
-> password char(6)
-> );

mysql> select * from gamedb.regtab;
Empty set (0.00 sec)

5,程序员编写用户注册网页页面reg.html
6,程序员编写存储注册帐号存储到数据库里的脚本 tomysql.php

 

index.html reg.php 要把老师共享的这2个文件放到/var/www/html
下面就可以了

到时候用户在网页注册时,用户名和密码会自动记录到gamedb.regtab这个表里。

 

推荐阅读