Can someone steal my PHP code or program without hacking my Linux box? Can someone snoop script over plain HTTP session?
Short answer is no. PHP is server side thingy.
However a misconfigured webserver can easily give out php file to all end users. You need to make sure that mod_php / mod_fastcgi loaded and correct MIME type is setup. To avoid such problem always test your server before moving to production environment. Most Linux distro configures both Apache and PHP out of box.
How do I stop downloading php source code?
The first step should be stopping a webserver.
# /etc/init.d/httpd stop
# /etc/init.d/lighttpd stop
If you are using Lighttpd...
Next bind webserver to 127.0.0.1 for testing purpose. Open lighttpd websever config file and bind server address to 127.0.0.1
# vi /etc/lighttpd/lighttpd.conf
Bind to localhost/127.0.0.1:
server.bind = "127.0.0.1"
# /etc/init.d/lighttpd start
Now follow these instructions to configure php as fastcgi module. Now test your configuration using url http://127.0.0.1/test.php. PHP should work on server. If not working, refer to server log file.
If you are using Apache...
Open httpd.conf file and bind apache to 127.0.0.1:
# vi httpd.conf
The Listen directive instructs Apache to listen to more than one IP address or port; by default it responds to requests on all IP interfaces, but only on the port given by the Port directive.
# /etc/init.d/httpd start
Now make sure php is installed use apt-get or rpm command to verify the same:
# rpm -qa | grep -i php
# dpkg --list | grep -i php
If PHP is not installed just follow these instructions to install PHP. Next make sure httpd.conf or php.conf has following directives:
LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php
Note: the path may differ in your setup. Now restart httpd:
# /etc/init.d/httpd restart
A sample php code:
<HTML><HEAD>PHP</TITLE></HEAD> <BODY> <?php phpinfo(); ?> </BODY> </HTML>
Finally when php started to work properly, make sure you bind back a server IP address from 127.0.0.1 to public IP address.
Another option is keep your source code out of webroot and server all php requests from php application server using mod_proxy and multiple back-end servers.