Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a php without a web server?

Tags:

php

I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the steps that I do I have to choose through the installation of php? I mean the preferences as CGI and the components after that step?

I installed the php 5.3.3 but is seems not working, I get several message that the php5ts.dll is missing and when I put that file in my ext folder other error messages appear. Are there any configuration files or steps that I have to use? (is php 5.3.3 suitable for doing something like this?)

If I have to have a web server installed how can I run my php code through the command line?

like image 797
touinta Avatar asked Nov 29 '10 08:11

touinta


People also ask

Can PHP be run locally?

The preferred way of running PHP files is within a web server like Apache, Nginx, or IIS—this allows you to run PHP scripts from your browser. That's how all PHP websites work! The other way is to run PHP scripts on the command line, and it doesn't require you to set up a web server.

Can we run PHP without WAMP server?

You can run PHP scripts on Windows without needing to install WAMP or Apache webserver. This is great if you don't need all the features that these tools provide. The PHP built-in web server is not intended for production use but is great for developing and testing.

Can I run PHP without xampp?

To run PHP for the web, you need to install a Web Server like Apache and you also need a database server like MySQL. There are various web servers for running PHP programs like WAMP & XAMPP. WAMP server is supported in windows and XAMP is supported in both Windows and Linux.

How do I run a PHP site in local?

Type the command php -S localhost:8000 to run your site on port 8000. Note: If you get an error that 'php' is not recognized, you likely will need to add it to your path manually. To do that, locate php.exe (for me it is in the directory C:\xampp\php\ ).


2 Answers

You should normally be able to run a php file (after a successful installation) just by running this command:

$ /path/to/php myfile.php // unix way C:\php\php.exe myfile.php // windows way 

You can read more about running PHP in CLI mode here.


It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:

$ php -S localhost:8000 

You can read more about running a PHP in a Web Server mode here.

like image 81
Michal M Avatar answered Oct 22 '22 04:10

Michal M


For windows system you should be able to run php by following below steps:

  1. Download php version you want to use and put it in c:\php.
  2. append ;c:\php to your system path using cmd or gui.
  3. call $ php -S localhost:8000 command in a folder which you want to serve the pages from.
like image 29
Brijesh Kapletiya Avatar answered Oct 22 '22 04:10

Brijesh Kapletiya