LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写:Linux,操作系统 Apache,网页服务器MariaDB或MySQL,数据库管理系统或数据库服务器PHP、Perl或Python,脚本语言
#ubuntu安装lamp一般在没有更换apt源的时候(此时官方软件源archive.canonical.com的服务器在国外),所以你要用sudo apt install安装软件,或者甚至是sudo apt update速度都会很慢,甚至可能由于实在速度过慢,系统认为你没有网络连接而直接导致操作失败。所以为了提升我们下载的速度,一般需要把apt源更换成国内的镜像源,这样当你用apt install时系统就会从国内的服务器上去搜索和获取你所查找的资源,下载也就能快很多。备份原来的apt源文件
cp /etc/apt/sources.list /etc/apt/sources.list.bak修改为下方的其中一个源,
#vim /etc/apt/sources.list阿里源deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse中科大源deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiversedeb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiversedeb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse清华源deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiversedeb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiversedeb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiversedeb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiversedeb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiversedeb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiversedeb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse然后获取最新资源包
apt-get update安装apache,ubuntu使用的web服务器是apache2
apt install apache2 -y安装mysql
apt install mysql-server mysql-client安装完成之后使用如下命令检测是否安装成功
netstat -antlp | grep mysql
通过上述命令检查之后,如果看到有 mysql 的socket处于 LISTEN 状态则表示安装成功。登录mysql数据库可以使用如下命令:
mysql -u root -p-u 表示选择登陆的用户名, -p 表示登陆的用户密码,现在是mysql数据库是没有密码的,Enter password:处直接回车,就能够进入mysql数据库。 然后通过 show databases; 就可以查看当前的所有数据库。

退出数据库,在终端输入以下命令对数据库进行安全配置
mysql_secure_installation然后根据自己的需求设置即可,配置完成之后重启数据库使其生效
/etc/init.d/mysql restart再次用mysql -u root -p命令,Enter password:处输入刚设置的密码,回车,就能够进入mysql数据库。安装php,首先查看当前apt源仓库所带的php版本
apt shou php
从上图可以看到php版本为7.4的,如果没有需求的话直接执行以下命令
apt-get install php php-gd php-mysql安装完成之后重启apache2
/etc/init.d/apache2 restart然后在网站根目录新建info.php,内容为:<?php phpinfo();?>
#vi info.php<?php phpinfo();?>然后浏览器访问http://ip/info.php

进入到网站根目录下,一般为/var/www/html,然后将dvwa克隆下来
git clone https://github.com/digininja/DVWA.git
修改dvwa配置,进入到dvwa下的config文件夹里,将config.inc.php.dist的dist后缀去掉
cp config.inc.php.dist config.inc.php
然后使用vi编辑该文件,将username和password修改为我们的数据库用户名和密码

到这里配置初步完成,通过浏览器访问dvwa,点击下方的创建数据库即可。

解决红色报错内容PHP function allow_url_include: Disabled修改php.ini文件,我的在/etc/php/5.6/apache2/php.ini,找到allow_url_include=Off,将其改为allow_url_include=On

[User: root] Writable folder /var/www/html/DVWA/hackable/uploads/: No该文件夹是文件上传存放的地方,没有写权限(w),给其权限即可
chmod 777 /var/www/html/DVWA/hackable/uploads/
[User: root] Writable file /var/www/html/DVWA/external/phpids/0.6/lib/IDS/tmp/phpids_log.txt: No一样给其权限即可
chmod 777 /var/www/html/DVWA/external/phpids/0.6/lib/IDS/tmp/phpids_log.txtreCAPTCHA key: Missing编辑 dvwa/config/config.inc.php这个配置文件,key可以自己生成,地址是 https://www.google.com/recaptcha/admin/create,注册reCAPTCHA时选用V3版在DVWA中会提示错误,使用V2版正常,

完成,没有报错

使用admin/password登录dvwa
#安装其他php版本sudo add-apt-repository ppa:ondrej/phpsudo apt-get updatesudo apt-get install php5.6sudo apt-get install php5.6-gdsudo apt-get install php5.6-mysqlsudo apt-get install php5.6-mbstringsudo apt-get install php5.6-zipsudo apt-get install php5.6-curlsudo apt-get install php5.6-xmlsudo /etc/init.d/apache2 restart#centos7安装lamp备份yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak下载yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo清除yum源缓存
yum clean all生成yum源缓存
yum makecache安装apahce
yum install -y httpd httpd-devel启动
systemctl start httpd安装数据库
yum -y install mariadb mariadb-server mariadb-libs mariadb-devel启动数据库
systemctl start mariadb数据库安全配置
mysql_secure_installation安装php
yum -y install php安装依赖
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath php-mysql重启apache以加载php。
#数据库忘记密码修改配置文件/etc/my.cnf,在[mysqld]配置中增加:
skip-grant-tables重启数据库,修改密码
mysql -uroot -puse mysql;UPDATE user SET password = password('root') WHERE user = 'root';