简体   繁体   English

如何用vscode运行PHP

[英]How to run PHP with vscode

I'm trying to create a simple HTML form that redirects users to a thank you message displayed by the server, and written in PHP. However, nothing I do seems to work.我正在尝试创建一个简单的 HTML 表单,将用户重定向到服务器显示的感谢消息,并用 PHP 编写。但是,我所做的一切似乎都不起作用。 I get a 405 every time I try to run the code.每次尝试运行代码时,我都会收到 405。 If I refresh the page it starts downloading.如果我刷新页面,它就会开始下载。 I'm using the live server extension and I have PHP installed.我正在使用实时服务器扩展,并且安装了 PHP。

HTML file: HTML 档案:

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel = "stylesheet" type = "text/css" href = "styles-signup.css">
    <script type = "text/javascript" src = "script-signup.js"></script>

</head>
<body>
    <div>
        <h1 class = "title"></h1>
    </div>
    <div class = "form">
        <h1 id = "header">Create Your Account</h1>
        <form method = "POST" id = "signup" action = "action.php">
            <input name = "firstName" type = "text" placeholder="First Name" required id = "fname">
            <input name = "lastName" type = "text" placeholder = "Last Name" required id = "lname">
            <input name = "Email" type = "email" placeholder="email, e.g. person@gmail.com" required id = "mail">
            <input name = "newPassword" type = "password" id = "password" placeholder="Password" required minlength="8" maxlength="25">
            <input name = "passwordConfirm" type = "password" placeholder = "Confirm Password" required minlength="8" maxlength="25" id = "cpassword">
           <br>

           <input name = "gender" type = "radio" id = "male" required>
           <label for = "gender" id = "mlabel">Male</label>

           <input name = "gender" type = "radio" id = "female" required>
           <label for = "gender" id = "flabel">Female</label>

           <input name = "gender" type = "radio" id = "other" required>
           <label for = "gender" id = "olabel">Other</label>
           <br>

           <br>
           <input name = "birthdate" type = "number" min = "1920" max = "2019" placeholder="Year Of Birth" id = bd required>
           <br>

            <input name = "terms" type ="checkbox" id = "box" required>

            <p id = "tc">I agree to the <a href = "termsandconditions.txt" id = "tcLink">Terms and Conditions</a></p>

            <input name = "submit" type = "Submit" id = "button" value = "Sign up">

            <a href = "login.html" id = "login">Already have an account? Log in</a>

        </form>
    </div>

</body>
</html>

PHP File: PHP 文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <?php
    echo "<p>Hi</p>";
    ?>

</body>
</html>

I get this error:我收到此错误:

错误:

You need to set-up a server to be able to use PHP.您需要设置一个服务器才能使用 PHP。 If you use windows their are a couple easy to use options, try downloading one of these:如果您使用 Windows,它们有几个易于使用的选项,请尝试下载其中之一:

  1. XAMPP XAMPP
  2. WAMP WAMP

If you are on Linux you will need to build a LAMP server.如果您使用的是 Linux,则需要构建 LAMP 服务器。 If you are on mac, I think it is called OS-X.如果你在 mac 上,我认为它被称为 OS-X。 It sounds like your new to all this.这听起来像是你对这一切的新手。 I highly suggest setting up a server, it will really help you understand how websites work, and also give you the ability to write and learn server-side languages like PHP and ASP.我强烈建议设置一个服务器,它将真正帮助您了解网站的工作原理,并且还使您能够编写和学习诸如 PHP 和 ASP 之类的服务器端语言。

Just as a note, servers interrupt PHP, not editors and IDE's.请注意,服务器会中断 PHP,而不是编辑器和 IDE。

I am highjacking this rather old and answered thread to present a far more comfortable method of running/testing your php projects from inside VSC that does not require you to run a XAMPP setup.我正在劫持这个相当古老且已回答的线程,以提供一种更舒适的方法来从 VSC 内部运行/测试您的 php 项目,不需要您运行 XAMPP 设置。

There is a VSCode extension called PHP Server that lets you serve your project to a temporary server.有一个名为PHP 服务器的 VSCode 扩展,可让您将项目提供给临时服务器。 Of course you will need to have (depending on your project requirement) eg a MySQL server running as well but it's a great tool that helped me enormously, especially since I can place my project anywhere I want on my disk without having to take into account apache.当然,您还需要(根据您的项目要求)运行 MySQL 服务器,但它是一个对我帮助很大的好工具,特别是因为我可以将项目放在磁盘上任何我想要的地方,而不必考虑apache。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM