是否可以使用 Live-server for PHP 并在保存时自动重新加载? [英] Is it possible to use Live-server for PHP with autoreload on save?

查看:31
本文介绍了是否可以使用 Live-server for PHP 并在保存时自动重新加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 VS Code for PHP 上使用 Live-Server 扩展,但它只打开了服务"项目文件夹的根",并将 index.php 显示为可下载文件链接.

然后我阅读了 Live-Server Web Extension 并安装了它,但它仍然无法正常工作.
(是的,我确实在 VS Code 的 Live-Server 配置设置中启用了 Web 扩展).

我也尝试使用 PHP Server 扩展,它在为项目服务方面做得很好,而不是在 XAMPP 中使用 Apache,但我还没有找到保存时重新加载的方法.

有没有办法在 PHP 服务器上自动重新加载 PHP?

Live-Server Web 扩展是否需要在 VS Code 中安装 Live-Server 并在 Live-Server 配置设置中启用 Web 扩展之外的其他东西?

我在 gif/视频中看到它对某些人有效,但我没能解决.

解决方案

首先我想告诉你的是

  • 现在点击Go Live"VS Code 中的按钮.5.现在打开VS Code中/var/www/html/demo/下的index.php文件,右击选择PHP Server: Reload Server";然后PHP 服务器:在浏览器中打开文件".
  • 在浏览器中打开 IP 地址
  • <块引用>

    http://localhost:3000/demo/index.php

    您将看到它在带有动态网页(如 PHP)的实时服务器中运行.当您使用正在运行的 VS Code 编辑并保存 index.php 文件时,它将自动更新该 IP 地址.

    I tried to use the Live-Server extension on VS Code for PHP, but it only opened the "root" of the "served" project folder and showed the index.php as a downloadable file link.

    Then I read about the Live-Server Web Extension and installed it, but it still did not work.
    (Yes, I did enable the web extension inside Live-Server config settings in VS Code).

    I've also tried to use the PHP Server extension, which does good job for serving the project, instead of using Apache in XAMPP, but I have not found a way to reload when saving.

    Is there even a way to autoreload PHP on PHP Server?

    Does the Live-Server Web Extension require something else other than the Live-Server installed in VS Code and enabling the web extension in Live-Server config settings?

    I've seen that it works for some people in gifs/videos, but I didn't manage to work it out.

    解决方案

    First of all, I want to tell you that Live Server which is available in visual code market place is the solution to your problem. It works mainly with the static webpage like HTML but also works with dynamic webpages like PHP, NodeJs and ASP.NET in a tricky way. In the following example I will guide you to install a live server which works with both webpages (static & dynamic).

    1. Install PHP Server and Live Server from VS Code market place.
    2. Create a PHP file, example index.php and place it in any sub-directory(say, demo) under /var/www/html/, like /var/www/html/demo/
    3. Install the
    4. Now click on the "Go Live" button in the VS Code. 5.Now open the index.php file which is placed under /var/www/html/demo/ in VS Code and right click and select "PHP Server: Reload Server" then "PHP Server: Open file in browser".
    5. In the Browser just open the IP address

    http://localhost:3000/demo/index.php

    you will see that it is working in a live server with a dynamic webpage like PHP. When you edit and save the index.php file with the running VS Code, it will automatically updated on that IP address.

    这篇关于是否可以使用 Live-server for PHP 并在保存时自动重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆