如何从 ubuntu 运行 PHP 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37541718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:17:03  来源:igfitidea点击:

How to run a PHP file from ubuntu?

php

提问by User

How to run a php file from ubuntu platform in the localhost? I have also installed LAMP in my system. When I try to run the php file, in the browser, it says "The requested URL is not found-404 ERROR found". I do not know how to proceed with this. My php files are in the directory as shown here "/usr/var/html/a.php".

如何在本地主机中从 ubuntu 平台运行 php 文件?我还在我的系统中安装了 LAMP。当我尝试运行 php 文件时,在浏览器中显示“未找到请求的 URL-404 错误”。我不知道如何处理这个问题。我的 php 文件位于“/usr/var/html/a.php”所示的目录中。

回答by sjsam

There are two options.

有两种选择。

  1. Access the php file through a local webserver(ie thru a local website). The web-server will deal with the requested php file. It will use either,

    • Inbuilt PHP module to interpret the php file, or
    • PHP through CGI (eg.CGI, FastCGI)

      If your apache(check if apache is running using service apache2 status!!) is set to the default configuration, this could be as simple as

      http://localhost/path/to/your.php
      

      Remember by default, the base directory for apache is /var/www/html/, so you need not include this in the url.

  2. Use the php binary directly from a terminal.

       php /path/to/your/file.php
    
  1. 通过本地网络服务器(即通过本地网站)访问 php 文件。网络服务器将处理请求的 php 文件。它将使用,

    • 内置 PHP 模块来解释 php 文件,或
    • PHP 通过 CGI(例如 CGI、FastCGI)

      如果您的 apache(检查 apache 是否正在使用service apache2 status!!)设置为默认配置,这可能很简单

      http://localhost/path/to/your.php
      

      请记住,默认情况下,apache 的基本目录是/var/www/html/,因此您无需将其包含在 url 中。

  2. 直接从终端使用 php 二进制文件。

       php /path/to/your/file.php
    

回答by DSK

After installation of Lamp system in Ubuntu. Please follow the below two steps to run your php file.

在 Ubuntu 中安装 Lamp 系统后。请按照以下两个步骤运行您的 php 文件。

  • Place your php file (.php) in /var/www/html/ (default path)
  • Please run url as localhost/withfilename.php
  • 将您的 php 文件 (.php) 放在 /var/www/html/ (默认路径)
  • 请运行 url 作为 localhost/withfilename.php

Example : I have placed welcome.php file in the /var/www/html/welcome.phpthen url will be http://localhost/welcome.php

示例:我已将welcome.php 文件放在 /var/www/html/welcome.php然后url 将是http://localhost/welcome.php