3

I am following a tutorial "PHP & MySQL for dummies" to build a web application. I created a simple test.php file in web space (/var/www/html). The problem is that when I type localhost/test.php in the browser address window, it returns me an empty page. I tried localhost/php.info and it worked well but I could not find why test.php does not work.

This is the test.php code:

 <html>
 <head>
 <title>PHP Test</title>
 </head>
 <body>
 <p>This is an HTML line
 <p>
 <?php
    echo “This is a PHP line”;
    phpinfo();
 ?>
 </body></html>

I do appreciate any information.

Thanks.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
mOna
  • 2,341
  • 9
  • 36
  • 60
  • empty page means no error ? – Babu May 06 '14 at 13:18
  • check the source code of the html you get – Babu May 06 '14 at 13:18
  • although I don't see it doing much, try and change the second

    to

    . Also, comment out the PHP, run locally (in browser) confirming it works, then the same on the server. If it then returns try and add back the PHP. Process of elimination.
    – Anthony Horne May 06 '14 at 13:20
  • @RyanBabu: yes, No erro, just an empty page, html is empry as well – mOna May 06 '14 at 13:20
  • restart your server and then try it – Boopathi Rajan May 06 '14 at 13:22
  • can you please tell your calling URL format – Babu May 06 '14 at 13:25
  • @Boopathi: I receive this error while restarting apache : Warning: DocumentRoot [/var/www/tutorial.com/public_html] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName – mOna May 06 '14 at 13:38
  • in order for me to help you could you fill me in on a couple things? 1. Do you have apache running and php installed? 2. What happens when you right click the empty page and choose view source? EDITED 3. Did you copy and paste the code from the tutorial? IF so retype the quotes. – James MItchell May 06 '14 at 13:23
  • 1. yes I have apache2 running and php installed 2.when I write click again the html is empty – mOna May 06 '14 at 13:26
  • ok can you install chrome and check the developer console network tab(while refreshing), you will see what code the page is returning. https://developers.google.com/chrome-developer-tools/docs/console – James MItchell May 06 '14 at 13:29
  • Please see the new edit. – James MItchell May 06 '14 at 13:37
  • Also while you're learning, this site will be helpful for debugging these errors http://3v4l.org/ . – James MItchell May 06 '14 at 13:46
  • Mitchell - In the future, please try to ask your clarification questions in comments and provide just the solution and explanation in your answer. Thanks and happy coding :) – Zachary Kniebel May 06 '14 at 14:02

2 Answers2

3

You said that you put your script in /var/www/html

So the link might be

localhost/html/test.php

Also check the error log file for PHP error.

# cat /var/log/apache2/error.log

EDIT: Change your quote, ” are for Word document and not programming ;-)

<html>
 <head>
 <title>PHP Test</title>
 </head>
 <body>
 <p>This is an HTML line</p>
 <?php
    echo "This is a PHP line";
    phpinfo();
 ?>
 </body>
</html>
OpenStark
  • 476
  • 2
  • 8
  • 1
    No even with localhost/html/test.php it did not work :( – mOna May 06 '14 at 13:27
  • Do you have anything in the error file ? Have you tried to restart apache ? "sudo /etc/init.d/apache2 restart" – OpenStark May 06 '14 at 13:28
  • 2
    I checked the error log: this is the error: PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/html/test.php on line 9 – mOna May 06 '14 at 13:34
  • Maybe try to reinstall the environment with this tutorial http://doc.ubuntu-fr.org/lamp#alternative_2installation_des_paquets_methode_recommandee – OpenStark May 06 '14 at 13:36
  • when I try to restart apache I receive this error: (I never received this error before) Warning: DocumentRoot [/var/www/tutorial.com/public_html] does not exist apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName – mOna May 06 '14 at 13:37
  • Ok, you just have to change your double quote “ and ” by this one ". It's an encoding issue... – OpenStark May 06 '14 at 13:37
  • I don't recommend PHP&MySql for dummies, it's not the best book to learn for scratch. To many thing at the same time for nothing... You can check this website to learn the basics http://www.codecademy.com/tracks/php – OpenStark May 06 '14 at 13:51
  • thanks alot! the problem was solved by changing double quotes to "" :) – mOna May 06 '14 at 14:08
-1

I have tried with this..just type the word localhost followed with name of the work eg.. localhost/test.php in the navigate bar on your browser then click enter

fred
  • 11