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

前端 未结 6 817
半阙折子戏
半阙折子戏 2021-02-13 22:04

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.

Now I\'ve created my progra

相关标签:
6条回答
  • 2021-02-13 22:45

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

    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
    
    0 讨论(0)
  • 2021-02-13 22:48

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

    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.

    Open up a web browser and enter the following address:

    localhost/hello.php

    And BAM. There's you page.

    0 讨论(0)
  • 2021-02-13 22:54

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

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

    0 讨论(0)
  • 2021-02-13 22:54

    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/

    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 chmod command

    0 讨论(0)
  • 2021-02-13 23:05

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

    ip/hello.php
    

    The error logs from my apache gave this message

    [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/htdocs it worked.

    0 讨论(0)
  • 2021-02-13 23:07

    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

    /opt/lampp/htdocs

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

    0 讨论(0)
提交回复
热议问题