Can someone steal my PHP script without hacking server?

Adarsh asks:

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 for testing purpose. Open lighttpd websever config file and bind server address to
# vi /etc/lighttpd/lighttpd.conf
Bind to localhost/
server.bind = ""
Start lighttpd:
# /etc/init.d/lighttpd start
Now follow these instructions to configure php as fastcgi module. Now test your configuration using url 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
# 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.
Start apache:
# /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/
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:

<?php   phpinfo(); ?>

Finally when php started to work properly, make sure you bind back a server IP address from 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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 15 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
15 comments… add one
  • Binny V A May 2, 2007 @ 11:30

    One thing to note is the .inc files – many people use this extension when including files in PHP. But many servers give it text/plain(or similar) mime type. This is a huge security risk.

    If your server is not configured properly, people will be able to get this file.

  • 🐧 nixCraft May 2, 2007 @ 11:59


    Good point, somehow I missed altogether about .inc files.

    Appreciate your post!

  • oPx May 3, 2007 @ 19:11

    Nice , never thought about it like that !

  • @be Mar 4, 2008 @ 18:37

    Great advice for the beginner coder!

    Using .inc for extensions isn’t the best way as stated above… Great work 🙂

  • Silver Knight Feb 2, 2009 @ 1:21

    One tiny little comment I have is that this last paragraph makes it sound as if one would be safe by serving all PHP requests from an application server via mod_proxy.

    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.

    While this does indeed introduce another layer of security to the equation, it also introduces more complexity and therefore more possible points of failure. Furthermore, a misconfigured server behind the proxy will happily hand out PHP code just as freely through a proxy as it would directly, as the proxy pretty much just passes on whatever it gets from the servers it makes it’s requests to…

    That having been said, this should not be an issue at all if people follow your good advice about testing it all on localhost ( and configuring it correctly as you have so helpfully described in such clear detail.

    Also, your advice to keep PHP code out of the webroot is very good advice indeed. Any important PHP code should be kept outside the webroot where the web server cannot accidentally serve it up as plain-text, and should be included using PHP include or require statements so that if something does happen to go wrong, then the worst that could happen is a totally non-essential file might get served up as text, but nothing of any significance would be at risk.

    Thank you very much for posting this useful and informative post, as I am certain it will help many beginners out there. Keep up the good work… 🙂

  • Tanner Jan 28, 2011 @ 5:16

    PHP downloading files can make happen, too. Say you have a file called download.php, with pretty much no security, that downloads a file like this: “download.php?file=file.ext”. somebody could type: “download.php?file=../index.php”, or so.

  • Eni Aug 19, 2011 @ 0:22

    How about grabbing this php file ehh ?
    any manner?
    please reply

  • fbpetition Dec 14, 2011 @ 18:26

    please remove “Tanner January 28, 2011” quotes … this is encouraging hacking … will complain to Google if not removed within 72 hours …..

    • NoNeedForAName Apr 20, 2012 @ 23:38

      Kill yourself. Now.

    • MV May 31, 2013 @ 16:15

      Listen you fuckquad, Google doesn’t run the Internet and last time I checked these are people’s posts. Don’t like it, go fuck yourself.

    • Dor May 9, 2016 @ 3:38

      You protect yourself from hacking by knowing how its done. Sometimes i go on creepy websites that explain how to scam and hack. Because i want to stay safe and know how it works.

  • jin Mar 25, 2012 @ 12:45

    mr. Tanner is giving a tip of php programming its not hacking. hacking is much more then this

  • Tom May 8, 2013 @ 20:18

    Another factor to consider is backup files. If you edit files on the server some editors are configured to save a backup copy in the same directory with a ~ or # character appended to the filename. These can easily be guessed and will be served as plain text by the web server.

  • LessEvil Jan 23, 2014 @ 12:40

    Please dont use bad words…..My 10 Year old daughter reads this stuff !

  • tans Sep 3, 2015 @ 21:21

    php code is interpreted in the server and in clients it see as plain html, so definitely no way unless someone can get into your server.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum