PHP Built-In Web Server & Testing Your Development Project In Mobile Without Any Software


Share On        


In this article, you will learn how to start the PHP built-in web server. How to connect to your computer to mobile hotspot and test your PHP project from your computer in a mobile browser.


Step 1 - Setup Local Working PHP Project


For the sake of demonstration I have created testserver as PHP project inside htdocs folder. You might be creating inside /var/www/html depending on software you use in your computer. You might be having working project


Step 2 - Create index.php & Add Code For Testing


Now in my testserver project folder I have created index.php and added the following code in it


<?php
echo 'Local Web Development Testing!';


NOTE: If your using any framework like LARAVEL / SYMFONY which points to public folder then don't loose hopes I have even covered in this article, please continue reading

Step 3 - Connect Your Laptop To Mobile Hotspot


Now turn on your mobile hotspot and connect your laptop to it. I use ( Android ) Redmi Note phone and you can find the hotspot enabling option with the following, this will mostly remain same for other devices too

i. Settings -> Portable Hotspot ->Portable Hotspot ( Turn On By Clicking Switch Button )

ii. Click On Setup Portable Hotspot -> Set SSID & PASSWORD

Your all set to share & connect your hotspot with SSID & PASSWORD


Step 4 - Check IP Address Of Your Laptop


After connecting your laptop to mobile hotspot. Go to your terminal and type the following command


MACBOOK / UBUNTU


ifconfig 


Windows


ipconfig


You will see the ip address allocated to your laptop there, for example mine is shown in the following image


IP Address Of Laptop After Connecting To Phone Hotspot


Step 5 - Start Your PHP Built In Server From Step 4 IP Address


Now go to your PHP project folder ie testserver from the terminal and run the following command to turn on the PHP built in server.


sudo php -S 192.168.43.43:80


If you have any specific path like public folder in you use LARAVEL to start with then use -t parameters as follows


sudo php -S 192.168.43.43:80 -t public


Here we are using the same IP Address 192.168.43.43 as that of my laptop got assigned after connecting to mobile hotspot in Step 3. And I want it to get connected with port 80 by default


You will get the following success output after running the above command


Plain PHP Output


sudo php -S 192.168.43.43:8888

#ouput
Password:

PHP 7.2.21 Development Server started at Sat Apr 25 13:34:56 2020

Listening on http://192.168.43.43:8888

Document root is /Applications/MAMP/htdocs/testserver

Press Ctrl-C to quit.

[Sat Apr 25 13:35:11 2020] 192.168.43.1:45870 [200]: /


Laravel Project With Public Folder


sudo php -S 192.168.43.43:80 -t public
Password:
PHP 7.2.21 Development Server started at Sat Apr 25 13:40:13 2020
Listening on http://192.168.43.43:80
Document root is /Applications/MAMP/htdocs/stackcoder/public
Press Ctrl-C to quit.


Now your application is ready to be access with http://192.168.43.43:80 URL. No need to add port 80 as its the default port for HTTP. You can test the same in your laptop before going to your phone browser.


Step 6 - Testing In Your Mobile Browser


Now go to your phone browser and open the URL http://192.168.43.43 you will be able to see the application developed as shown in the following image


Plain PHP Project


Plain PHP Project Image


Laravel Project Which Points To Public Folder


Larvel Project



Conclusion


Hope this article helped you. You might be interested in my other articles




AUTHOR

Channaveer Hakari

I am a full-stack developer working at WifiDabba India Pvt Ltd. I started this blog so that I can share my knowledge and enhance my skills with constant learning.

Never stop learning. If you stop learning, you stop growing