You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VirtualBox Ubuntu16.04 Apache2虚拟主机跳转HTTPS或页面无法显示问题

在Ubuntu 16.04 + Apache2 + PHP7.0环境下迁移虚拟主机配置指南

嘿,我来帮你梳理下这个迁移过程的关键要点,尤其是针对PHP7的兼容性问题——毕竟你从旧环境搬过来的配置里藏着个大坑😉

首先先把你提供的旧虚拟主机配置片段贴出来(补全了缺失的结构部分):

<VirtualHost 192.168.2.174:80>
    ServerName admin.ubuntu16.de
    ServerAlias admin.ubuntu16.de
    ServerAdmin email@company.de
    DocumentRoot /home/www/public_html/workspace/admin
    php_value auto_prepend_file '/home/www/public_html/workspace/admin/administration/conf/register_globals.php'
    <Directory /home/www/public_html/workspace/admin>
        # 旧环境可能的目录配置
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

核心兼容性问题:register_globals已被PHP7移除

PHP7.0彻底砍掉了register_globals这个过时特性,所以旧配置里的php_value auto_prepend_file加载那个模拟全局变量的脚本完全无效,甚至会导致PHP报错。你必须:

  • 删除这一行配置
  • 修改代码中依赖register_globals的部分:把原来直接使用的全局变量(比如$username)替换为对应的超全局变量($_POST['username']、$_GET['username']或$_SESSION['username']等),这是代码层面必须做的适配。

修改后的虚拟主机配置(适配Apache2 + PHP7.0)

这里给你一份修正后的配置模板,同时适配Ubuntu 16.04的Apache2语法(比如用Require all granted替代旧的Order allow,deny):

<VirtualHost 192.168.2.174:80>
    ServerName admin.ubuntu16.de
    ServerAlias admin.ubuntu16.de
    ServerAdmin email@company.de
    DocumentRoot /home/www/public_html/workspace/admin

    # 移除PHP7不支持的register_globals相关配置
    # php_value auto_prepend_file '/home/www/public_html/workspace/admin/administration/conf/register_globals.php'

    <Directory /home/www/public_html/workspace/admin>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        # Apache2.4+的权限语法,替代旧版的Order/Allow
        Require all granted
    </Directory>

    # 配置日志路径,方便排查问题
    ErrorLog ${APACHE_LOG_DIR}/admin.ubuntu16.de-error.log
    CustomLog ${APACHE_LOG_DIR}/admin.ubuntu16.de-access.log combined
</VirtualHost>

配置生效的关键步骤

  • 把修改后的配置文件保存到Apache的站点配置目录:
    sudo cp your-config-file.conf /etc/apache2/sites-available/admin.ubuntu16.de.conf
    
  • 启用这个虚拟主机:
    sudo a2ensite admin.ubuntu16.de.conf
    
  • 检查Apache配置语法是否正确(避免重启失败):
    sudo apache2ctl configtest
    
  • 重启Apache服务让配置生效:
    sudo systemctl restart apache2
    
  • 额外检查:确保PHP7.0的Apache模块已启用(如果没启用的话):
    sudo a2enmod php7.0
    sudo systemctl restart apache2
    

最后一步:目录权限检查

确保Apache的运行用户(www-data)有权访问你的网站目录:

sudo chown -R www-data:www-data /home/www/public_html/workspace/admin
sudo chmod -R 755 /home/www/public_html/workspace/admin

内容的提问来源于stack exchange,提问作者Yuriy Semenikhin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:01:51