Find the answer to your Linux question:
Results 1 to 10 of 10
Learning PHP and after uploading my files to a webserver, I can see my efforts OK. I've installed PHPMyAdmin, signed in as 'root' (localhost, etc...) All seems to be running ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2012
    Posts
    15

    Can't Run a PHP File Locally


    Learning PHP and after uploading my files to a webserver, I can see my efforts OK.

    I've installed PHPMyAdmin, signed in as 'root' (localhost, etc...)

    All seems to be running OK.

    In the same browser, Firefox, file>open file...I choose my php file and get the 'open with' box.

    How do I associate my php file with the already up and running myPHPAdmin?

    Using Ubuntu 12.04 in KDE mode.

  2. #2
    Just Joined!
    Join Date
    Sep 2012
    Location
    Nashville, TN
    Posts
    97
    Not sure I really understand what is being asked, but I am going to give it a shot. You can't open up your php file directly from a browser. The php page need to go through the php engine in order for it to do the tag replacement.

    If you are running a web server on your local machine you would type in Open Source and Linux Forums to access the webpage. When doing that you still get the open page then you will need to tell the apache file that index.php is a DocumentType.

  3. #3
    Just Joined!
    Join Date
    Jan 2012
    Posts
    15
    Thanks for that. I understand now.

    UPDATE!!!

    Just read that you can set up a web server. I've edited http.conf and added 'ServerName localhost', restarted but still can't run the file locally.
    Last edited by chome4; 03-11-2013 at 07:00 PM.

  4. #4
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    883
    You don't 'open' the file with file open. You enter the url in the address bar like any other website:
    http://localhost/somedirectory/myfile.php

  5. #5
    Just Joined!
    Join Date
    Sep 2012
    Location
    Nashville, TN
    Posts
    97
    Quote Originally Posted by chome4 View Post
    Thanks for that. I understand now.

    UPDATE!!!

    Just read that you can set up a web server. I've edited http.conf and added 'ServerName localhost', restarted but still can't run the file locally.
    Ok I think I see what the problem is. Yes you need to have a web server in order to run PHP scripts that are web based. If you want to use php on the command line you will need to install the php-cli extension.

    Here is a link: ( https://help.ubuntu.com/community/ApacheMySQLPHP ) that will give you more information to get you up and going. You can skip the mysql part but I recommend it as you get further along and you start creating more and more projects you will start to introduce dynamic content and this is where mysql will come into play.
    Last edited by bsdtux; 03-11-2013 at 07:39 PM. Reason: Forgot to include link.

  6. #6
    Just Joined!
    Join Date
    Jan 2012
    Posts
    15
    I can see the 'it works!' page, which is /var/www/index.html

    Using sudo gedit, I can edit the above file. When change it to be a 'hello world' php file and save it as index.php, I get lost.

    /var/www/index.html is arrived at by simply entering localhost

    If I type localhost/var/www/index.php, I get:

    Not Found

    The requested URL /var/www/index.php was not found on this server.
    Apache/2.2.22 (Ubuntu) Server at localhost Port 80

    My syntax is now the issue!

    How do I display any php file in place of index.html?

  7. #7
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    883
    The webserver software is Apache.
    PHPMyAdmin is a tool to configure MySQL.

    Anyway, you should consult a tutorial, such as this one: Ubuntu 12.04 Web Server

  8. #8
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    3,190
    Using sudo gedit, I can edit the above file. When change it to be a 'hello world' php file and save it as index.php, I get lost.
    If you change the index.html file in /var/www/ to index.php, you need to open a web browser (firefox?) and just enter in the browser: h.t.t.p://localhost/index.php]]

    You do not put the file path "/var/www/index.php". If you do that, it won't work.

  9. #9
    Just Joined!
    Join Date
    Jan 2012
    Posts
    15
    Finally got it!

    Thanks.

  10. #10
    Just Joined!
    Join Date
    Jan 2012
    Posts
    15
    Quote Originally Posted by mizzle View Post
    The webserver software is Apache.
    PHPMyAdmin is a tool to configure MySQL.

    Anyway, you should consult a tutorial, such as this one:...
    Thanks for the link.

Posting Permissions

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