Sublime text php как запустить код
Перейти к содержимому

Sublime text php как запустить код

  • автор:

Six Easy Setups for Local PHP Development — Beginners

Surajudeen Akande

I decided to write on this obviously simple topic because a lot of people still find it difficult! ������ These people include beginners who battle with a lot of difficulties just trying to echo their hello world using PHP, oldies who have years of experience writing PHP but have failed to migrate to modern paradigms in PHP and naysayers who behave as if PHP murdered a member of their family ��.

At this point let me say, using *AMPs is old school and there are faster and easier way of setting up the lovely blue elephant ��.

Actually, it is just one way of setup that I would be talking about but I will be enumerating on different flavors of the one way. The one way is simply installing global installation of PHP which allows you to run PHP code everywhere on your machine, unlike the *AMPs that restrict you to the boys-quarter of htdocs and www folders ��. Also, the *AMPs do not let you see that you can actually use PHP beyond the web.

Let’s get started …

Simply install PHP globally on your Machine

On a Mac, simply do:

On a Linux machine, simply do:

On a Windows machine, simply extract the binary downloaded from php.net to your C:/ and remember to add it to your System’s Environment Variables.

Once that is done on respective machines, kindly run:

to confirm that your installation was successful. You should see a response similar to this:

Below are the ways you can use your PHP installation easily:

1. Start PHP local web server

In the root of your PHP application or file. Simply start PHP web server using:

to run your index file or specify the name of the file you simply want to run like:

With this, you will see a response like:

You can easily see your pages served by visiting http://localhost:port_number.

2. Use PHP interactive shell

A good number of PHP developers are not aware of this. It is simply a REPL environment to quickly run your span with some PHP code. Simply run:

This is an example:

3. Using the php command

Simply type php before a filename to execute a PHP script. Below is an example:

4. Using Sublime Text’s Build System.

If you use Sublime Text editor, you can run your php script within ST3 using the Build System feature by running cmd + B or Ctrl + B. To setup build system for PHP in ST3, follow the guideline here. Here is an example:

5. Using Atom’s Build System

Similar to using ST3’s Build System, running PHP code within your Atom editor comes out of the box. Just run cmd + I or Ctrl + I.

6. Using PHP Server within Atom

Starting PHP server within Atom editor is easy by using this plugin. With this, you can easily spin up your server with few keys. See example below:

I hope you found something of benefit from this simple post.

If you liked this, click the�� below so other people will see this here on Medium. Also, if you have any questions or observations, use the comment section to share your thoughts.

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 Files\Sublime Text 2

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

What should I do that makes my code run succesfully

SidraM's user avatar

3 Answers 3

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:

and then edit the file like this:

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!

Как запустить PHP-код в Sublime Text 2

Я очень новичок в Sublime text 2. Я только начал использовать это и ничего не знаю об этом. Я хочу работать на PHP. Я создал систему «php». После выбора системы сборки php я создаю новый файл и пишу PHP-код только с одной эхо-линией и пытаюсь запустить его. Каждый раз, когда он дает мне эту ошибку

Изображение 43639

По умолчанию Sublime Text 2 сохранен в C:\Program Files\Sublime Text 2

и путь, по которому сохраняются автоматически файлы, C:\Users\SM Ahmed\AppData\Roaming\Sublime Text 2\Packages\User

Что мне делать, что делает мой код успешным?

2 ответа

Хотя традиционно скрипты PHP выполняются веб-серверами, их можно запускать через Sublime. Чтобы настроить веб-сервер, я предлагаю вам прочитать следующее: http://www.ntu.edu.sg/home/ehchua/programming/howto/WampServer_HowTo.html

Вы узнаете, как настроить локальный сервер и запустить «PHP».

Если вы хотите запустить PHP из консоли Sublime Text 2, вы должны перейти к:

а затем отредактируйте файл следующим образом:

где /path/to/php — это что-то вроде /usr/local/bin/php в Linux/OS X или C:/WAMP/bin/php.exe в Windows (обязательно используйте косую черту / ). Сохраните файл как Packages/User/PHP.sublime-build , где Packages — это папка, открытая при выборе Preferences -> Browse Packages. . Затем нажмите Tools -> Build System -> PHP и нажмите Ctrl + B , чтобы запустить script (или Cmd + B на Mac). Вы должны увидеть выход, если он есть, в открывшейся консоли сборки.

Убедитесь, что в вашем PHP нет ошибок, а также убедитесь, что PHP настроен правильно!

Sublime Text Configuration for PHP

Sublime Text is a powerful text editor , its not just a text editor compare to other text editor the plug-ins of sublime text enables it to a complete IDE options. Here I will tell you the basic configuration required for PHP development using sublime text.

Sublime Text Configuration for PHP have the following main plug-ins.

  • PHPfmt
  • Sublime linter
  • Sublime Linter – PHP
  • Bracket highlighter
  • HTML beautify.
  • Git Gutter
  • Alignment

There are many other useful plug-ins available for Sublime text. First of all install the Sublime text latest version on your system based on your OS Win/Linux. Once you installed the Sublime Text good to go with package Controller. You have to run the Python code provided by the package controller io. Based on Sublime text version choose the script code. Open your console with Ctrl+` Paste the code and press enter. once it render you may need to restart the Sublime Text, It will install the required dependency as well.

Now you will be able to install other plug-ins packages via pressing Ctrl + Shift + P . then type ” install ” it will load all the repository for you the just type the above list of plug-ins name one by one .

Once you install all the required list now you can configure each of the plug-ins with you customization.

PHPfmt Configuration

Open the Preference menu of sublime text -> Package Settings -> PHPfmt-> user Settings. Paster the following codes.

make sure your PHP installation path is correct. Now you can set the short for formatting the phpfmt output Preference -> Key Binding – User paster the following codes.

I set it to alt+shift+c you can set it to your own key combination.

Sublime linter

This is an awesome plug-in that helps to detect PHP syntax errors while you coding.

Open Preference -> Package Settings -> Sublime Linter -> User Settings.

You can set the basic theme and spacing of tab index and all with following code. add the code inside your Preference -> User Settings

Forced refresh of the Project folder can be set with short cut key combination add the following code inside your User key binding.

here also the make sure the php path is correct as well, I’m on Linux machine so settings are are according to that.

If you preferred more package for JS and CSS like Js beautify or Less and Sass support etc are also available in Sublime Text Package repo.

Hope this article will help you to set up the PHP coding standard with PSR-2 using Sublime Text .

3 thoughts on “ Sublime Text Configuration for PHP ”

Yo are great ! you saved my hours, Lastly I have found the best setting Thank Man!

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *