Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm using a latest Geany version from official repositories, same with a php5 package. Theres my question:

  • How to run PHP code from Geany in browser (for eg. in Firefox) instead of terminal?

I know, there are some options about what program needs to be runned (terminal, browser, and grep), but I have no idea where it is used.

Edit: 16.03.2013: So, I found something interesting: running php -S localhost:8000 will create a local server with main directory where the file is saved. But I want to make that as flexible as it is in NetBeansIDE, where when I click F5, the browser is opening, and when I close the browser, the server is also shutting down. I tried something like php -S localhost:8000 "%f" && sensible-browser localhost:8000, but it don't even open a browser window/tab. I will be happy if anyone find a solution for this!

Edit: 05.09.2013: I found it :) The build command is: php -S localhost:8080 -t "%p" -e & sensible-browser localhost:8080/"%f"

share|improve this question
2  
Have a search for: webserver, apache, lamp. –  Rinzwind Mar 3 '13 at 14:18
add comment

2 Answers

php doesn't run in the browser, it runs on the server. You need to install a web server with php support. The Ubuntu Server Guide documents this in detail. You can easily get started by installing the libapache2-mod-php5 package

$ sudo apt-get install libapache2-mod-php5

And then you can put a php file where the apache server can read and execute it. e.g. /var/www

$ echo '<?php phpinfo(); ?>' > /var/www/test.php

Now visit http:// localhost /test.php and you should see the php info page. (I had to break this url to make askubuntu happy - links cannont contain localhost.)

See also: https://help.ubuntu.com/12.04/serverguide/php5.html

share|improve this answer
1  
Thanks, but it's not what I want. I have already installed 'php5' metapackage, what contains Apatche server and PHP (in version 5.3.x i think). I just want to redirect Geany to that localhost server. Similiar thing is doing in NetBeans IDE. –  Roomy Mar 3 '13 at 18:55
    
I suggest you ask that question, or maybe I simply don't understand that question. :) –  Jay _silly_evarlast_ Wren Mar 5 '13 at 2:20
    
You want it to open that localhost page when you click run? –  NoBugs Oct 22 '13 at 6:49
add comment

if you use a webserver always running as a local service (as I do), you can use GeanyLua to convert absolute path to localhost URL path and then open it in a browser, thanks to string patterns (~regexes):

local f = geany.filename()
--[[
try to split path in 3 parts: DocRoot parent path, DocRoot, relative path + filename
else open the file with file:// scheme directly
easy to adapt: '/var/www/'…
--]]
local s,e,path,p,file = string.find(f,'^(.*)(/Public_html/)(.*)')

if p == '/Public_html/' then
  target = ("http://127.0.0.1/" .. file)
  firefox = ('firefox ' .. target .. ' &')
  print('Firefox running')
  os.execute(firefox)
else
  firefox = ('firefox "' .. f .. '" &')
  print('Firefox running')
  os.execute(firefox)
end

to be saved in "/home/yourname/.config/geany/plugins/geanylua/show-Firefox.lua" on Linux

run it by menu/Tools/Lua Scripts/Show Firefox

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.