Good content takes time and effort to come up with.
Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.
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.
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
Now in my
testserver project folder I have created
index.php and added the following code in it
echo 'Local Web Development Testing!';
NOTE: If your using any framework like LARAVEL / SYMFONY which points to
publicfolder then don't loose hopes I have even covered in this article, please continue reading
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
After connecting your laptop to mobile hotspot. Go to your terminal and type the following command
MACBOOK / UBUNTU
You will see the ip address allocated to your laptop there, for example mine is shown in the following image
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.43as that of my laptop got assigned after connecting to mobile hotspot in Step 3. And I want it to get connected with port
You will get the following success output after running the above command
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 : /
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.
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
Hope this article helped you. You might be interested in my other articles
Happy Coding :)