First understand that it is not possible to make an impenetrable portal. No matter what you do a Level 8 player with enough L8 XMP Bursters can (currently) take down any portal no mater how well defended it is. But some times it is a war of attrition you know they can take it, but make them work their butts off for it.
Keep it Charged
The easiest thing you can do is keep your portal fully charged. This basic step helps no matter what other tactics you use. A weaker portal is an easier one to take down.
Portal Shields - Your portal shields are your basic building block of portal defense. Their defense rates range from 10 mitigation for common shields (the green ones) to 30 for the very rare ones (the pink ones).
Force Amplifier - These are nice mods to use in conjunction with other portal modifications, but you will not want to stack your portal with Force Amps because after deploying the first one you get less protection from each additional one. The first one deployed does double the damage to an attacker.
Turret - This great portal mod gives your portal more attacks.Like the Force Amp you do not want to stack these up on a portal because of diminishing returns. You will want to combine it with other portal mods. Placing a turret on your portal will have your portal attack an attacker twice but will also give a hit bonus of 30%.
A not so commonly known fact is that links, either incoming or outgoing, provide a defensive bonus to portals. One link gives about a 10% defensive bonus to a portal. Each additional link gives less of an increase until you have 8 links. A portal with 8 links gets a 50% bonus, but after 8 links there seems to be no advantage.
Another interesting trick you can use to protect a portal is use other portals around it to defend it. The picture below is a local level 8 farm. The portal circled in red has no defensive portal mods, but rather heat sinks and multi-hacks. The portals around it have shields force amps and turrets. This is great for farming. We have 14 L8 portals and one is a very fruitful portal. You can walk the path of this artsy park and each sculpture has a portal. Then the monument in the center has the multihack and heat sink. As you walk the path, you can hit each portal and every 2nd or 3rd sculpture hit the monument. Walk the path a few times and you have hopefully loaded up on some goodies. The outer perimeter portals protect the inner one. An attacker would sustain significant XM losses and have to use many additional XMP Bursters to take down the farm. It's not impossible, and happens somewhat regularly, but it takes a lot of resources on their part to do.
Yes, Portal keys can be a very effective defensive tool. When you get the alert on your scanner that you have a portal under attack, start recharging the heck out of it. Eventually your portal may fall, but once again you have cost the attacker to deplete their inventory much more than they otherwise would have.
With these tips hopefully you can defend your portal well and atleast annoy the heck out of any would be attackers.