1.测试环境搭建
1.1 基础nginx配置
#1.创建web目录
mkdir -p /var/www/aaa/
#2.配置nginx配置文件
/usr/local/nginx/conf/nginx.conf
#3.文件内容添加server模块
server {
listen 80;
server_name www.aaa.com;
root "/var/www/aaa/nginxhost/web";
index index.html index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
#4.启动nginx
[root@blackstone aaa]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@blackstone aaa]# /usr/local/nginx/sbin/nginx
记得修改本机的host文件:C:\Windows\System32\drivers\etc
192.168.2.169 www.aaa.com
1.2 代码部署+数据库配置
#1.将代码部署到指定位置(源码在评论区给出)
mv /home/batman/nginxhost .
#2.测试页面
![](https://i-blog.csdnimg.cn/blog_migrate/8e7d1093767b7b263389a5e6d93d2c09.png)
#3.给tmp文件赋权
[root@blackstone web]# chmod 777 /var/www/aaa/nginxhost/protected/tmp
再次测试:
![](https://i-blog.csdnimg.cn/blog_migrate/fcbad3d62b0623cc0d11711bb8de7ba0.png)
#4. 数据库对接 在对应目录下输入mysql -uroot -p密码 即可
[root@blackstone nginxhost]# cd /var/www/aaa/nginxhost
mysql> create database security;
Query OK, 1 row affected (0.00 sec)
mysql> use security;
Database changed
mysql> source initialize.sql
在开始之前我们浅浅分析一下数据库的大致结构,并插入flag
#flags就是我们需要获取的数据,两个字段构成
mysql> show columns from flags;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| flag | varchar(256) | YES | | NULL | |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
#这里是一个用户注册的数据表,四个字段,id、username、passsword、email
mysql> show columns from users;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(256) | NO | UNI | NULL | |
| password | varchar(32) | NO | | NULL | |
| email | varchar(256) | YES | | NULL | |
+----------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
#我们插入flag
mysql> insert into flags (flag) values ('mygod,you are a hacker!');
Query OK, 1 row affected (0.01 sec)
mysql> select * from flags;
+----+-------------------------+
| id | flag |
+----+-------------------------+
| 2 | mygod,you are a hacker! |
+----+-------------------------+
1 row in set (0.00 sec)
测试登陆页面的功能:
运气好的话会有一个报错:Fatal error: Class 'MySQLi' not found in /var/www/aaa/nginxhost/protected/lib/core.php on line 280
这是因为当前的php内部没有mysqli这个模块需要扩展安装,首先我们需要确定php的安装版本,下载对应的源码包进行重新安装:
php官网:https://www.php.net/releases/ 详情见下方php安装。
![](https://i-blog.csdnimg.cn/blog_migrate/20a9bf6a1c2e691dc8347e97c8fccf9a.png)
到此环境初步部署完毕。
2.php安装
安装源码编译php5.4.16的步骤
#1.下载依赖
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
#2.解压安装包 解压不了需要安装bzip扩展 yum -y install bzip2
tar jxvf php-5.4.16.tar.bz2
#3.进入目录,进行预编译 --- 这里会直接编译进去必须的模块,如果想通过外置模块进行添加可以自行解决
cd php-5.4.16
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
#4.安装
make && make install
#5.测试版本以及模块
[root@blackstone batman]# php -v
PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
[root@blackstone batman]# php -m | grep mysqli
mysqli
注意这里如果先前进行了nginx的解析,一定要把php-fpm重新启动一下刷新我们的配置:
systemctl restart php-fpm