How to run php extencioned files in CMD (DOS)? - php

Is there a possibility to run a php file by using the cmd? So it will become much easier to see things without using any html codes in it.

Show Desktop.
Right Click My Computer shortcut in the desktop.
Click Properties.
You should see a section of control Panel - Control Panel\System and Security\System.
Click Advanced System Settings on the Left menu.
Click Enviornment Variables towards the bottom of the window.
Select PATH in the user variables list.
Append your PHP Path (C:\myfolder\php) to your PATH variable, separated from the already existing string by a semi colon.
Click OK
Open your "cmd"
Type PATH, press enter
Make sure that you see your PHP folder among the list.
That should work.
Note: Make sure that your PHP folder has the php.exe. It should have the file type CLI. If you do not have the php.exe, go ahead and check the installation guidelines at - http://www.php.net/manual/en/install.windows.manual.php - and download the installation file from there.

Related

Error while running a php code in vs code

An error show's that the php executable not found and add it to your path
Step 1: First, we have to download PHP from it’s official website. We have to download the .zip file from the respective section depending upon on our system architecture(x86 or x64).
Step 2: Extract the .zip file to your preferred location. It is recommended to choose the Boot Drive(C Drive) inside a folder named PHP (ie. C:\php).
Step 3: Now we have to add the folder (C:\php) to the Environment Variable Path so that it becomes accessible from the command line. To do so, we have to right-click on the My Computer or This PC icon, then choose Properties from the context menu. Then click the Advanced system settings link, and then click Environment Variables. In the section System Variables, we have to find the PATH environment variable and then select and edit it. If the PATH environment variable does not exist, we have to click New. In the Edit System Variable (or New System Variable) window, we have to specify the value of the PATH environment variable (C:\php or the location of our extracted PHP files). After that, we have to click OK and close all remaining windows by clicking OK.
you didn't set php as a local variable to use it in CLI, so:
Click the Advanced system settings link.
Click Environment Variables. ...
Duble click on PATH
click new and write your PHP path (EX: C:\wamp\bin\php\php8.0.11)

How to use VSCode to remotely edit website files?

I need to be able to remotely log into web servers for my clients and edit code remotely. I mostly use this for CSS changes, but also am starting to play with PHP as well.
I have tried to get Remote-Editor to work but it won't pick up the .remote file that I placed in the /home folder. The instructions don't really give great details on setting this up.
What do I do?
Use FileZilla, then set VScode as default editor (edit->settings->file editing->filetype associations and insert "php /usr/bin/code"). okey, now u need select your file on FTP and press "View/Edit", then ur file open in VScode editor. Done:)
Use an FTP client (like FileZilla), then set VSCode as the default editor. Anytime you open a file, it will open it in VSCode. I highly recommend that you download all of the code to your own computer and use it as a dev environment, and then, when you're finished with your changes, backup your site, then upload the modified files together. It's not required to edit files on your own machine, but it is recommended if you ever need to revert to an old version for whatever reason (like you made a mistake in the code, and now nothing works right).
Alternatively, you can use an extension like FTP Sync to code locally, and have the files be automatically synced for you.
Open Filezilla -> Edit -> Settings -> File Editing -> Filetype associations
Now you will have "Custom filetype associations:" situated on the right pane of the window.
Over there you have to write the command for opening VSCode for PHP files.
Step 1: Search and locate the VSCode Exe file setup install directory on your computer. In my case it was (C:\Users\Shubham\AppData\Local\Programs\Microsoft VS Code/Code.exe)
Step 2: Copy the directory path link of the ".exe" file and come back to the "Custom filetype associations:" inside Filezilla.
Step 3: Now type "php" then give space & paste the directory path that you have copied inside double quotes and then again give space and write "-open". The final code should look something like this
php "C:\Users\Shubham\AppData\Local\Programs\Microsoft VS Code/Code.exe" -open
Step 4: Click the Okay Button and have a coffee.
There are several approaches to this that are all editor-agnostic.
First, there is sshfs, which is cross-platform and you can install via your OS package manager. A simple approach would be as following:
mkdir -p ~/mnt/server
sshfs user#server.example.com:/path/on/server ~/mnt/server
Afterwards, you have the complete folder structure from server.example.com locally available at ~/mnt/server. Make sure you set up SSH keys to avoid entering the user password every time. You can find tutorials on that everywhere on the net.
For servers that only offer FTP access (shared hosting and the like), you can use curlftpfs in the same fashion.
To close the connection, simply unmount:
umount ~/mnt
For a GUI-based approach, you have several options. There is Transmit (macOS), which features mounting connections as volumes, Forklift (macOS) which is a Finder replacement that can do the same, ExpanDrive (macOS/Windows) and my favorite Mountain Duck (macOS/Windows).
If you plan to move lots of data, especially a lot of small files, Mountain Duck performs the best in my experience.
Just type this is Filezilla Settings->File Editing-> File Association
php /snap/bin/code
Open Filezilla and go to Edit >> Settings
Click on File Editing, and set the radio button to use Custom Editor
In the text field below you need to enter the full path to Visual Studio Code, this is usually found in the /usr/bin/ directory, so you need to enter the following /usr/bin/code
Next select the radio button Always use default editor and click OK to finalise the settings.
Most of the answers I see are for Windows. If anyone wants to associate File Types using Linux in Filezilla, the path is a bit different.
htm /snap/bin/code --force-user-env --no-sandbox --unity-launch
html /snap/bin/code --force-user-env --no-sandbox --unity-launch
js /snap/bin/code --force-user-env --no-sandbox --unity-launch
php /snap/bin/code --force-user-env --no-sandbox --unity-launch
You do not need to use the extra flags, but they are being used in the Menu Shortcut, so I included them.
To set VS Code as default editor for all type of files in mac use below steps:-
Click on Edit menu
Then click on setting option
Then find out File Editing and click on it (Not on submenu(Filetype associations))
Click on custom editor and then browse in application or download and select VS Code. And also click on checkbox "Always use default editor" and then click ok.
open filezilla->edit->file editing->use custom editor->browse(find the visual code path)
for find visual code path->right click on the visual code and open location and paste that location to the browse menu and find the visual code short cut
after that press ok on filzilla it will work fine
It's important that you start Filezilla as an administrator. That was the reason why it wasn't working for me.
Open Filezilla -> Edit -> Settings -> File Editing -> Filetype associations then type:
php "C:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\Code.exe" %f
Note: substitute <username> with your windows username
Bonus: php can be replace with any kind of file format. Just write file extension name on lowercase.
I used this registry update to set vscode as my default text file editor (copy & paste into update.reg, open regedit and import the file):
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\SystemFileAssociations\text\shell\edit\command]
#=hex(2):22,00,25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,\
00,45,00,25,00,5c,00,41,00,70,00,70,00,44,00,61,00,74,00,61,00,5c,00,4c,00,\
6f,00,63,00,61,00,6c,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,\
00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,\
53,00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,\
00,78,00,65,00,22,00,20,00,25,00,31,00,00,00
After that the registry is updated as follows:
Of course you should not trust hex encoded registry updates you found in the internet. So copy 22,00 ... 00,00, remove all backslashes, linebreaks and whitespaces and convert through one of many hex to ascii online converters to verify the import:
After you made this change you can even edit text files with vscode through the "edit" context menu entry:

PHP desktop how to change the main window icon

I am starting to use PHP desktop to create a desktop application and it works great, just want to know if there's any settings to change the main windows icon, i know to change the pop-up windows icon can be change on settings.json, but i cannot find any settings to change the main windows.
Note: im using Inno Compiler to distribute my application, but the compiler only change the set-up icon not the main application.
I had the same problem, the solution is provided by the creator -
If you would like to change the icon that is embedded in the executable file then do the following steps:
Download Resource Hacker and run it.
From the "File" menu select open, navigate and choose "phpdesktop-msie.exe" (or "phpdesktop-chrome.exe").
On the left side there should be a tree control, expand "/Icon Group/128/1033", right click on the "1033", select "Replace Resource..." and replace that resource with your icon.
That's it, save it and see the changes by running the executable file.
When you change icon embedded in the executable file you do not need to set it anymore in the settings file.
Put .ico image inside your folder and edit setting.json file like below
"main_window": {
"title": "----",
"icon": "ico.ico",
----},

Using Brackets for PHP files

I currently have wampserver running and I'm trying to do live preview of a php file using Brackets.io. However when I click live preview I'm getting
Project settings for: Getting Started
Live preview base URL: ______________
I'm following this tutorial on running PHP scripts.
My php file is in C:/wamp/wwww/php_proj1/php1.php so I've been trying to put this in my "Base URL"
http://localhost/php_proj1/php1.php
However everytime when I type that and enter it, it just asks me for the "Live Preview Base URL" again and nothing happens. I also tried putting the URL in my 'File->Project settings' and that also didn't work. I'm just running a basic php script that echos some words.
It works when I manually type
http://localhost/php_proj1/php1.php
in my Chrome URL but not when I use Bracets live preview.
What am I missing or doing wrong? Do I need to config anything in my wampserver? I've just started learning php and using wampserver so I'm not entirely sure what I'm doing wrong.
Thanks!
EDIT: I'm following these 2 tutorials on doing this and it's just not working for me.
tutorial 1 and tutorial 2
EDIT2: Found my mistake.. I did not do File->Open Folder to open the folder that I was working on... Thanks to everyone that helped me with this, I will definitely not make this mistake again. sigh
The Live Preview Base Url should be set to the same url that you would use to launch your project in a browser.
So if you have a project in C:/wamp/wwww/php_proj1/ you would launch that project in a browser by entering http://localhost/php_proj1/php1.php therefore that is what Brackets is expecting to be entered into the Base Url field minus the actual script file name.
Remember the DocumentRoot of localhost is pointing to the folder C:/wamp/www/
So enter
http://localhost/php_proj1/
into the dialog that requests the Base Url.
Assuming you are editing the file php1.php at the time you clicked the Live Preview icon that is the script that will be run in the browser.
Oh and of course you have to have WAMPServer and therefore Apache up and running when you do this as it is running the code through Apache so that the PHP code can be interpreted.
Found my mistake. I did not do File->Open Folder to open the folder that I was working on...
Try the same thing but with a simple HTML file.
Try launching your project with PHP's built-in server. Open a terminal/cmd window and go to the folder php_proj1. Now execute php -S localhost:8000. Now set your Live preview path to http://localhost:8000/. If this one does work, then there may be a problem with Wamp.
Now remember that no matter what, you're not supposed to contain a file in the Live Preview path, but only a folder path. When you contain it, you get to this URL: http://server/file.php/file.php (double) and that's not exactly what you want...
If none of these work - there may be a problem with either your computer, Brackets, Chrome, or both. Try to reinstall them (Brackets first).
My two cents, is the name of the project php_proj1 ? If not you'll have to use http://localhost/ as your base URL.
Also (When you are using Brackets) check the content of the Chrome Network tab. F12 Developer Tools -> Network -> Filter -> Documents
Try to investigate the URLs, probably that'll give you some insight

Opening a local file in Eclipse from the web

Right now, when I notice a problem on a page on my PHP web site, I have to look at the URL, mentally deduce what file is responsible for displaying that page, then navigate the Eclipse PDT file tree to open that file. This is annoying and uses brain power that could have been applied to solving the issue instead.
I would like my PHP web site to display on every page a link that I could click to automatically open the correct file in Eclipse.
I can easily compute the complete absolute path for the file I need to open (for example, open C:/xampp/htdocs/controllers/Foo/Bar.php when visiting /foo/bar), and I can make sure that Eclipse is currently open with the correct project loaded, but I'm stuck on how I can have Firefox/Chrome/IE tell Eclipse to open that specific file.
Edit
I'm going along the way of a data: URI, by adding a link to my file that contains the name of the file, with an unusual MIME type.
<a href="data:link/php;base64,IkM6XHhhb[snip]GhwIgo=">
View controller
</a>
The base64-encoded content is the absolute path to the file on my computer. When I click the link, Firefox lets me bind the content type to a new application, so I chose a batch file I wrote myself:
for /f "delims=" %%i in (%1) do (
notepad.exe "%%i"
)
This works. Now, I would like the file to be opened in the already opened window of Eclipse. What do I have to replace notepad.exe with in the above batch?
[pathtoeclipse]\eclipsec.exe -name Eclipse --launcher.openFile [fullpathtoyourfilehere]
I am not sure if it works with Galileo (i am on Helios)
Further reading: https://bugs.eclipse.org/bugs/show_bug.cgi?id=4922 (it is a long, long story)
I've tried similar things in the past, but this isn't as easy as it should be. The end result was always that Firefox would need an extension to execute a local file (I never found one that would do the job), and IE won't do it at all any more (save, maybe, for some complicated proprietary VBScript/WScript).
I see two workarounds to do this:
A function that displays the file path on your page in a big fat dialog window, making it easy to copy and paste into the Windows + R "Execute" Dialog
Alternatively, registering a custom Protocol (e.g. eclipse://) in your operating system, and tying that protocol to Eclipse. This is a pretty great way actually, I haven't tried this yet but definitely will in the next project I need this. Mozillazine: Register protocol (see the .reg file example)
You get the local path with FILE.
Maybe you try something like this?
<?php
'127.0.0.1' == $_SERVER["REMOTE_ADDR"] and print __FILE__;
?>
Is integrating Eclipse with Xdebug an option? I've done this with TextMate so that generated error messages are clickable to take me to the correct line in the right file. (See this question for details).

Categories