localhost does not process php script correctly - php

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.

Related

issue with PHP on IIS 7.5

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!

Can't connect to localhost using Chrome with Uniform Server

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

PHP or WAMP not sure what

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

Server side script for launching application

I have been trying unsuccessfully so far to write a php script that will run when a page is opened and that will launch metasploit!
I ve tried shell_exec and exec and all the other alternatives but although I can get it to do simple things (i.e. ls, cds etc) if I try msfconsole it doesnt do anything!
I have also tried a different script that launches firefox and again nothing happens!
Now i know that php runs on the server and I m not expecting to see a console or firefox opening in the clients machine! Instead in order to check if it works I am trying to echo out the output of the shell_exec!But anyway since im hosting the files on my machine (i.e. this is the server and a VM is the client) if it could actually launch firefox i should be able to see the app opening here in the same way as by just doing this from the command line!
What am I missing?
Is there any other way to do this?(i.e. Launch metasploit everytime a user opens up my page)
NOTE: I've tried specifying the full path for msfconsole but that didnt work either!
Heres what I have so far:
$output = shell_exec('/opt/local/libexec/metasploit3/msfconsole;show');
echo "<pre>$output</pre>";
The ";show" bit was used in order to actually make it run something and print some stuff but didnt make any difference!
When you run a gui application from the command prompt in a X window system, it will use the default display. When you run it using php which is embedded in apache webserver, the program may not know where to display the gui application.
there are 2 things to make this work.
The program that executes the gui application must have permission to use display
you need to tell the program which display to use.
I used the following in my php script
<?php
$cmd = `export DISPLAY=:0; gedit`;
shell_exec($cmd);
?>
and ran the script from terminal using php -f test.php
I got the gedit up and running.
You can test the same with the script in apache too.
Please add apache user with privileges to access display server
update: I just added the following in /etc/apache2/apache2.conf (I am using ubuntu)
User poomalai
Group poomalai
and restarted the web server
sudo service apache2 restart
now I accessed localhost/test.php
and Presto!! I got the gedit :)
Hope this helps

PHP: Messaging/Logging to Eclipse Console?

Is it possible to send messages from a PHP script to the console in Eclipse? Has anyone attempted this already? I'm not very familiar with how the console works, so I'm not sure if there is a standardized method for communicating with it.
If you look at...
Main Menu -> Run -> External Tools -> Open External Tools Dialog.
In there I have set up PHP Codesniffer with the following...
Name : Code Sniffer
Location : /usr/bin/phpcs
Working Directory : ${workspace_loc}
Arguments : --standard=${resource_loc}
That runs the codesniffer as an external tool and all the messages it returns appear in the console. Once you have set it up, click the down arrow and choose "Code Sniffer" and then anything the external program (in this case codesniffer) outputs will be in the Eclipse console.
If you set it up like this...
Name : PHP
Location : /usr/bin/phpcs
Working Directory : ${workspace_loc}
Arguments : ${workspace_loc}${resource_path}
It will just run php in CLI mode and if you run it with Wilco's code (above) you will get.
Hello World
In the terminal.
Hope that helps.
Any echo or print you do should go to the console automatically. This has been very unreliable for a long time, however. Please vote to have this bug fixed at:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282997
All output from an Eclipse external tool launch goes to the console by default, so if you execute a PHP script using an external tool launcher any output from the script will go to the console.
For example:
<?php
echo "Hello World\n";
?>
Will send "Hello World" to the console.

Categories