How to use Brackets for coding PHP
Brackets Code Editor is best for Front End Development i.e. HTML, CSS & JavaScript.
From Brackets 1.14 version, the Brackets code editor supports PHP using the PHP Language Server.
Brackets has Syntax Highlighting and other important features.
Important features of Brackets for PHP
- Code Hint – Shows PHP coding hints to the user
- Parameter Hint – During the function call, it shows the hints about the parameter
- Jump to definition – Jump to the location where the class/selection is defined in PHP. Shortcut is Ctrl + J
- Linting – Diagnoses the PHP code while typing or saving. Brackets does it by showing Linting errors at the bottom
- Find references – A file referencing feature that can find the list of files where a code/text is coded. For this, simply Right Click on the particular code and click on ‘Find All References”. The shortcut key is Shift + F12
- Can find all Document Symbols in current document – Shortcut is Ctrl + T
- Helps to find all the project Symbols – Shortcut is Shift + Ctrl + T
Prerequisite to run PHP on Brackets
HTML, CSS and JavaScript can easily run in the browser as these are client side languages.
On the other hand, PHP is an Open Source Server Side Scripting Language. So, you need to install a local web-server such as Apache or ngix server in your computer to run PHP.
If you are looking for a server in cloud, then Amazon Cloud or Nitrous is a good option.
Install XAMPP and setup PHP
Follow these steps to run PHP code in your local computer –
- Install XAMPP from the official website here. By default, it will install in C drive(C:\xampp)
- Go to XAMPP Control Panel & start the Apache server. Optionally, you can also start MYSQL if you would require a Database connection with MYSQL.
- Locate the folder with the name as htdocs inside the XAMPP installation.
- Create your PHP Project Folder here with any name such as myphpproject.
- Go to Brackets editor and navigate to File -> Open Folder and open the myphpproject folder. The shortcut is Ctrl + Alt + O.
- Set the Base URL. Go to File -> Project settings and set the project URL. In most of the computers, the localhost is http://localhost/. So, the base URL for your project will be http://localhost/myphpproject
- Create a new PHP file inside this folder and write your PHP code
- Save the PHP file with any name such as index.php. It is important to save the file with a .php extension
- Click on ‘Live Preview’ and you are ready to run the PHP files in your computer
- Navigate to File -> Enable Experimental Live Preview and Uncheck this option to enable the project setting. If this option is unchecked but Live preview is not working, then enable this option and try again. If this does not solve the issue, uncheck this option again and restart Brackets again.
- Make sure that the local server is already running. If you are using XAMPP, go to XAMPP control Manager and restart Apache again. Wait until it starts completely.
Is it mandatory to run Live Preview?
No, it is not mandatory to use the “Live Preview” feature of Brackets if you have installed a local server like XAMPP, WAMP, MAMP, etc.
Suppose, you have your Apache installation and you created your project folder under the ‘htdocs‘ folder. Now, you need to simply start your Apache server and type your localhost URL such as – http://localhost/index.php on your browser.
Now, whenever you do your code changes, you have to refresh the browser for changes to reflect.
Extra Tips
Brackets supports many file formats such as Html, CSS, JavaScript, PHP, Perl, Python, etc.
While working with a PHP file, make sure that Brackets shows the file format as PHP at the bottom. If it shows any other format, then change it to PHP.
Popular PHP Brackets Extension
- QuickDocsPHP – Good extension to show the PHP documentation quickly.
- Indentator – Extension to Re-indent the PHP code as per your current indentation settings. To use this, go to Edit -> Indent Document. Shortcut is Ctrl + Alt + i.
- PHP SmartHints – Intelligent & robust code hinting extension for PHP in Brackets. This extension has a PHP autocomplete feature which is extremely helpful. The Code Hints include Function, Variables, etc. As Brackets has inbuilt Code hint mechanism now, this extension is not necessary but few developers are still using it.
- PHP Code Quality Tools – Tool that shows PHP Linting by using multiple code analysis tools. Now, PHP has the Linting feature inbuilt so this extension is not necessary. If you do not like the inbuilt Linting of Brackets, then you can use this tool.
To refer most popular extensions, we recommend you to read our best tutorial on ‘Brackets Extensions‘.