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
相关推荐
学逆向的23 分钟前
win32远程线程
网络安全·api·win32
陌上花开缓缓归以24 分钟前
mebdlts3.4.1安全启动全流程
服务器·算法
鬼手点金24 分钟前
opencode-全能开发者配置
java·linux·服务器·前端·javascript·学习·前向传播
溪语流沙26 分钟前
【Web全栈进阶】Alembic数据库迁移:改表结构不再删库
前端·数据库·python·elasticsearch·postgresql
AI你一生一世32 分钟前
当构建工具成为基础设施:从 Tailwind 被收购谈起,前端工具链的“归属”难题
前端·构建工具·tailwind css·前端工具链·开源软件收购·技术中立性·前端基础设施
_zxd40 分钟前
TypeScript 类型树
前端·typescript
炸鸡叔1 小时前
我做了 BotBus:从手机续聊本地 Agent,查看文件和终端
前端·后端
骑着蜗牛撵大象3271 小时前
多 Agent 串行流水线:把一个任务拆成可重试、可续跑的 Pipeline 节点链
前端·langchain
阿明61 小时前
进程替换【Linux】
linux·运维·服务器