I'm trying to run a .php web application on Google Chrome, using Uniform Server. I thought that just having that installed would make PHP run, but clearly there's a lot I don't know. First off, when I opened the file from file:///C:/Users/... etc the PHP didn't execute properly. Here's the code:
<html>
<body>
Hello to you, good sir.
<?php
echo "</br> Hello there yourself.";
?>
</body>
</html>
Here's the output on the website:
Hello to you, good sir. Hello there yourself."; ?>
And here's how the <body> code looks from Chrome:
Hello to you, good sir.
<!--?php
echo "</br-->
Hello there yourself.";
Then, when I tried accessing the file from localhost, Chrome wouldn't even connect, saying:
Oops! Google Chrome could not connect to localhost
I'm aware of this question, but the OP didn't appear to have software needed to run PHP. I'm pretty sure I have the right software, but I don't know how to use it. How do I get Uniform Server to run PHP, and how do I connect to localhost from Chrome?
PHP wont work if opened directly in browser, thats not how PHP works, it needs to be run through the PHP parser.
A Step by step:
Download the Latest package
Unpack it onto desktop or C:, (somewhere your find it)
Open up the UniServerZ folder, where you unpacked it
Double click UniController.exe
Click Start Apache button - it should go green like below
Remove the junk files in UniServerZ/www
Put your PHP files inside that www folder.
Visit http://localhost to view your PHP files
Related
I am learning about databases and GUI to make database management more user friendly. I successfully downloaded wampserver (3.0) and mysql (5.7). To test if the php prints "Hello world" (see PHP script below).
Script (saved as name.php)
>?
echo "Hello world";
?<
My output in the browser is:
>?
echo "Hello world";
?<
Can someone give advise me on what the problem is, and how I can fix it?
PHP scripts start with a <?php and end with a ?>:
<?php
echo 'Hello, World!';
?>
As correctly pointed out in the comments, the ?> a the end of a file is optional and should - in most cases - not be used.
This will also work:
<?php
echo 'Hello, World!';
In PHP scripts where you don't mix PHP and HTML this is the way to go.
If you want to work with your databases using a web GUI once you have installed WAMP you can open up any web browser (be it firefox or chrome or whatever) and in he address bar write http://localhost/phpmyadmin or simply localhost/phpmyadmin . If you did not set any password during setup for your database the default credentials are user 'root' and no password. Phpmyadmin is a very user friendly web GUI for managing mysql databases that comes with basic setups of wamp and xampp
Also if you want to verify if php was installed correctly from a console window you can type php -i which would display info aboout your current version/setup/extensions installed/etc.
I recently installed an Apache2 web server, and PHP5 on my Raspberry Pi, and hooked it to my home router. It all works fine in terms of displaying HTML, even when the index document is a .php file. However, as soon as I try to enter any PHP code, and run it through my browser, it's completely removed from the document.
<html>
<head>
<?php
$baseUser = fopen("GCusernames.txt", "a");
$newUser = $_POST['user'];
fwrite($baseUser, $newUser);
fclose($baseUser);
?>
</head>
<body>
<h1>Writing to userbase</h1>
</body>
</html>
PHP document inspected in my browser
I've tried changing it back and forth to a HTML file and scouring the internet for clues. But everything I found was seriously unclear and vague.
I'd appreciate any help at all. Thanks.
UPDATE: So after I realized how idiotic I was (thank you everyone who answered,) I now understand that the PHP code shouldn't show up in the browser anyway. Sorry about that.
However, it still doesn't explain why the code doesn't execute at all. It just goes straight to the PHP page, rather than executing it.
PHP is interpreted by the server, it is not send to the user.
Thats what PHP is for.
For Example:
You want to make a password login. You write the passwordfunction in php because the user cannot see it.
More Information on PHP
PHP is run by the server that your '.php' file lives on, in this case, your Raspberry Pi. When you request a page from your PI your PHP code will be executed before any HTML is returned to your browser.
You will never see your PHP code in your browser's inspector because your browser never even knows it existed.
If you added something like:
<?php echo "This sentence was written by PHP"; ?>
to your page, you would see the text This sentence was written by PHP in your HTML but you wouldn't see the word echo or the <?php ? tags.
There is a great piece in the PHP docs which explain the three main abilities of PHP. They also have a good guide on how to get started with PHP which may be worth checking out if you are not that familiar with it.
Further Reading:
PHP enabled page
Many people try out codecademy
With the following code below,
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
I want only the Hello World statement to be printed, but it also prints out ;?>.
After I inspected the element, it came out like this.
<body>
<!--?php echo '<p-->
Hello World
<p></p>
"; ?>"
</body>
Your website is treated as plain HTML. Ensure that you have a webserver running:
If you have accesst to the command line on a Gnu/Linux derivate you can start PHP's internal server by:
php -S 127.0.0.1:1337
This command has to be started in your web root and you should have an index.php living there. Then your code runs fine.
In the long run, you want to set up a nginx or an apache2. Another aspect to look into is using vagrant to setup a virtual Linux machine that creates your development enviroment.
You are trying to open the file directly in your web browser, but unlike HTML, your browser is incapable of understanding PHP.
PHP needs to be run server-side behind Apache, Nginx or any viable web server, your web browser will then request pages from that webserver, which will request PHP to serve your browser the fully generated page.
Practically, if you're trying PHP for the first time, you want to install a development LAMP stack such as WampServer (for Windows only), XAMPP (for Linux, Windows, OS X) or MAMP (for OS X, Windows). Installing and running this will easily set up a web server on your computer.
I will not write a full tutorial on how to use a LAMP stack but I can recommend you to read that article from Kasia Mikoluk on Udemy. It should teach you the basics.
So I've done a bunch of research and tried a bunch of things that it'll be difficult to try and explain everything i've already done but here's my issue.
My website isn't interpreting PHP code, whether I try to use an include 'file.php'; or just input the code directly into the HTML it doesn't matter.
I'm running Windows 7 with IIS 7.5 with PHP installed from php.iis.net. I'm going to keep it simple rather than go into the specifics of exactly what I'm trying to do, and hopefully once I get the simple things working the more complex stuff I'm working on will work.
Here's the HTML piece:
Weather condition is currently <?php echo '<p>Hello world</p>'; ?>
The output is
Weather condition is currently Hello world '; ?>
The beginning bracket of the PHP is hidden, after World its showing the rest on a new line under the text.
I also have
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>
That returns nothing on the webpage, and if you look at the source code you see the full PHP code. Same with the Hello world example, the text doesn't show the ?php portion but viewing the page source you see the full php.
There's something I'm missing somewhere in the IIS config or the PHP config and I'm just not finding it.
Any insights or ideas I'm open to try. This is a fresh IIS and fresh PHP install, I installed IIS on this workstation specifically to get this PHP script to work so it is doing nothing else but hosting this web page.
thanks!
I have installed WAMP server 2.0 with (PHP 5.4.3). After installing WAMP I have restarted all the services and can open
phpinfo() - it is showing up fine
phpmyadmin - it is also showing up fine.. i can play with database..
however when run simple php file in chrome I could see the code rather than result. below is the code i am trying..
<?php
echo "hello world";
?>
below is the link to file which I am trying to access via chrome.
file:///C:/WAMP/www/hello%20world.php
Make sure you have started apache
Try http://localhost/hello_horld.php
To run this script, start a browser use URL http://localhost/your_file.php or http://127.0.0.1/your_file.php
PHP is a server-side technology (instead of client-side technology like JavaScript). The PHP statements <?php ... ?> are processed in the server, and the results returned to the client (browser). so you need to use it through server not direct