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
相关推荐
HungryGoogle11 分钟前
【无标题】
python·网络安全
shanql15 分钟前
系统安装:安装Ubuntu 26.04 LTS
linux·ubuntu
小脑斧12320 分钟前
从范式重构到工程落地:OpenTiny NEXT 引领前端智能化新范式
前端·hermesagent·opentiny next
小江的记录本20 分钟前
【AI大模型选型指南】《2026年5月(最新版)国内外主流AI大模型选型指南》(企业版)
前端·人工智能·后端·ai作画·aigc·ai编程·ai写作
fpcc21 分钟前
Linux命令——lsof分析说明
linux·服务器
幽络源小助理26 分钟前
最新轻量美化表白墙系统源码v2.0_带后台版_附搭建教程
前端·开源·源码·php源码
qq_3813385038 分钟前
前端状态管理新范式:Zustand、Jotai 与 Preact Signals 深度对比
前端·arcgis
布局呆星40 分钟前
Vue Router 笔记(二):正则路由、组件通信与动态路由
前端·javascript·vue.js
cui_ruicheng43 分钟前
Linux网络编程(二):网络数据传输基本流程
linux·服务器·网络
TechWayfarer1 小时前
网络安全视角:利用IP定位API接口识别机房与基站流量(合规风控篇)
开发语言·网络·数据库·python·安全·网络安全