Last Updated: February 25, 2016
·
1.524K
· newsociallife

Webserver using only PHP

I will show you how to create a webserver using only php 5.
You say impossible?
Just try :)

What you need?
-Just PHP package
How to do this?
Open your terminal and insert this code:

php -S 127.0.0.1:80

Our tutorial is ended, thanks

12 Responses
Add your response

Just work on PHP 5.4+

php -S 0.0.0.0:8080

ATTENTION: This server is not made to be used in production. In addition has some problems when used with Javascript/JSON. Also problems with MIME types.

over 1 year ago ·

the code you entred opens the port 8080... so the user has to write 127.0.0.1:8080 in the browser, with my code the user has to write just 127.0.0.1
but of course your code works too

over 1 year ago ·

This is a awesome implementation of PHP 5.4! Is like a Rails App but without a framework! XD

over 1 year ago ·

@newsociallife 0.0.0.0 is equal to 127.0.0.1. You can write like this too:
php -S localhost:8080
Also the port 80 sometimes is not allowed to be used by localhost (127.0.0.1) web servers if you are not root on the machine. That is why you should use another port.

over 1 year ago ·

@jmarizgit I know that 0.0.0.0 and 127.0.0.1 are the same thing in theory you could even write ::1 if you have an IPV6 card

@squiter85 well, am not a fan of ruby on rails, but yes, it's like it :)

over 1 year ago ·

@newsociallife can I ask why you don't like RoR? :)

over 1 year ago ·

@squiter85 well... i hate the ruby sintax, ruby is less powerfull than php
doing a mysql connection in ruby requires 1000 of tweaks ( don't say it's just editing a configuration file, you have to install the mysql gem, edit the configuration, edit the other file ( the one with all packages, don't remember the name anymore ) and then you can cross your fingers and look if it works )...
in php just insert the mysql exstension in php.ini ( in 90% of the cases is already inserted ) and then magic, works...
php has full integration with html... ( erb isn't powerfull as the <? and ?> :) )

over 1 year ago ·

@newsociallife lol. php is bullshit

over 1 year ago ·

@newsociallife your comment is bad and you should feel bad

over 1 year ago ·

Neat, but I wouldn't want to lose apache. It just handicaps me

over 1 year ago ·

@newsociallife And if you want to use Postgresql or MongoDB? In Ruby you just use the right gem. Also with erb, it's just one templating option of many. And, btw. just use the mysql2 gem. The mysql gem is old. And did I mentioned that you have lots of app servers you can choose from. For production and development. So, please inform yourself before you make a quick judgement.

over 1 year ago ·

For those < PHP 5.4:

https://github.com/lox/phpup

over 1 year ago ·