You need to run a simple web server and you don’t want to set up a virtual host or do any configuration. Here is how you can run a simple web server locally. Note, these utilities are not for production web hosting.
Pythons built-in HTTP server
Use Pythons built-in HTTP server. Python ships with a module for running an HTTP server. This is a perfect tool running a simple HTML website. Here is the command:
$ python -m SimpleHTTPServer 8080
This will serve the content from the current directory on port 8080. You can, of course, change the port as long it is not in use. Visit http://localhost:8080 to view the output.
PHPs built-in webserver
If you need to execute some PHP then you can use PHP’s built-in webserver. This is useful if you don’t have Apache or Nginx setup or you don’t want to mess with virtual hosts and other server configuration.
The command to run a PHP server is:
$ php -S 0.0.0.0:8080
For this to work, the file you want to host needs to be index.php
NPM module server
Node also has an HTTP server you can install via NPM called serve. Serve is a simple node module that you can use to host simple websites locally.
Install: yarn global add serve
To run a server the command is:
$ serve
Conclusion
Now you know 3 ways to run a web server from the command line. I hope you found this useful!
Leave a Reply