To preview PHP pages and have them rendered appropriately you need a web server, such as XAMPP, which can serve PHP pages. If you are using OS X or Linux, you may be able to use the pre-bundled web server that comes with the operating system, or you can download XAMPP too. In either case, the instructions will be relatively similar.
Download XAMPP (or the web server of your choice) and install it on your computer according to the installation instructions. For XAMPP, it will create a document root (by default), in the following locations:
- Windows: \xampp\htdocs
- OS X: /Applications/XAMPP/htdocs/
- Linux: /opt/lampp/htdocs/
If you decide to use a different install location (or a different server) the above paths may be somewhat different, but make note of the document root as it will become important in the next step.
Set up your project
You can either create a new project to hold your content, or move an existing project into the new location.
Create a new project
- From the File menu, select New > Project... > Web Project (or PHP Project) in the project wizard.
- Type a name for your project.
- Uncheck the Use default location box and browse to the htdocs (or equivalent) folder in your server installation directory.
- Create a new folder in that directory with the same name as your project and select that new folder for your project location (shown below). Using the above paths, that would equate to \xampp\htdocs\myproject on Windows, or /Applications/XAMPP/htdocs/myproject on OSX
- Continue on to choose a project template, or Click the Finish button.
Import an existing project
- In Finder, Windows Explorer, or equivalent, copy the files from their current location into a sub-folder under the htdocs (or equivalent) folder in your server installation directory. Using the above paths, that would equate to \xampp\htdocs\myproject on Windows, or /Applications/XAMPP/htdocs/myproject on OSX.
- Follow the steps here Importing an Existing Project
Create your preview server
A more detailed discussion of this step can be found at Creating a Custom Preview Server
- Right-click on a project in the "Project Explorer" view, and select Properties
- Select "Preview Settings". Click Use Specific Server and New
- Select Simple Web server
- Fill out the form:
- Click OK and OK
Start the external server
It may be started automatically for you, but ensure the server is started. XAMPP comes with a small control panel you can use to start and stop the server.
Preview your files
You can now use the preview button in the editor toolbar, or continue on to create a run configuration based on this new preview server. See Previewing a project in a web browser for more information.