Geany PHP Web Server

Geany View PHP Code In Web Browser

Geany was reviewed as part of a series of lightweight programming editors. To select a reviewed lightweight programming editor read the Ojambo.com Lightweight Programming Editors.

Geany is a small IDE that loads quickly. Geany comes with an optional project management feature. Each project can have project-specific build features.

This tutorial uses the Geany. Once the build menu item is selected, the project will open in the specified web browser.

    Tools are required:

  • Geany text editor.
  • Geany project management.
  • Web browser.

Optional Download and install Geany

Geany is required in order to follow this tutorial. For more information about Geany read Ojambo.com Lightweight Programming Editors.

How to Use:

    Open Geany

  • Project -> New -> Name = webphp, Base path = /project/webphp.
  • Build -> Set Build Commands -> Execute Commands -> Execute = php -S localhost:8000 & sensible-browser localhost:8000/”%f”.
  • File -> New(with Template) -> file.php
  • File -> Save As -> Name = index.php

Image Missing
Ojambo.com Geany New Project

Image Missing
Ojambo.com Geany New Project Path

Image Missing
Ojambo.com Geany Project Properties

Image Missing
Ojambo.com Geany New File Template

More information about the PHP built-in web browser can be read at Ojambo.com PHP Web Development Without Web Server. The ampersand indicates another command to run. Sensible-browser is the name of the web browser.

The Geany character sequence “%f” is substituted by the name of the current file without the path. The default path is the current project path.

PHP Index File

<?php
/*
 * index.php
 * 
 * Copyright 2013 edward <http://Ojambo.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */

?>
<!DOCTYPE html>
<html xml:lang="en" lang="en">

<head>
	<title>Ojambo.com Geany PHP Web Server Index</title>
	<meta charset="utf-8" />
</head>

<body>
	<h1><?php echo "This is the Index Page"; ?></h1>
	<p><a href="tester.php">Tester Page</a></p>
</body>

</html>

The PHP code is embedded in the h1 HTML tags. If the document is a PHP file then PHP embedded code can be interpreted by a web server. The anchor link points to another PHP file called “tester.php”.

PHP Tester File

<?php
/*
 * tester.php
 * 
 * Copyright 2013 edward <http://Ojambo.com>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */

?>
<!DOCTYPE html>
<html xml:lang="en" lang="en">

<head>
	<title>Ojambo.com Geany PHP Web Server Tester</title>
	<meta charset="utf-8" />
</head>

<body>
	<h1><?php echo "This is the Tester Page"; ?></h1>
	<p><a href="index.php">Index Page</a></p>
</body>

</html>

The PHP file is loaded as a new page. The PHP embedded code inside the h1 tags is interpreted by a web server. The anchor link points to a separate PHP file called “index.php”.

How To Use:

    Open Browser For Speed

  • Build -> Execute.
  • Alternate method is to click the run icon in the toolbar or F5
  • Close terminal to close web server.

Image Missing
Ojambo.com Geany Execute Menu

Image Missing
Ojambo.com Geany Execute Toolbar

Demonstration:

Ojambo.com Geany PHP Web Server Tutorial

Image Missing
Ojambo.com Geany PHP Web Server Index

Image Missing
Ojambo.com Geany PHP Web Server Tester

Conclusion:

Geany is a powerful editor that has features only available in much larger IDEs. An important tool that PHP application developers need is project-specific execution. Each project can have custom menu labels and commands.

The build menu configuration for a project can override the system defaults. A new execute command can be created to use the PHP built-in web server and open in a web browser.

    Recommendations:

  1. Create projects for PHP web applications.
  2. Override the default execution command in order to use the toolbar execute icon
  3. Create a custom execute command if your will use non web-specific PHP code.