CTF-WEB: 配置一个Ubuntu 多版本php服务器

今天复现题windows的php /tmp缓存一直是空的,直接配一个新虚拟机

开始

准备一个全新的虚拟机,可以在这里下载镜像

Verifying - USTC Mirrors

走完常规安装流程继续

设置中文(可选)

复制代码
sudo apt install language-pack-zh-hans language-pack-gnome-zh-hans

然后在设置->语言中选择chinese

安装 zsh(可选)

复制代码
sudo apt install zsh -y

chsh -s $(which zsh)

exec zsh

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses --- 2

安装Apache Web服务器

bash 复制代码
sudo apt install apache2

添加PHP的PPA源

为安装多个PHP版本,添加Ondřej Surý的PPA仓库:

bash 复制代码
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

安装PHP 7和PHP 8

安装所需的PHP版本及其模块:

bash 复制代码
sudo apt install php7.4 libapache2-mod-php7.4
sudo apt install php8.0 libapache2-mod-php8.0

如果需要其他扩展,例如MySQL支持,可以安装:

bash 复制代码
sudo apt install php7.4-mysql php8.0-mysql

配置Apache以切换PHP版本

Apache使用模块来处理PHP。要在不同的PHP版本之间切换,需要启用或禁用相应的模块。

禁用所有PHP模块(确保干净的开始):

bash 复制代码
sudo a2dismod php7.4
sudo a2dismod php8.0

启用所需的PHP版本模块:

  • 切换到PHP 7.4:

    bash 复制代码
    sudo a2enmod php7.4
    sudo a2dismod php8.0
    sudo systemctl restart apache2
  • 切换到PHP 8.0:

    bash 复制代码
    sudo a2enmod php8.0
    sudo a2dismod php7.4
    sudo systemctl restart apache2

每次更改后,重启Apache以应用更改。

验证当前的PHP版本

创建一个info.php文件以查看当前正在运行的PHP版本:

bash 复制代码
sudo nano /var/www/html/info.php

在文件中添加:

php 复制代码
<?php
phpinfo();
?>

保存并退出,然后在浏览器中访问:

复制代码
http://你的服务器IP地址/info.php

您将看到PHP的信息页面,其中显示了当前的PHP版本。

切换CLI中的PHP版本(可选)

如果需要在命令行界面(CLI)中也切换PHP版本,可以使用update-alternatives:

bash 复制代码
sudo update-alternatives --set php /usr/bin/php7.4

或

bash 复制代码
sudo update-alternatives --set php /usr/bin/php8.0

或者使用交互式命令进行切换:

bash 复制代码
sudo update-alternatives --config php

然后按照提示选择所需的PHP版本。

使用PHP-FPM(可选)

如果您希望使用PHP-FPM,可以安装并配置:

安装PHP-FPM:

bash 复制代码
sudo apt install php7.4-fpm php8.0-fpm

配置Apache使用PHP-FPM:

启用必要的模块:

bash 复制代码
sudo a2enmod proxy_fcgi setenvif

禁用传统的PHP模块:

bash 复制代码
sudo a2dismod php7.4 php8.0

切换到PHP 7.4 FPM:

bash 复制代码
sudo a2enconf php7.4-fpm
sudo a2disconf php8.0-fpm
sudo systemctl reload apache2

切换到PHP 8.0 FPM:

bash 复制代码
sudo a2enconf php8.0-fpm
sudo a2disconf php7.4-fpm
sudo systemctl reload apache2

踩坑

如果info.php文件无回显,这是因为你使用了root创建了文件,这会导致阿帕奇无权限读取

复制代码
sudo chmod 644 /var/www/html/info.php
相关推荐
for_ever_love__7 分钟前
LangGraph Checkpointer:持久化、断点续跑与多轮记忆
服务器·数据库·学习·持久化·langgraph·checkpointer·断点续跑
Data analyse4568 分钟前
用户路径SQL按会话起止时间聚合的方法
大数据·服务器·前端·数据库·人工智能·sql·数据分析
FungLeo12 分钟前
成为全栈·Flutter App 篇·内置 WebView:网页历史、App 返回与外链安全
flutter·网络安全·移动开发·webview·路由管理·成为全栈
独孤九剑打醒他12 分钟前
【原创开源·2.0 版】太阳能水闭环氢能源汽车:动态制氢、动能回收与副产物商业闭环
前端·嵌入式硬件·汽车·硬件工程·能源
小毛驴85015 分钟前
mvn help:effective-settings 与 mvn help:effective-pom
java·linux·前端
志尊宝22 分钟前
AI原生前端开发(001):Cursor编辑器深度使用从入门到精通
前端·编辑器·ai-native
我先去打把游戏先26 分钟前
Git-Rebase使用指南-从原理到实战
服务器·git·嵌入式硬件·物联网·ubuntu
ZoeLandia30 分钟前
TypeScript 07:工程化——import type、声明文件与 tsconfig
开发语言·前端·typescript
拖孩32 分钟前
# AI 帮我写的小程序,上线不到一个月流量主突然爆了
前端·后端·微信小程序
染指111032 分钟前
145.Agent-LangGraph基础概念和安装和简单代码示例
java·服务器·数据库·langchain·agents