I wrote a bit of php code in my r-pi on which I installed raspbian. I would like know to protect this code from the possibility to being copied or read. I looking for a solution that crypt my directory (eg. /home/pi/myphpcode) from reading through raspbian and from reading through the SD insertion in a PC. Thanks.
To keep someone from reading specific data on the SD card, use an encryption package to encrypt the data and then keep the decryption key off of the SD card. Of course, then application on your RPi will not be able to read the data, either. But your question did not state that as a requirement.
You can store your home directory, or at least the encrypted program, using some
dm-crypt based technique.
dm-crypt will work on both physical devices (e.g. encrypted USB thumb drive) or a disk image, and since you are using Raspberry Pi you can use write a bit of code to store the cryptographic key in I2C EEPROM, sort of like a hardware decrypt dongle.
And if your code is not too big (<=2MB), you can store it in
dm-crypt-enabled SPI DataFlash chips also.