Short answer : it has been attacked 
Short answer : you can’t.
Long answer : well, take an analogy with your house. How do you make it so that people do not enter your house ? You lock the front door. But since the door is not the only possible entrance, you also close the window, the cellar, and the chimney somehow. Is that enough to certify that nobody else than you entered your house ? Nope … the window might not be entirely locked, or maybe someone has the key somehow…
So maybe you also check that every items is still at its place after you left. But that’s difficult to check, and what do you know maybe the intruder just entered to add poison in your yougurth in your fridge using something discrete like a syringe ?
In computer systems, a rootkit or a backdoor is pretty much invisible so it’s really hard to detect those. So you can’t really know. An attacker might have had access once 10 years ago, left a backdoor and you might never be aware of it. In fact, the backdoor could be already included in the image of the initial system you installed, or in one fundamental program running on the system (e.g. C/C++ compiler)
Of course, the attacker needs to gain access to your house at some point. So maybe you can put cameras or an alarm, and get an email each time somebody enters your house. But that’s a bit “heavy” to check each time you enter your house that “yes, this is actually me”. The equivalent on a server would be to receive an email each time you (the admin/root) log in, or each time an user gets admin/root access somehow.
But this does not prevent either an app or a service (let’s say, wordpress or php-fpm) to be compromised and start running weird activities such that suddenly sending thousand of emails. If you know what you are looking for and know what things are expected and what are not, you will end up noticing this. But generally speaking, there is no magic recipe for detecting this kind of behavior either. Sending thousand of emails might be something common and legit on your wordpress manages a ~big mailinglist. But let’s say if you use a monitor tool checking various aspects of your server, you might be able to notice an unexpected increase in resource usage which you can then attribute to your wordpress that got compromised…
So tl;dr : imho security is a mess and there’s basically no way of checking things are alright, except with regular and rigorous monitoring of many things. And as always with security : everything also really depends of what you defend against. Are you defending against targeted NSA attack (during the installation, or after the installation ?), against bots trying to bruteforce root/admin, against your own users, or against automatic attacks targeting apps with bad security reputation…