kkj
kkj

Reputation: 45

Run PHP code on Sublime Text without being connected to a server?

I have just started using HTML/Sublime/PHP.

I am creating an HTML website using Sublime Text.

In order to condense parts of the web pages that appear in multiple pages (like the menu, header, and footer), I want to run a PHP script. Does that require the website to be hosted on a server? Or can I run a PHP script directly on Sublime Text.

Thank you!

Upvotes: 0

Views: 1614

Answers (2)

archvayu
archvayu

Reputation: 448

Any web page containing the php script should be saved with extension '.php'. This type of file is fetched by the web server to the browser view. Locally, you need to install a web server (eg. apache) in your device so that you can fetch the contents of the script locally. So, the basic things to be noted are ::

  1. All pages containing (HTML escape or php script) must have to be saved with .php extension
  2. .php files are fetched by web server (either on local device or over internet) so you need web server service installed if you want to work on local
  3. The best way to do so is install respective web server solution package ::
    • XAMPP for cross-platform
    • MAMPP for Mac users
    • WAMPP for Windows
    • LAMPP for Linux

After you have successfully installed and configured the above mentioned package, you have to run the php files on the browser over the localhost (which will serve as local web server).

Try installing the web server solution package that suits your device. You will get to learn a lot on the process.

P.S. Regarding sublime, it is just a editor. It is just used to write the codes in simple and easy way.

Upvotes: 3

Naveed Ramzan
Naveed Ramzan

Reputation: 3593

Well, you need to install a web server software locally to your machine.

For example :

  • WAMP (Windows Apache MySQL PHP)
  • XAMP (Linux Apache MySQL PHP)
  • MAMP (Mac Apache MySQL PHP)

and you need to save files in working directory of the server.

Then those files can be executable in web browser.

Regarding Sublime, Its just an IDE (integrated Development Environment) software which recognize PHP and other languages code and make developer easy.

Upvotes: 0

Related Questions