Introduction
When developing on a local server, it can be helpful to enable access to your site or web application from other devices on the same local network. For example, this allows you to preview your site on a phone or tablet.
In this article, I’ll guide you through configuring access to an Open Server Panel 6 (OSP) project within your local environment.
Configuring Access
Steps for the Host Computer (Device [1])
- Press Win + R, type
cmd
, and hit Enter. - In the terminal, enter
ipconfig
and press Enter. - Locate the line labeled IPv4 Address and copy its value (e.g.,
192.168.0.100
). - Open the
.osp/project.ini
file located in the project directory you wish to make accessible. - Add the following line at the end of the file, replacing
192.168.0.100
with your copied IP address:
aliases = 192.168.0.100
- Save the file.
- Restart Open Server.
Steps for the Device Accessing the Project (Device [2])
- Open a browser on the target device.
- Enter the IP address from step 3 (on Device [1]) into the browser’s address bar.
Limitations
It’s important to note that this setup comes with certain limitations. Depending on your use case, you may need to address these limitations or explore alternative methods.
One Project at a Time
Since the access relies on the host computer’s IP address, you can only serve one project at a time. Accessing multiple projects simultaneously would require additional configuration or tools, such as a reverse proxy or virtual host management.
CMS-Specific Challenges
If your project uses a Content Management System (CMS) that stores the base URL in its database or configuration file, you should understand how these systems handle URLs.
For example, consider a WordPress project with a local domain of project.local
. WordPress stores the base URL in the wp_options
table under the fields siteurl
and home
. These values (e.g., https://project.local/
) are used to generate URLs through functions like home_url()
.
If you access this project from another device via the local network, WordPress will continue generating URLs based on the stored domain (https://project.local/
). On the target device, this will likely result in 404 errors because project.local
won’t resolve without further configuration.
Suggestions for Improvements
- Virtual Hosts: Consider setting up virtual hosts and configuring a hosts file on the target device for proper domain resolution.
- Temporary Adjustments: Update the CMS configuration to match the IP address during testing. For WordPress, this involves updating the
siteurl
andhome
options in the database or viawp-config.php
. - Dynamic IPs: If your local network uses dynamic IPs (DHCP), ensure your host machine has a static IP or configure a reserved IP in your router settings.
Conclusion
This method is simple and effective for testing projects across devices within a local network. By understanding the limitations and exploring potential workarounds, you can create a more robust and flexible development environment.