4

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.

1
  • 3
    Have a search for: webserver, apache, lamp.
    – Rinzwind
    Mar 3, 2013 at 14:18

5 Answers 5

4

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

3
  • 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.
    – roomcayz
    Mar 3, 2013 at 18:55
  • I suggest you ask that question, or maybe I simply don't understand that question. :) Mar 5, 2013 at 2:20
  • You want it to open that localhost page when you click run?
    – NoBugs
    Oct 22, 2013 at 6:49
4

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.

1

Geany is great. We can write a scrip, e.g. python, then run it. And it will run just like a normal IDE like Netbean do. It even will show the result in GUI when we run python with wxPython. Of cource, Python and wxPython must be installed first.

It also able to show output of PHP and/or HTML scrips directely in a Browser, so far as I know, Firefox. Of cource, a Geany project should be set first to do that. Again, web browser, PHP anda MySql must be ready first.

To directly output a PHP scrip in a Browser, e.g. Firefox. Do as follows :

Open a Geany project, then : Project -> Propesties -> Build. There are 3 group option to edit : PHP Command, Independent Command and Execute Command. Thera are 2 columns in Execute Command group.

Look at the bottom of the window (Click here)

Fill the second column with :

  firefox "http://localhost/your_project_folder/%f"

And the third column, fill with your document root of your project e.g :

  /var/www/html/your_project_folder

Thas all.

0

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

0

The accepted answer:

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

did not open files with databases connected, and in fact gets this error:

The requested resource /index.php was not found on this server.

While this works great to me (one subdirectory only):

A="$(pwd | rev | cut -d'/' -f1 | rev)"; sensible-browser localhost/"${A}"/%f

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .