Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Notepad++ to run php on localhost?

I am trying to get the option Run->Launch With Firefox; to open the file I am currently viewing in Notepad++ at http://127.0.0.1:8080/currentfile.php, but instead it just opens to current file directory in Firefox.. I've tried to edit the shortcut xml file in the Notepad++ directory, I've shut Notepad++ down and edited the XML file with regular Notepad, and when I start Notepad++ back up it does not show the settings I entered.. How can I edit the settings to load localhost rather than the file directory in Firefox?

like image 528
CLUEL3SS Avatar asked Sep 24 '11 00:09

CLUEL3SS


4 Answers

Here's a quick and dirty fix to run php files even if they are in subdirectories inside your document root. In shortcuts.xml:

<Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>

Then create the file "redirect.php" in your web server document root:

<?php
$root = $_SERVER['DOCUMENT_ROOT'];

$file = str_replace('\\', '/', $_GET['file']);
$file = str_replace($root, '', $file);

header("Location: http://localhost{$file}");
like image 79
A. Gneady Avatar answered Oct 07 '22 12:10

A. Gneady


well two things

  1. you edited the wrong file , i'm guessing you are using windows vista/7 so real preferences files are in C:\Users\user\AppData\Roaming\Notepad++

  2. i don't think that notepad++ has a variable that contains only half of the address

meaning : the variable used now is $(FULL_CURRENT_PATH) == file:///C:/server/htdocs/pages/example.php

so you don't have any variable that contains only this pages/example.php.

so i think it's impossible

but just keep the page open and refresh after editing

like image 42
elibyy Avatar answered Oct 07 '22 10:10

elibyy


If you save your PHP file directly into the www directory of WAMP (no subfolders), you can execute it by selecting the "Run..." command and pasting in this line:

firefox.exe "http://localhost/$(FILE_NAME)"

It's not great, but it will help you debug in a jiffy.

like image 2
Kevin Scharnhorst Avatar answered Oct 07 '22 11:10

Kevin Scharnhorst


I know this is an older question but:

A. Gneady's solution works well. However, it may require some modification on Windows so the DOCUMENT_ROOT is replaced before the slash directions are replaced. Otherwise, no replacement will be made and the $file will output the same as the original path and file name, except with the slashes reversed.

Since I test in multiple browsers, I modified all of the pertinent rows in C:\Users[username]\AppData\Roaming\Notepad++\shortcuts.xml:

<Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="70">safari &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>

Then create the "redirect.php" file in the web root directory as follows:

<?php 
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\\', '/', $file);

header("Location: http://localhost{$file}");

?>
like image 2
Jesperai Avatar answered Oct 07 '22 10:10

Jesperai