Can I set a home web server with java instead of php?

To make a web server on your local network available to the internet as a whole, you have a few steps. These are all working toward the goal of having a person somewhere in the world be able to request your website and be able to actually reach it:

  1. You need a way for computers to know how to find your server. Your NETWORK has an IP address (you can go to whatismyipaddress.com to find out what it is) that will point to your network. You could just use that as your server's address but there are two problems: That number is hard to remember and share with people and it is likely to change! Let's solve the first one first:
  2. Buy a domain name. There are lots of places to do that - the most popular (probably) is godaddy. When you get your domain name, you can go into the settings in godaddy and tell that domain name to point to your IP address. That will solve the first problem.
  3. IP addresses on normal home networks (IE: not "business internet plans") don't guarantee a static (non-changing) IP address. You could set up your domain to point to your IP address today and try to go to your website tomorrow and it won't work! We fix that by using "dynamic DNS services" (for brevity, I'll call these dynaDNS for the rest of this step). DynDNS is a popular one. It costs some money per month (there ARE free ones but at least most put ads on your pages) but if you're going to be making money off your website, it could easily be worthwhile. These work by having a device on your network (often the server itself) tell the dynaDNS when its IP address has changed and the dynaDNS then updates its local "routing table" - a way for it to tell computers where your network is. Many home routers have settings available inside them that will update dyndns (and some other dynaDNS services) records for you so you don't have to do any programming to do this step. You will have to update your domain name settings to, instead of pointing to your IP address, point to the nameserver of your dynaDNS service but your dynaDNS service will have instructions on how to do that.
  4. Your potential users still can't reach your website, though. Looking at the flow of data, we will see that the user has used your easy-to-remember domain name that allows your browser to request your actual IP address from the dynaDNS service and has made the request to your network. So what is in the way? The request still has to get to the correct computer on your network. You often have many computers (game console, phone, tablet, etc.) on your network so we have to tell the router which device should handle this request. That takes two steps:
  5. Go into your router settings and make sure to give your Pi a static IP address. You might have already done this but it's important that, if your Pi's IP address is 192.168.0.105, it STAYS that address. Doing this is dependent on your router so I can't tell you exactly how to do it.
  6. This is also different for each router but you'll need to find a setting called "port forwarding" or "virtual server" on your router's settings. You will need to add a listing there to forward port 8080 to your Pi's IP address and port 8080. NOTE: you MIGHT be able to forward port 80 (the standard HTTP port) to port 8080 so that users don't have to type in www.yourdomainnamehere.com:8080 to get to your website. I have just never done it.

TEST! Everything should work. You should (after a day or so wait) be able to type www.yourdomainnamehere.com into your browser and get your web page. If not, here are some testing tips.

  1. Can you reach your website by typing its LOCAL IP address into your browser? If not, there is a problem with your local network or the server itself. Debug that.
  2. Can you reach your website by typing in your EXTERNAL (the one from www.whatismyipaddress.com) IP address? If not, there is a problem with your router settings. Try using ports 80 and 8080 dependent on how you configured your router.
  3. If both of those work, there is a problem with your domain name settings. Try re-doing steps 2 and 3 and pay careful attention to the instructions from your dynaDNS service provider to make sure you configure those settings correctly.

IMPORTANT NOTES: most IPSs don't like home users running servers on their networks. All of them that I know of have rules against it. They don't generally care if you don't get a lot of traffic but if you're getting a lot they may shut down your service. That's your risk. Also, some of them block port 80 (and sometimes 8080) for incoming requests. If that's the case, you may have to upgrade your service to a business plan. They don't have the same restrictions for those and you could skip the dynamic DNS service step in some cases because most business plans guarantee a static IP address.

Good luck and if you have any more questions, feel free to ask.

/r/raspberry_pi Thread