logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: serve php page without allowing them to be downloadable
Author
completementgaga



Joined: 07 May 2021
Posts: 3
Location: Rio de Janeiro, Brazil

PostPosted: Sat 08 May '21 17:00    Post subject: serve php page without allowing them to be downloadable Reply with quote

Hello everybody,
I have a question:
how to let apache use a .php file to serve the corresponding http page and still prevent the same .php file from beeing downloadable with wget, by third parties ?

I guess this could involve file ownership, file permissions, php configuration and apache configuration.

Here is what I had before discovering that my php code was exposed:

I have Apache 2.4.37 installed on a centos 8 server, together with PHP 7.2.33


I have a hello world test.php php file in /var/www/html
Code:
$ls-l
-rw-r--r--.  1 root   root         75 31 août   2020 test.php


When
I do
1) go to siteurl/test.php with firefox,
I get the hello world message echoed normally.

The issue is that I am able to download the source code from another computer doing
2)
Code:
wget 'siteurl/test.php'

in the terminal
I feel it is not very safe, because database credentials can be in php files like config.php; and in general I want to hide my code, if possible.

I tried to solve the issue editing httpd.conf:

I added the following lines

Code:
<Files ~ "\.php$>
<RequireAll>
    Require all denied
    Require not user apache
</RequireAll>
</Files>


(User and Group are set to apache)

I restarted httpd
Now
when I do 1),
I get the message
Quote:
Forbidden
You don't have pmission to access /test.php on this server.
"
when I do 2), I get a 403 error.

So the problem is not really solved,

I would like 1) to behave as before and 2) to behave as it is behaving right now.

Thank you for your help,

best.


Last edited by completementgaga on Sun 09 May '21 19:10; edited 1 time in total
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Sat 08 May '21 20:56    Post subject: Reply with quote

how about just

<Files "config.php>
Require all denied
</Files>

or for multiple php files

<Files ~ "(config|install|preferences)\.php$>
Require all denied
</Files>

php will still be able to import those files, Apache will just not serve them up to the visitors. Visitors will get the 403 Forbidden.
Back to top
completementgaga



Joined: 07 May 2021
Posts: 3
Location: Rio de Janeiro, Brazil

PostPosted: Sun 09 May '21 19:12    Post subject: Reply with quote

@glsmith Thank you for your answer.
Are you meaning there is no way to prevent all php source from beeing acessible to third parties?

Best,
Back to top
completementgaga



Joined: 07 May 2021
Posts: 3
Location: Rio de Janeiro, Brazil

PostPosted: Sun 09 May '21 20:41    Post subject: Reply with quote

Another answer to the same question has been provided
at https://stackoverflow.com/questions/67460525/how-to-serve-php-pages-without-allowing-them-to-be-downloadable/67460641#67460641

Best,
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Sun 09 May '21 23:20    Post subject: Reply with quote

There is a misunderstanding. When the Webserver is configured to interpret the php files they cannot be downloaded from the outside.
Back to top


Reply to topic   Topic: serve php page without allowing them to be downloadable View previous topic :: View next topic
Post new topic   Forum Index -> Other Software