Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

sublimetext2 - How to run PHP code in Sublime Text 2

I am very new to Sublime text 2. I have just started using this and know nothing about it. I want to work on PHP. I have built a system 'php'. After choosing 'php' build system I am creating a new file and writing PHP code with just a single echo line and trying to run it. Everytime it is giving my this error

enter image description here

By default Sublime Text 2 saved in C:Program FilesSublime Text 2

and the path where automatically files are being saved is C:UsersSM AhmedAppDataRoamingSublime Text 2PackagesUser

What should I do that makes my code run succesfully

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

While traditionally PHP scripts are run by web servers, it is possible to run them through Sublime. To set up a webserver, I suggest you to read this: http://www.ntu.edu.sg/home/ehchua/programming/howto/WampServer_HowTo.html

It will get you started on how to setup a local server and 'run' PHP.

If you want to run PHP from your Sublime Text 2/3 console you should go to:

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

and then edit the file like this:

{
    "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 (make sure to use forward slashes /). Save the file as Packages/User/PHP.sublime-build where Packages is the folder opened when you select Preferences -> Browse Packages.... Next, click on Tools -> Build System -> PHP and hit Ctrl+B to run your script (or Cmd+B on a Mac). You should see the output, if any, in the build console that opens.

Be sure there aren't any errors in your PHP and also be sure that PHP is configured correctly!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...