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. There is my question:

  • How to run PHP code from Geany directly in web browser 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.

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

3 Answers 3

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
up vote 2 down vote accepted

After a year...

Fastest solution to run PHP code instantly is a custom build option:

php -S localhost:8080 -t "%p" -e & sensible-browser localhost:8080/"%f"

It will run a php process with internal server with root in the project directory, and run default browser on same port and file which build command was executed.

share|improve this answer

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

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.