02-网站搭建过程-红帽LAMP建站
1 基础环境
[root@localhost /]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.2 (Maipo) [root@localhost /]# uname -a Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux [root@localhost /]#
PHP 版本:5.4.16
mysql版本:5.6.51
2 建站过程
2.1 配置好yum环境
具体参考:https://www.cnblogs.com/snow2021/p/16941886.html
2.2 安装lamp环境
[root@localhost /]# yum -y install httpd php php-mysql mysql mysql-server
2.3 启动apache和mysql服务
[root@localhost /]# service httpd start Redirecting to /bin/systemctl start httpd.service [root@localhost /]# service mysqld start Redirecting to /bin/systemctl start mysqld.service
解决mysql报错问题:参考https://blog.csdn.net/weixin_43303530/article/details/103713915
centos7默认安装的是mariaDB,而不是mysql,所以先卸载mariaDB。
查看是否安装了mariaDB:
rpm -qa |grep mariadb
卸载已安装的mariadb:
rpm -e --nodeps mariadb-5.5.68-1.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
查看是否已经成功卸载:
rpm -qa |grep mariadb
下载mysql:
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
安装mysql:
rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装mysql-server:
yum install mysql-server
再次启动mysql,service mysqld start,已经成功。
2.4 配置mysql root账号密码,然后登录进去。
[root@localhost /]# mysqladmin -u root password 123123 [root@localhost /]# mysql -uroot -p123123 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 4 Server version: 5.6.51 MySQL Community Server (GPL) Copyright (c) 2000, 2021, 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>
2.5 关闭防火墙和seLinux
[root@localhost /]# iptables -F [root@localhost /]# setenforce 0
2.6 访问测试
浏览器输入虚拟机地址,可以看到测试页面。
<?php echo phpinfo(); ?>
在/var/www/html目录可以新建上述文件。phpinfo.php,在浏览器中直接访问可查看PHP相关信息。
3 搭建phpcms网站
3.1 拷贝网站源代码到服务器上
网站目录在/var/www/html/,可以把自己的网站源码拷贝到此目录。本文搭建的是PHPCMS内容管理系统。
访问地址:https://www.phpcmsv9.cn/
下载最新源码,放到/var/www/html/目录下。本文新建目录phpcm,所有源码拷贝至此。
3.2 安装网站
[root@localhost /]# iptables -F
[root@localhost /]# setenforce 0
确保防火墙等已关闭。浏览器直接输入网址:http://192.168.225.137/phpcms,默认进入安装界面。
1、进入安装许可协议界面,点击开始安装。
2、运行环境检测,执行后发现两项不通过。
GD扩展不通过直接yum安装即可:yum -y install php-gd
DNS解析不通过:修改源码中install目录下面install.php,域名改成www.baidu.com。
$PHP_DNS = preg_match("/^[0-9.]{7,15}$/", @gethostbyname('www.baidu.com')) ? 1 : 0;
3、选择模块,选择全新安装PHPCMS V9。
4、文件权限设置,使用chmod修改里面文件权限即可。
5、账号设置,设置数据库账号口令,管理员账号口令。
6、安装详细信息
7、安装完成
3.3 访问网站
进入管理后台页面:
http://192.168.225.137/phpcms/admin.php
3.4 数据库
[root@localhost phpcms]# mysql -uroot -p123123 mysql> show databases; mysql> use phpcmsv9; mysql> show tables; +-----------------------+ | Tables_in_phpcmsv9 | +-----------------------+ | v9_admin | | v9_admin_panel | | v9_admin_role | | v9_admin_role_priv | | v9_announce | | v9_attachment | | v9_attachment_index |
管理员账号密码:
mysql> select * from v9_admin; +--------+----------+----------------------------------+--------+---------+-------------+---------------+-------------+----------+------+------+ | userid | username | password | roleid | encrypt | lastloginip | lastlogintime | email | realname | card | lang | +--------+----------+----------------------------------+--------+---------+-------------+---------------+-------------+----------+------+------+ | 1 | admin | b4e0d1a9dec66325977b52e00ba69f7e | 1 | fPZHu4 | | 0 | test@qq.com | | | | +--------+----------+----------------------------------+--------+---------+-------------+---------------+-------------+----------+------+------+ 1 row in set (0.00 sec)
添加管理员账号:账号admin,密码phpcms。
mysql> INSERT INTO `phpcmsv9`.`v9_admin`(`userid`,`username`,`password`,`roleid`,`encrypt`,`lastloginip`,`lastlogintime`,`email`,`realname`,`card`,`lang`) VALUES ( NULL,'admin','09fd8aa544abd9f913c277d3f9215014','1','TPTUni',NULL,'0',NULL,'','',''); Query OK, 1 row affected (0.00 sec)
mysql> select * from v9_admin; +--------+----------+----------------------------------+--------+---------+-------------+---------------+-------------+----------+------+------+ | userid | username | password | roleid | encrypt | lastloginip | lastlogintime | email | realname | card | lang | +--------+----------+----------------------------------+--------+---------+-------------+---------------+-------------+----------+------+------+ | 1 | admin | b4e0d1a9dec66325977b52e00ba69f7e | 1 | fPZHu4 | | 0 | test@qq.com | | | | | 2 | admin | 09fd8aa544abd9f913c277d3f9215014 | 1 | TPTUni | NULL | 0 | NULL | | | | +--------+----------+----------------------------------+--------+---------+-------------+---------------+-------------+----------+------+------+
3.5 修改登录限制次数
登录时总是报错,需要一小时后重新登录。修改/var/www/html/phpcms/phpcms/modules/admin/index.php文件。找到下面代码并注释掉。
//if($rtime['times'] >= $maxloginfailedtimes) { // $minute = 60-floor((SYS_TIME-$rtime['logintime'])/60); // if($minute>0) showmessage(L('wait_1_hour',array('minute'=>$minute))); //}
重新登录网站进入管理后台界面。使用admin/phpcms登录成功。
可添加管理员账号,如下:添加test/123456管理员账号。
查询mysql库表,账号添加成功。
mysql> select * from v9_admin; +--------+----------+----------------------------------+--------+---------+---------------+---------------+--------------+----------+------+------+ | userid | username | password | roleid | encrypt | lastloginip | lastlogintime | email | realname | card | lang | +--------+----------+----------------------------------+--------+---------+---------------+---------------+--------------+----------+------+------+ | 1 | admin | b4e0d1a9dec66325977b52e00ba69f7e | 1 | fPZHu4 | 192.168.225.1 | 1669961874 | test@qq.com | | | | | 2 | admin | 09fd8aa544abd9f913c277d3f9215014 | 1 | TPTUni | NULL | 0 | NULL | | | | | 3 | snow | 09fd8aa544abd9f913c277d3f9215014 | 1 | TPTUni | 192.168.225.1 | 1669962043 | NULL | | | | | 4 | test | 0aef97f663ca8401b123217c3c316d00 | 1 | tqbEba | 192.168.225.1 | 1669962149 | test@163.com | | | | +--------+----------+----------------------------------+--------+---------+---------------+---------------+--------------+----------+------+------+ 4 rows in set (0.00 sec)