XAMPP DirectiveIndex issue (php development) - php

I'm having an issue with using XAMPP and the ability to use an includes folder in php etc. I'm learning how to use a single point access for my php files, by that I mean, you put only an index.php in the main folder to be accessed and it is it use classes that are located in the Includes folder outside the public_php folder.
Here is the current config inside the httpd.conf (located in the apache2 folder)
Here is the current config :
Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.html index.php
</Directory>
Here is a screenshot of my file structure, is someone able to help me on how to use the DirectoryIndex setting so that my program is able to just use the require_once 'bla/bla.php';
Thanks for any contribution given.

require_once (and it's other variations) include files locally.
You don't have to use your alias to access them, just write the full local path:
if you file is located at /Applications/XAMPP/bla/bla.php:
require_once('/Applications/XAMPP/bla/bla.php');

Related

How to load themes file properly using php

Talking about my project I am working, its just a simple website in localhost.I am Xampp server rand inside htdocs my website is in file creative which contains index.php file and another sub directory themes which further contains themes folder which contain all the necessary html php and css files that builds my websites.
When a user enters I want to redirect him from the index.php in localhost/creative to the index.php in localhost/creative/themes/theme-folder. I tried to use require_once('creative/themes/theme-folder/index.php'); but in most of cases it fails. is there any other way to do so.
You can modify the .httpd file.
Then you add:
#The path of your repositories:
DocumentRoot "C:/xampp/htdocs/creative"
#then you make an alias:
Alias /creative "C:/xampp/htdocs/creative/themes/theme-folder"
<Directory "C:/xampp/htdocs/creative/themes/theme-folder">
#Modify this data according to your needs
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>

Access files in home folder with PHP (linux)

I have a php application located in /var/www/phpapp and I need to create links to download files located in the /home/myuser folder. The complete path to the files is stored in a database, so the goal is for the app to place a link like Download 1 and be able to download it. I access the php app using http://localhost/phpapp. I know I can do this using alias in apache but I still haven't figure it out.
For anyone having this same problem, I got it working using this:
In Ubuntu: I went to /etc/apache2/sites-enabled/ and edit the site file
In Centos: Go to /etc/httpd/conf.d/ and add a new xxxx.conf file
And I added this into the file:
Alias /home "/home/user/"
<Directory "/home/user">
Options None
AllowOverride None
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
MultiViews Require all granted
</Directory>

How can I start a laravel project outside of "htdocs" folder in xampp?

Is it a way to start a Laravel project in another folder? For example:
instead of C:/xampp/htdocs
to D:/projects/web/project1
So after I download Laravel with composer to my D:/projects/web/project1 folder I want to reach it as: http://project1.local in my browser.
I added 127.0.0.1 project1.local to my hosts but it only opens xampp in the browser.
Suggestions, ideas?
You need to indicate to xampp that your site will be sited outside the documentroot folder (where all the sites in your server are located).
In your httpd.conf file add these lines, which will allow to you to access the site via http://localhost/laravel.project:
Alias /laravel.project "D:/projects/web/project1/public"
<Directory "D:/projects/web/project1/public">
Options FollowSymlinks
AllowOverride none
Require all granted
</Directory>
If you want to get access directly, via a uri like http://laravel.project, you must create a VirtualHost.

Providing downlaod link to file in non-public section of server

I have a number of files stored in a folder outside of the publicly accessible portion of my website.
For example, the file 'abcd.jpg' is stored (in terms of the server) in '/home/private_files/' and the website is in '/home/public_html/website.com/'
When I go to provide a link to view the file, I use
Download however this doesn't work.
Any suggestions?
If you are using Apache as the server, you can set it to alias a directory in httpd.conf...
Alias /images/ "/home/private_files/"
<Directory "/home/private_files/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</IfModule>
and you can use this
Download
You can not access to directory that located in out of www.
use symlink to link to file:
ln -s /home/private_files/abcd.jpg /home/www/abcd.jpg
and delete the link after deadline(something like rapidshare)
or use file downloader like this

Allowing only localhost to access a folder where all inclusive php files exist

We all have php files like 'connect_db.php' for include purposes only.
Suppose I have all those inclusive .php files in "www/html/INC"
And I have index.php
I want index.php accessible from browser to everyone, but I want to prevent users' direct access to "www/html/INC" folder. (e.g. when type in the browser 'www.domain.com/INC/' -> 404 error etc)
How do I achieve this?
Preferrably using .htaccess file in the root directory please.
Something like
<Directory /INC>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
should work.
How do I achieve this?
Don't. As per my previous answer, it's much more secure to put connect_db.php in /www/, not in /www/html/INC/. If you are going to do so, then you'd use /www/html/.htaccess:
<Directory "/www/html/INC">
order allow,deny
deny from all
</Directory>
Google searches have brought me here so I figured I'd post what I found in the apache docs today. I'm not positive what versions of apache it is available in, but do a search for your version to verify.
Now you can just use Require local. I'd recommend putting an .htaccess in the folder that you want to restrict access to with just that line. However, if you must do it in the root directory then here's what it would be:
<Directory "www/html/INC">
Require local
</Directory>
As of Apache 2.4, Require is the way to go.
E.g. the following denies access to the /www/html/INC directory by anyone except localhost:
<Directory "/www/html/INC">
Require all granted
Require ip 127.0.0.1
</Directory>
Move connect_db.php to the more high level in directories tree, than public directory.
And all scripts, which should not be executable - too.
/home/user/project/incs/ -- here your inclusive scripts
/home/user/project/www/html -- here your index.php and other executable scripts.

Categories