How to run PHP code in Sublime Text 2

I am very new to Sublime text 2. I just started using this and know nothing about it. I want to work in PHP. I created a php system. After choosing the php build system, I create a new file and write the PHP code with only one echo line and try to run it. Every time he gives me this error

enter image description here

By default, Sublime Text 2 is saved in C: \ Program Files \ Sublime Text 2

and the path where the files are automatically saved is C: \ Users \ SM Ahmed \ AppData \ Roaming \ Sublime Text 2 \ Packages \ User

What should I do that makes my code successful?

+6
source share
2 answers

Although traditionally PHP scripts are executed by web servers, they can be run through Sublime. To set up a web server, I suggest you read the following: http://www.ntu.edu.sg/home/ehchua/programming/howto/WampServer_HowTo.html

You will learn how to set up a local server and run "PHP".

If you want to run PHP from the Sublime Text 2 console, you must go to:

Tools -> Build System -> New Build System... 

and then edit the file as follows:

 { "cmd": ["/path/to/php", "$file"] } 

where /path/to/php is something like /usr/local/bin/php on Linux / OS X or C:/WAMP/bin/php.exe on Windows (be sure to use the slash / ). Save the file as Packages/User/PHP.sublime-build , where Packages is the folder opened when you select Preferences -> Browse Packages... Then click Tools -> Build System -> PHP and press Ctrl + B to run the script (or Cmd + B on Mac). You should see the output, if any, in the assembly console that opens.

Make sure there are no errors in your PHP, and also make sure that PHP is configured correctly !

+18
source

As a ref and example for Ubuntu users, this works well if you just need to check the PHP syntax in the current file that you opened;

Create a file in /home/$USER/.config/sublime-text-3/Packages/User/PHP - Check Syntax.sublime-build and paste it.

  {
     "cmd": ["php", "-l", "$ file"]
 }
+2
source

Source: https://habr.com/ru/post/973858/


All Articles