Making the php code execute in browser using PHPstorm - php

So PHPstorm is running the php code fine in its console when I click run, that's great but I want to see it in the browser.
So I created a new PHP web application inside PHPstorm, set up the server to "localhost:8000".
Now when I click RUN it opens the browser but I get an error message: "Oops! Google Chrome could not connect to localhost:8000"
What am I doing wrong??
Thanks!

You have to configure a run configuration for your project first.
Go to Run -> Edit Configurations, click on "PHP Built-in Web Server" and then press "+". You should see something like this:
After saving the settings you can run the web server via Run -> Run '<project-name>'. It should now serve up the pages to your browser.

Related

php artisan serve working but URL not working

I installed xampp and laravel in my system and while connecting my project in command prompt it shows as "Development Server (http://127.0.0.1:8080) started", whereas it is not launching the browser and I manually copy the link to the browser and it is not working and getting the below error. Please help me
enter image description here
Your screenshot shows that you're trying to connect to a different port (8000 vs 8080). Try http://127.0.0.1:8080 or http://localhost:8080.

Print from Browser: PHP and PyWin32 on IIS Server

I have a Python file, 'print.py', which exists on an IIS server and can print documents successfully from a network printer using PyWin32.
I have a PHP file, 'print.php', which exists in the same folder on the IIS server and can successfully execute 'print.py' when ran from the command line.
However, when I access 'print.php' from a browser on a separate computer, which has access to the server, nothing happens.
If I modify 'print.py' to simply output text, this works and the text appears in the browser. Only the printing is not happening.
What could be the reason for this?

How can I launch a local Application on OSX from php running MAMP?

I'm running a bunch of local Kiosks on mac mini's and have been using dropbox to keep all the files in sync. However - the dropbox updates have been sketchy as of late because of the firewall settings where these things are. A workaround I have found is by having dropbox quit and restart periodically to force it to update.
My question is - since all of these are running php applications on MAMP - is there a way to launch a local app from php? I'm able to kill dropbox by doing something like this:
$killit = killall -KILL Dropbox;
But it doesn't work the same to restart it. I've tried doing this:
$start_dbox = open /Applications/Dropbox.app;
To no avail. Is there a better way to automate this process of shutting down and reopening a local application?
I've had similar problems trying to control software remotely. The 'open' command must be executed either as the currently logged in console user, or from a terminal owned by the console (e.g. Terminal.app).
If you change your PHP to redirect STDERR, you should see the error that 'open' is returning:
$start_dbox = "open /Applications/Dropbox.app 2>&1";
The following text should then be returned from the system call:
LSOpenURLsWithRole() failed with error -10810 for the file /Applications/Dropbox.app.
One workaround I've used in the past is to create a lock file somewhere in the filesystem, which your PHP script can write to and your console user can read. Then, you can create a cron that runs as the console user and periodically checks the lock file to see if it needs to restart Dropbox.
I was actually able to solve this by creating a shell script with the following:
#!/bin/sh
export DYLD_LIBRARY_PATH=""
osascript -e 'tell application "Dropbox" to activate'
Saved it as start_db.sh and dropped it in my root apache directory (so there was no permissions problem for that user).
Then in my php file I was able to do:
$start_dbox = exec('/full/path/to/start_db.sh');
Worked like a charm. Dropbox now quits and restarts with no issues.

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