百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

linux下搭建lamp环境(dvwa)(linux怎么搭建php环境)

nanshan 2025-01-26 23:38 12 浏览 0 评论

lamp简介

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 multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-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 multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-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,内容为:

#vi info.php

然后浏览器访问http://ip/info.php

#安装dvwa

进入到网站根目录下,一般为/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.txt

reCAPTCHA 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/php
sudo apt-get update
sudo apt-get install php5.6
sudo apt-get install php5.6-gd
sudo apt-get install php5.6-mysql
sudo apt-get install php5.6-mbstring
sudo apt-get install php5.6-zip
sudo apt-get install php5.6-curl
sudo apt-get install php5.6-xml
sudo /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 -p
use mysql;
UPDATE user SET password = password('root') WHERE user = 'root';

相关推荐

Linux 的磁盘系统,和你了解的Windows差别很大

我的C盘去哪了?一个系统,如果没有存储,那么也就不能称之为系统。存储性是一个完整系统的重要组成部分。例如AWS最开始的服务就是S3(用来存储数据的云服务),足以见得存储对于一个应用平台是多么的重要。...

一文读懂 Linux 硬盘挂载:从问题到解决方案

各位互联网大厂的后端开发伙伴们!在咱们日常工作中,操作Linux系统是常有的事儿吧。你们有没有遇到过这样的场景:新添加了一块硬盘,满心欢喜准备用来存储重要数据或者部署新的应用服务,却突然发现不知道...

硬盘分区(硬盘分区格式)

 磁盘(硬盘)分区,可以分C、D、E等分区,大家可能都会用,会根据自已的需要确定所需的空间,但分区是如何工作的呢,内容如下。Windows中有3类:MBR分区:MasterBootRecord,也...

parted命令工具分区介绍(particle命令)

linux系统磁盘分区通常可以使用fdisk和parted命令,当分区大小小于2TB的时候,两种皆可以使用,当分区大于2TB的话,就需要用parted分区。以下介绍parted命令相关使用,以sdb为...

Linux 服务器上查看磁盘类型的方法

方法1:使用lsblk命令lsblk输出说明:TYPE列显示设备类型,如disk(物理磁盘)、part(分区)、rom(只读存储)等。NAME列显示设备名称(如sda、nvme0n1)。TR...

Linux分区命令fdisk和parted使用介绍

摘要:一般情况下,Linux分区都是选择fdisk工具,要求硬盘格式为MBR格式,能支持的最大分区空间为2T。但是目前在实际生产环境中使用的磁盘空间越来越大,呈TB级别增长;而常用的fdisk这个工具...

linux 分区原理与名词解释(linux操作系统中的分区类型)

分区的意义将磁盘分成几份,每份挂在到文件系统的那个目录在linux里的文件系统Ext2:早期的格式,不支持日志功能Ext3:ext2改良版,增加了日志功能,是最基本且最常用的使用格式了Ext4:针对e...

linux 分区合并(linux合理分区)

查看虚拟机当前磁盘挂载情况fdisk-l选择磁盘fdisk/dev/sda查看磁盘分区情况p重新选择分区n选择主分区p保存w创建物理卷pvcreate/dev/sda3查看物理卷信息pvdi...

如何在 Linux 系统中永久禁用交换分区 ?

Linux操作系统中的交换分区或交换文件充当硬盘上的临时存储区域,当物理内存(RAM)满时,系统使用该存储区域。它用于交换较少使用的内存页,这样系统就不会因为运行应用程序而耗尽物理内存。随着技术的发...

Linux 如何知道硬盘已用多少空间、未用多少空间

刚出社会时,去了一家公司上班,老板为了省钱,买的服务器是低配的,硬盘大小只有40G,有一次网站突然不能访问了,排查半天才知道原来服务器的硬盘空间已用完,已无可用空间。第一步是查看硬盘的使用情况,第二步...

用Linux系统管理磁盘空间 就该这么来

要想充分有效的管理使用Linux系统中的存储空间,用户必须要做的就是双管齐下,一边扩充空间一边限制空间。不得不说的就是很多时候磁盘空间就像水资源,需节制水流。说到要如何实现限制空间就离不开使用LVM技...

Windows 11 磁盘怎么分区?(windows11磁盘怎么分区)

Windows11磁盘分区技术解析与操作指南:构建高效存储体系一、磁盘分区的技术本质与系统价值磁盘分区作为存储系统的基础架构,通过逻辑划分实现数据隔离与管理优化。Windows11采用NTF...

linux上创建多个文件分区,格式化为 ext2、ext3、ext4、XFS 文件

以下是在Linux系统上创建多个20GB文件分区并格式化为不同文件系统的分步指南:步骤1:创建基础文件(4个20GB文件)bash#创建4个20GB稀疏文件(实际占用空间随写入量增长)ddif=/...

救命的U盘低格哪家最强?(低格优盘)

周二时有位童鞋留言说U盘之前做过引导盘,现在格式化不了,用各种工具都不行,而且因为U盘厂商的关系,查不到U盘主控,无法量产恢复,特来求助。小编花了点时间特意弄坏一个U盘分区,终于试出方法了,特来分享一...

Linux 查看硬件磁盘存储大小和磁盘阵列(RAID)的组合方式

一、查看硬件磁盘存储大小查看所有磁盘信息:#lsblk该命令会列出所有磁盘(如/dev/sda、/dev/nvme0n1)及其分区和挂载点。查看磁盘总容量:fdisk-l#或parted-...

取消回复欢迎 发表评论: