php server doesn't seem to execute code, although server is running - php

I haven't worked in a very long time with php so this question may be a very noob one.
I've installed apache server 2.0.65, and although when i call the localhost, my page in htdocs gets executed, only the html code appears in the view. The php code appears in the source view as html would, thus leading me to believe that it doesn't get interpreted.
My code is the from w3school:
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
what am i not doing ok?

You did not install PHP
You did not configure PHP to run your file (by default it will process files with a .php extensions)
You aren't actually visiting http://localhost/foo.php in your browser

Apache would just run HTML, CSS. In order to make PHP work, you must install PHP, and set environment variable on your local machine, so that all files with .php extension would be run by PHP.

Filename must have a .php file extension.
PHP must be installed and running - if you can open a terminal and type php -v or use top to see if php is running.
If you are running on your local computer try installing WAMP or something similar.

Related

When i ran php file in HTML , it didn't actually show up the result code that was expected

I ran this in chrome browser but it didn't show the expected results...
It showed the exact same code which was written
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
To run PHP code in your browser, you need a server like XAMP, WAMP, etc. I recommend XAMPP as it is quite easy to use.
Download XAMPP from here: https://www.apachefriends.org/index.html
After the installation is done, go the the htdocs folder (C:\xampp\htdocs in windows) and paste your .php file there. After that, open XAMPP control panel and start Apache. Open http://localhost/test.php (assuming the filename is test.php) in your browser and see the result. Done!
Before working on PHP Codes. You should know how to run PHP codes in browser.
If you dont have any server then please install some server like XAMPP, WAMP, etc.
Also, If you have installed the server then might be the file you are running on browser has html extension. It should be a .php extension.
& should run using
http://localhost/test.php (If its in htdocs folder)
I suggest you to see the below documentation before working on PHP.
https://codeofaninja.com/2013/06/how-to-run-a-php-script.html

How to get Embedded PHP working in HTML?

I am a beginner in PHP and I am trying to embed PHP in HTML as that is how I am going to need it in my project. This one is a very simple code saved as Trial.html
<html>
<head>
<title>Trial Page</title>
</head>
<body>
Hello, today is <?php echo "a great day!"; ?>.
</body>
</html>
When I load this page from server (I am running Apache Tomcat 7 locally), Only the HTML part is getting displayed and the PHP part is not. What am I missing? Do I need to include anything else or am I taking a completely wrong approach for this?
Rename "Trial.html" to "Trial.php" this is essential when you try to run php code.
You should save your file as .php and run it on a server with php installed on it.
check XAMP to install a local server
EDIT
Just saw that you're running Tomcat, just make sure php is installed, that your server is running, you're running your file from the server And your file is save as .php
You change file name from trial.html to trial.php

my .PHP file doesnt seem to work

i have a rather simple .PHP file with the following code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>hello world</p>
<?php echo "test";
?>
</body>
</html>
yet when i run it all i see is "hello world", i checked firebug and it showed me this
and in chrome it simply comments the php out
am i missing something important here?
PHP is an pre-processed, interpreted language which means a web server (like apache) with the PHP interpreter installed must serve it to you. You must install a webserver on your local machine and access it via a URL like http://localhost. PHP cannot be viewed the same way as locally-served HTML files (like what happens when you double click them) through the file:// prototcol.
But never fear, it is not hard to get a webserver installed. Try something like XAMPP, which will install Apache, PHP, and MySQL for you and give you a nifty little control panel.
You seem to be missing PHP. Where is the file located? Are you trying this in a server?
If you are new to PHP I recommend you using WAMP or LAMP, it's the easiest way to start using the languague.
A quote from here PHP gets commented out by the browser
Browsers shouldn't comment out PHP, they shouldn't even see PHP.
Most likely, what you are experiencing is that the <? is not being
parsed by the PHP engine and being delivered to the browser. The
browser is then treating it as an unknown tag and ignoring it.
The solutions are:
Don't use short tags as they are not turned on for all PHP installations. If you have > <? some code change it to <?php some code
2.Make sure you are trying to run your PHP on a server that supports PHP.
Try installing XAAMP, It will install everything you need for PHP Development.
Oh! I think you're saving it as .PHP with capital letters, Don't use capital letters, Use small letters, so your file name should look something like test.php.

web browser not processing PHP code as PHP code

I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.
For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:
<body>
<?php echo "hello"; ?>
</body>
instead of the HTML conversion. (i.e. just "hello")
Does anyone have an idea about what's going on here?
Thanks.
It's probably because PHP module isn't loaded in your apache. Be sure it is enabled
PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.
My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)
Second guess: is the directory containing your PHP files configured to parse PHP?
If you have Joomla, you probably have PHP. You probably also have Apache.
So check your Apache configuration, and check your file naming conventions.
Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.
Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.
if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.
Just restart httpd service. It will work fine.
sudo systemctl restart httpd.service
if it has not worked please reinstall PHP once again.

Call to PHP prints source, doesn't run when called from another file

I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.

Categories