在 Ubuntu 上,我应该把我的 Hello world PHP 文件放在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23825248/
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-25 16:59:11  来源:igfitidea点击:

Where do I put my Hello world PHP file on Ubuntu?

phpapache

提问by sashoalm

So I want to learn PHP, and I've installed it with "sudo apt-get install php5" on my Ubuntu 14.04 machine. I see it also installed Apache.

所以我想学习 PHP,我已经在我的 Ubuntu 14.04 机器上安装了“sudo apt-get install php5”。我看它也安装了Apache。

Now I've created my program, and I've saved it to a php file.

现在我已经创建了我的程序,并将它保存到一个 php 文件中。

 <?php echo '<p>Hello World</p>'; ?> 

I know that I need to use something like http://localhost/myfile.php, but where do I put the file, so Apache will see it?

我知道我需要使用类似的东西http://localhost/myfile.php,但是我把文件放在哪里,这样 Apache 就会看到它?

回答by Fluffeh

Pick a name for it lets use hello.phpfor this example.

为它选择一个名称让我们hello.php在这个例子中使用。

On Ubuntu the folder is /var/www/html, NOT /var/www. You will need root access for that. So you save the file as /var/www/html/hello.php.

在 Ubuntu 上,文件夹是/var/www/html,不是/var/www。您将需要 root 访问权限。因此,您将文件另存为/var/www/html/hello.php.

Open up a web browser and enter the following address:

打开网页浏览器并输入以下地址:

localhost/hello.php

localhost/hello.php

And BAM. There's you page.

和巴姆。有你的页面。

回答by Rodrigo E. Principe

The most voted solution didn't work for me. What I did to solve it was: searching directly in the root for the faq.html file that comes with XAMPP, and found that it was located in

投票最多的解决方案对我不起作用。我解决的办法是:直接在root中搜索XAMPP自带的faq.html文件,发现它位于

/opt/lampp/htdocs

/选择/灯/ htdocs

so there is where I put my files, and it worked perfectly. Cheers.

所以我把我的文件放在这里,它工作得很好。干杯。

回答by simplychrislike

The document root folder under *buntu 14.04 is /var/www/html/

*buntu 14.04 下的文档根文件夹为 /var/www/html/

The link for your browser is then: localhost/FILENAME.php

您的浏览器的链接是:localhost/FILENAME.php

回答by theDrifter

I had the same problems, but this solution did not work. When i tried to call my hello.php script via

我遇到了同样的问题,但此解决方案不起作用。当我尝试通过以下方式调用我的 hello.php 脚本时

ip/hello.php

The error logs from my apache gave this message

我的 apache 的错误日志给出了这条消息

[Fri Jun 26 16:21:27 2015] [:error] [pid +++] [client ip.ip.ip.ip:pppp] script '/var/www/vhosts/default/htdocs/hello.php' not found or unable to stat

When I moved the script from /var/www/html/to /var/www/vhosts/default/htdocsit worked.

当我将脚本从/var/www/html/移到/var/www/vhosts/default/htdocs它时,它起作用了。

回答by Prasanth

Assuming you have php5 and apache2 installed and apache running, here's how to get to script execution quickly.

假设您安装了 php5 和 apache2 并且 apache 正在运行,这里是如何快速执行脚本。

create script:

创建脚本:

echo "<?php echo '<p>Hello World</p>'; ?>" > /var/www/index.php

open browser:

打开浏览器:

gnome-open http://localhost/index.php
# or: 
sensible-browser http://localhost/index.php

回答by code it up

In order to make it possible for Apache to see and play with your helloWorld.php or any other file it should be inside /var/www/html/

为了让 Apache 能够查看和使用您的 helloWorld.php 或任何其他文件,它应该位于 /var/www/html/

But /var/www/html/ requires root privilege to write or create documents here. I.e use sudo in the terminal to open up the editor or simply extend the privilege to write and execute by using chmodcommand

但是 /var/www/html/ 需要 root 权限才能在此处编写或创建文档。即在终端中使用 sudo 打开编辑器或简单地通过使用chmod命令扩展写入和执行的权限