Is there a way I can compile or obfuscate the PHP code somehow so that it can still run on the server but cannot be viewed/edited/modified like compiled software?
In order for the code to run on the server, the CPU has to understand it. CPUs are much, much stupider than humans. If the CPU can understand it, then a human can, too. If you make it so a human cannot understand the code, then a CPU cannot either, and you can no longer run it.
By the way: all currently existing PHP implementations (Zend Engine, HVVM, P8, Quercus, Phalanger, Peachpie, HippyVM, Tagua VM, JPHP, …) will actually compile your PHP code.
Or is the only technical option to switch to a compiled programming language like Java?
It makes no difference. The code has to be on the server in a form that the server can understand it. But then, a human can understand it, too.
The only possible solution to make sure that someone cannot get access to your code is … to not give them access to your code. It really is that simple.
The easiest way to achieve this, is to keep the code on your premises and only offer access to it via a tightly controlled service. That's how Google keeps its code secret, for example.
A much, much, much harder and more expensive way is to have full end-to-end encryption of your code. Essentially, you deliver the server as a tamper-proof, impenetrable black box that only allows access through a tightly controlled service. The trick here is to ensure that the black box actually stays "black". This requires that you have full control over the Operating System, all libraries, the CPU, the motherboard, the RAM, all busses and I/O chips in the system, and so on.
Remember the XBox? Microsoft transmitted the master encryption key from the encryption module to the CPU via an un-encrypted bus. They thought this would be okay because there doesn't exist any hardware can snoop such a highspeed bus. Well, it turns out if you have 10000000$ oscilloscope and a lot of time on your hand, you can actually snoop that bus, and as it so happens, MIT has invented such an oscilloscope, MIT students have a lot of time on their hands, and are trained in cryptanalysis, and they like running Linux on everything, so they created a Linux installer for the XBox, which in turn was reverse-engineered by crackers to create installers for pirated games.