I am using Windows 10 with Ubuntu to build the NC server. But I aware if I restart the server / logoff the Windows. Then the NC will down due to the Apache server is stopped. Does anyone know how to handle this problem? Thanks a lot!
Thats not a direct answer to your question. But please consider running a productive nextcloud instance on a seperate device or at least in a VM. WSL is not designed to run productive services. even their FAQ say so…
WSL targets a developer audience with the intent to be used as part of an inner development loop. Let’s say that Sam is creating a CI/CD pipeline (Continuous Integration & Continuous Delivery) and wants to test it first on a local machine (laptop) before deploying it to the cloud. Sam can enable WSL (& WSL 2 to improve speed and performance), and then use a genuine Linux Ubuntu instance locally (on the laptop) with whatever Bash commands and tools they prefer. Once the development pipeline is verified locally, Sam can then push that CI/CD pipeline up to the cloud (ie Azure) by making it into a Docker container and pushing the container to a cloud instance where it runs on a production-ready Ubuntu VM.
Also, even though you will be able to run many popular server applications (e.g. Redis), we do not recommend WSL for hosting production services – Microsoft offers a variety of solutions for running production Linux workloads in Azure, Hyper-V, and Docker.
Besides of that Windows 10 is generally not designed to run services without a user logged in, even with native Windows apps. For this purpose MS offer their various Windows Server products.
In case you absolutely have to do it anyway, maybe this video will help you…
@szaimen Thank you so much. Finally, I follow 1st result and for grant the apache2 without password option need to use this command “sudo visudo -f /etc/sudoers.d/wsl_start_up”. Then the service will start when user logged in to the Windows. As I want the service start when computer start. So that I do one more thing that I add task schedule to run the .bat when windows start. After that seems everything is fine.