Hi All,
I'm new to PHP. I've started service apache2 and put a testphp.php file in its webroot directory with the following content

<?php
phpinfo();
?>

But when I want to see the result in the browser, the browser opens the source file instead of showing the contents of PHP language specification.
Greatest Thanks for anybody who helps me.

Member Avatar for diafol

You confirmed that Apache is actually running?

Did you install XAMPP? Did you get the default page? This is in .../htdocs/ directory right?

Check your Apache files, you should have something like the following:

At the end of - C:\xampp\apache\conf\extra\httpd-vhosts.conf

NameVirtualHost *:80
<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs"
   ServerName localhost
</VirtualHost>

At the end of - C:\Windows\System32\drivers\etc\hosts

127.0.0.1       localhost
::1             localhost

This is assuming you're on Windows.

Ontop of what diafol has said, make sure the file format is actually a .PHP file.

Some text editors have it set automatically to .txt or .html so even if you call it, 'testphp.php' it is actually calling it 'testphp.php.html'

Do as suggested above, otherwise, it appears to me that you maybe using an ubuntu? or any linux derivs ? How did you install your server? conical or command line?

Let me know if it is Linux distros... that should be an easy fix...

sudo :)....

Thanks everybody,
The problem has been resolved. Was there The abrasion that apache2 was not actually started. I installed a Wamp server and set the port to 78 (because 80 was busy). After all I gave permission by turning "deny from all" to "allow from all" in httpd.conf. Now I can code php and enjoy it. I hope you enjoy coding, too.
Warmest Regards, Parsa

Member Avatar for diafol

The abrasion that apache2 was not actually started

Yep, that'll do it. :)
Glad you came back and let us know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.