Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP and Apache PROBLEM!

Options
  • 19-03-2014 7:43pm
    #1
    Closed Accounts Posts: 147 ✭✭


    Hi,

    I am running Ubuntu on a VM where I have installed php5, apache2 and mysql server. However, when I write a php program using nano, something as simple as a loop from 1-100, it doesn't appear on my 192.160.x.x/loop.php(name of file).

    Any reason why?

    Thanks.


«1

Comments

  • Registered Users Posts: 8,432 ✭✭✭RedXIV


    What directory do you have the php file in?


  • Closed Accounts Posts: 147 ✭✭Stanlex


    RedXIV wrote: »
    What directory do you have the php file in?

    /var/www


  • Closed Accounts Posts: 147 ✭✭Stanlex


    I made a phpinfo program

    <?php

    phpinfo()

    ?>

    ...and it works when I open it in the browser. Also in /var/www


  • Technology & Internet Moderators Posts: 28,799 Mod ✭✭✭✭oscarBravo


    When you say "doesn't appear", do you get a blank page? A 404? What?


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    When you say "doesn't appear", do you get a blank page? A 404? What?

    I tried a for loop program, saved it in /var/www and it comes back with a blank page. Then I tried accessing a database with in php and it returns "Not found". Once again, saved in the same folder.


  • Advertisement
  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Stanlex wrote: »
    I tried a for loop program, saved it in /var/www and it comes back with a blank page. Then I tried accessing a database with in php and it returns "Not found". Once again, saved in the same folder.

    Can you post the code, if you have any reference to mysql functions in the code and you haven't setup the mysql module properly this can occur, set php to display all errors on screen and see what you get.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Ziycon wrote: »
    Can you post the code, if you have any reference to mysql functions in the code and you haven't setup the mysql module properly this can occur, set php to display all errors on screen and see what you get.

    Here's an example of the code:

    <?php


    mysql_connect('localhost', 'root', 'password');


    mysql_select_db('test_db');


    $result = mysql_query("select * from contacts");


    $numrows = mysql_numrows($result);

    echo "There are $numrows in the table.";

    mysql_close();
    ?>


  • Closed Accounts Posts: 147 ✭✭Stanlex


    e5h6o2.png

    Does that look okay? That's like that by default but yet no error messages.


  • Registered Users Posts: 26,571 ✭✭✭✭Creamy Goodness


    Firstly I'd be looking at the php error log it ironically will tell you what's wrong. You can find its location in the php.ini file.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Firstly I'd be looking at the php error log it ironically will tell you what's wrong. You can find its location in the php.ini file.

    Post #9


  • Advertisement
  • Registered Users Posts: 6,392 ✭✭✭AnCatDubh


    as you report it, your phpinfo code is a success, thus your basic php/apache setup would appear to be ok.

    try taking a look in /var/log/apache2/error.log and see if you are getting any error output when you run your script.


  • Registered Users Posts: 772 ✭✭✭maki


    Can you attach your whole php.ini file? That bit in the screenshot is just the reference area and is commented out.
    Otherwise what you're looking for in that file is to make sure that:
    log_errors = On

    You can then set the location of the log by using something like this:
    error_log = /var/log/error_log (or wherever you want to put it)


  • Registered Users Posts: 29 B000


    Try enabling errors with these commands. Put them at the top of your script.
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Looks to me like mysql module isn't set up properly, if you view phpinfo() does the mysql section show up? Also post #10 is a good start, looking in the logs will point you in the right direction, what you've put in post #9 is the options, it's not the actual settings in your php.ini file, you need to scroll down further to see what's set, the semi-colon ';' is used to comment out a line.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    This is the error.log file

    2i89fg6.png


  • Technology & Internet Moderators Posts: 28,799 Mod ✭✭✭✭oscarBravo


    Can you use cat instead of nano? It's a bit useless with the ends of the lines missing.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    Can you use cat instead of nano? It's a bit useless with the ends of the lines missing.

    Of course.

    2m6n0qh.png


  • Closed Accounts Posts: 147 ✭✭Stanlex


    The table.php file contains php/sql code that I posted earlier in the thread. That file is located in /var/www.

    How do you actually run PHP, just save and refresh the browser?


  • Technology & Internet Moderators Posts: 28,799 Mod ✭✭✭✭oscarBravo


    Could be a permissions issue. Can you "ls -l /var/www"? (Those are both lowercase Ls.)


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    Could be a permissions issue. Can you "ls -l /var/www"? (Those are both lowercase Ls.)

    33k507q.png

    The table.php file is not there for some odd reason.


  • Advertisement
  • Technology & Internet Moderators Posts: 28,799 Mod ✭✭✭✭oscarBravo


    There's your problem. How did you create the file? Just "nano table.php" while logged on as root? Because that will put it in /root, not /var/www.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    oscarBravo wrote: »
    There's your problem. How did you create the file? Just "nano table.php" while logged on as root? Because that will put it in /root, not /var/www.

    But when I run ex1.php, it doesn't work either.


  • Closed Accounts Posts: 147 ✭✭Stanlex


    33davt2.png

    Still doesn't work. What I do is, write the code in Nano, save it and enter 192.168.x.x/table.php in to my browser. Just an empty screen. Nothing.


  • Registered Users Posts: 772 ✭✭✭maki


    Nothing in the error log after running it this time?


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Drop the below into a file and go to it in your browser, search for mysql, post what you find if anything relating to mysql please
    <?php
    phpinfo();
    


  • Closed Accounts Posts: 147 ✭✭Stanlex


    Ziycon wrote: »
    Drop the below into a file and go to it in your browser, search for mysql, post what you find if anything relating to mysql please
    <?php
    phpinfo();
    

    10rq0wm.png


  • Closed Accounts Posts: 147 ✭✭Stanlex


    maki wrote: »
    Nothing in the error log after running it this time?

    2yynv2h.png


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Stanlex wrote: »
    10rq0wm.png

    Is that it, no other references to mysql or sql? Is the phpinfo() page publicly available if so can you pm the url and I'll have a quick look?


  • Registered Users Posts: 772 ✭✭✭maki


    Looks like it's not finding the mysql client libraries.
    Have you the php mysql libraries installed?
    sudo apt-get install php5-mysql

    By the way, in php you should be using mysqli functions instead of mysql.
    http://php.net/manual/en/mysqli.overview.php


  • Advertisement
  • Closed Accounts Posts: 147 ✭✭Stanlex


    I've found my problem. It's something very ridiculous and noob like.

    Well this is how I found out what it was.

    1. I turned errors on. Found a way and it worked.
    2. Decided to make a basic database in mysql
    3. Used php and html to get it on the server/browser
    4. Yesterday I had a problem with it appearing on the browser. The table just wouldn't appear.
    5. Well today, since I turned errors on, it told me "Access denied" even though my password in the php file was correct.
    6. I knew there was something wrong and the apache server wasn't talking with my directories.

    Now what the problem was.

    All my files were saved in ~/var/www Hence the ~

    ...instead of... /var/www

    When I copied them over it all worked fine. What made things really difficult was the fact that I was running a Ubuntu server on a VM so the interface was constantly the terminal.

    Anyway, the fun of debugging huh?

    Thanks to everyone who helped!


Advertisement