在 Ubuntu 搭建 PHP 环境

前言

练习SQL注入,在本机搭建php靶场所需的php开发相关笔记。

安装 PHP 7.0

1
2
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
php -v

php访问。

安装 PHP 5.6

1
2
3
4
5
6
7
8
sudo apt-get install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-cache search php5
sudo apt-get install php5.6-common
sudo apt-get install libapache2-mod-php5.6
php5.6 -v

php5.6访问。

更低版本可能需要自行编译安装
https://www.howtoforge.com/tutorial/how-to-install-php-5-6-on-ubuntu-16-04/
https://gist.github.com/jniltinho/959f873a84b72ddd9fca2513a52a6b04

MySQL

新建数据库

1
create database sqli_test;

新建表

1
2
3
4
5
6
7
8
9
10
11
use sqli_test
drop table if exists sqlinj;
create table if not exists sqlinj (
id int primary key auto_increment,
info varchar(32)
);
insert into sqlinj values (1, "item #1");
insert into sqlinj values (2, "item #2");
insert into sqlinj values (3, "item #3");
insert into sqlinj values (100, "item #100");
insert into sqlinj values (1000, "item #1000");

Apache2

重启

1
2
sudo systemctl restart apache2
sudo systemctl stop apache2

参考资料

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04