Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: [SOLVED] PHP - Hello World

  1. #11
    Join Date
    Jan 2008
    Beans
    4,757

    Re: PHP - Hello World

    To get your localhost up and running, install the lamp-server packages.

    Open up a terminal and type in:
    Code:
    aptitude
    Scroll down to Tasks, press Enter
    -> Unrecognised Tasks, press Enter
    -> -> lamp-server, press +

    Then press g a few times to confirm the selection (enter your password), then g again to begin the installation.

    Once it has finished, press q to quit aptitude, and type in the following into a web browser:
    Code:
    http://localhost
    In your browser, and you should get a page saying:
    Code:
    It works!
    Next, to setup PHP, run the following:
    Code:
    sudo a2enmod php5
    sudo /etc/init.d/apache2 restart
    Now, for anything else you wish to test, just drag and drop all files you write into the /var/www folder, then type in their names into the firefox web browser:
    Code:
    http://localhost/hello.php
    Though, since you'll probably be wanting to keep your web server private to only you, I recommend that you setup your firewall:
    Code:
    sudo ufw default deny
    sudo ufw enable
    And all incoming connections without the ACK bit turned on will be denied (So you can connect to the outside world, but they can't freely connect to you without your permission first).

    For an easy to setup GUI frontend for ufw, check out gufw.

    Regards
    Iain
    Last edited by ibuclaw; December 30th, 2008 at 03:01 AM.

  2. #12
    Join Date
    Dec 2006
    Beans
    121

    Re: PHP - Hello World

    I thought I had installed PHP5, but it looks like I missed it. I just installed PHP5 and PHP5-cli (shotgunning a bit). I still seem to have the same problem, though.

    Thanks,

    SteveJ

  3. #13
    Join Date
    Nov 2007
    Location
    São Carlos, Brazil
    Beans
    136
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: PHP - Hello World

    Quick checklist for you, all right?

    1) Have you checked if your file is .php extension??

    2) Is your file located at the folder your Apache uses as root for the web browsing, or in a sub-folder of it? (I mean, the folder it seeks when you type on your browser http://localhost/.)

    3) Are you making sure you are NOT trying to access it through File > Open File... option, or putting it's hard drive address into the browser? You are supposed to access it through http://localhost/<folder of the file>, otherwise the PHP processor won't do a thing.

    4) Is your Apache with the PHP5 Module activated? You can find aewsome guides in Google typing things like "install lamp ubuntu intrepid". I'd suggest you completely uninstall all applications for Apache and Apache itself and follow one of those guides if you are in doubt if anything you already did might be breaking it.

    The "Hello World" code of yours should work if your Apache is all set. I hope it helps you.
    João Paulo Melo de Sampaio
    Computer Engineering Student @ UFSCar
    Site: http://www.jpmelos.com
    Twitter: http://www.twitter.com/jpmelos (@jpmelos)

  4. #14
    Join Date
    Dec 2006
    Beans
    121

    Re: PHP - Hello World

    Then press g a few times to confirm the selection (enter your password), then g again to begin the installation.
    It says that I have no software packages waiting to install.



    In your browser, and you should get a page saying:
    Code:

    It works!
    I get that.



    Next, to setup PHP, run the following:
    Code:

    sudo a2enmod php5
    sudo /etc/init.d/apache2 restart
    Yep;



    N
    ow, for anything else you wish to test, just drag and drop all files you write into the /var/www folder, then type in their names into the firefox web browser:
    Code:

    http://localhost/hello.php
    This part doesn't work. Says the file doesn't exist. My file is test.php. It is in /var/www
    Attached Images Attached Images

  5. #15
    Join Date
    Dec 2006
    Beans
    121

    Re: PHP - Hello World

    It says that I have no software packages waiting to install.
    OK, went back and got the lamp-server to install.

    Now, when I type http://localhost, I get the file not found error? I verified that index.html is still in var/www, and it does work when I go there via FireFox.

    Thanks,

    SteveJ

  6. #16
    Join Date
    Dec 2006
    Beans
    121

    Re: PHP - Hello World

    Heh, what do you know! When I browse to test.php in Firefox, I get my PHP page. It works!

    I just wrote my first PHP code in Ubuntu! I'm as giddy as a school girl! Thanks Iain !!!

    SteveJ

  7. #17
    Join Date
    Jan 2008
    Beans
    4,757

    Re: [SOLVED] PHP - Hello World

    Try stopping and restarting the apache service:
    Code:
    sudo /etc/init.d/apache2 stop
    sudo /etc/init.d/apache2 start
    Have you done anything else that I have not mentioned when you tried to setup the web server ?

    Also, you are typing in http://localhost/test.php , right ?

    [EDIT]
    Ah, ok... as long as it is all good, and working fine
    Enjoy your PHP/SQL experience...

    Here's my Hello World:
    Code:
    <html>
    
    <body>
    
    <h1>It works!</h1>
    
    <?php
    $name = $_GET['x'];
        if(isset($name)) {
            echo "Hello $name";
        }
        else {
            echo "Hello World";
        }
    ?>
    
    </body>
    
    </html>
    Now type in : http://localhost/test.php?x=SteveJ and say hello to input arguments

    Regards
    Iain
    Last edited by ibuclaw; December 30th, 2008 at 05:27 AM.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •