环境:Centos7
工具:mysql,php,httpd
目的:熟练掌握httpd服务器搭建和个服务器之间的配合。
有兴趣的朋友可以来实践一下,我会提供各种源码进行搭建。
网络家园和论坛****源码:https://www.lanzous.com/i3yqq3c
(1)准备一台centos服务器,我是在虚拟机搭建的centos7.
(2)关闭防火墙和selinux等(centos7关闭防火墙和selinux)
(3)搭建myql数据库(MySQL的rpm安装教程)
(4)搭建httpd服务器(centos7自带httpd,只需要启动即可用)
(5)安装PHP服务器
-
**安装**
1
|
[root@wei ~]# yum install php –y
|
安装php-mysql
1
|
[root@wei ~]# yum install php-mysql –y
|
2.测试php和apache协同
测试协同
1
|
[root@localhost ~]# cd /var/www/html/
|
1
2
3
4
5
6
7
8
9
|
[root@localhost html]# vim phpinfo.php
<?php
phpinfo();
?>
|
** 测试: http://IP/phpinfo.php**
-
测试php和MySQL协同
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
[root@localhost html]# vim php_mysql.php
<?php
$servername = "localhost";
$username = "admin";
$password = "123456";
// 创建连接
//$con = mysql_connect($servername,$username,$password);
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "连接成功";
?>
|
** 测试: http://IP/php_mysql.php**
(6)部署应用
1.上传代码(代码在上面)(代码上传到/var/www/html/目录)
2.解压
安装解压软件:
1
|
[root@localhost html]# yum install unzip –y
|
3.配置
改名:
1
|
[root@wei html]# mv upload/ farm
|
在线安装:
http://192.168.196.131/farm/install/index.php
1.问题一
修改/etc/php.ini, 将short_open_tag = On
修改完毕,重启httpd服务。
1
|
[root@wei html]# systemctl restart httpd
|
2.问题二
修改目录权限:
1
|
[root@localhost html]# chmod -R 777 farm
|
让后进项下面步骤,进行在线安装
步骤一:
步骤二:
创建farm数据库和用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@wei html]# mysql -u root -proot ##登录数据库
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database farm; ##创建farm数据库
Query OK, 1 row affected (0.00 sec)
mysql> grant all on farm.* to farm@'localhost' identified by 'farm'; #创建用户,进行授权
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; ##刷新权限表
Query OK, 0 rows affected (0.00 sec)
|
步骤三:
进行安装
步骤四:
进行测试
http://192.168.196.131/farm/bbs/
http://192.168.196.131/farm/
http://192.168.196.131/farm/home/space.php?do=home