How to block access folder that not has index file - php

I using xampp for my project. Now i have a problem
Example i have a project like
myproject\
|-subfolder\
| |---example.php
|-index.php
Now, if i process subfolder in my address like
localhost/myproject/subfolder
i will get a list of files in subfolder (b/c subfolder haven't index file).
Have anyway to block access that (not used index file? ). That should show any message instead of list files in the folder
thanks

You should configure your apache httpd.conf file, change something like:
Options FollowSymLinks Indexes
To:
Options FollowSymLinks
And restart your apach service.

You will have to create a specific file to show the message:
For instance
localhost/myproject/subfolder/message.html
This will then show the message and not all the files.

This is the Index feature of Apache and is designed to help with easy file navigation. Obviously this is undesirable on some servers. To turn it off you need to edit Apache's config file which is usually found in /etc/apache2/apache2.conf on Ubuntu or /etc/httpd/conf/httpd.conf on CentOS / RedHat but could be somewhere else, you did not specify operating system in question. Anyway, find it and edit it.
Search for Indexes in this file and change the value to -Indexes.
Then restart Apache with the following command:
sudo service apache2 restart
(on Ubuntu)
sudo service httpd restart
(on CentOS or RedHat)
Directory listing should now be switched off for all your folders.

Related

How to setup/access page in subdirectory of separate project for a Laravel/OctoberCMS website?

I have a website running an OctoberCMS theme that I built. It's running on a server from DigitalOcean. I need to add a separate project (namely code from Matomo analytics) on the same server and access a public page (e.g. my_site.com/matomo). I'm new enough to Laravel and server configurations that I'm unsure of how I need to configure the index.php files or maybe something like .htaccess so that I can access my_site.com/matomo.
Here's my file structure
/var/www/html/
index.php (serves the pages of my project)
artisan
bootstrap/
config/
modules/
plugins/
server.php
storage/
themes/
vendor/
matomo/ (for installing the analytics for the site)
index.php
matomo.php
piwik.php
config/
a number of other files I can enumerate if necessary
I've followed the instructions from matomo but to no avail. When I try to go to my_site.com/matomo I just get a 404 from my website with my theme's formatting for it.
I know this shouldn't be hard. Thanks!
EDIT: The home page of my website is at my_site.com, as desired. The various pages are at my_site.com/page_name. This is configured fine for my purposes.
Now, for Matomo, the instructions say:
Open your FTP client and upload the Matomo files in ‘binary mode’ to the desired location on your web server. For example using the Filezilla FTP client, you can enable Binary mode transfer in the top menu Transfer > Transfer type > Binary). All files can be uploaded to a “analytics” sub-directory in your public www folder, for example http://yourdomain.org/analytics/ or you could setup Matomo in its own subdomain and upload all the files at http://analytics.example.org/
If you have SSH access to your server, you can use it instead of FTP as it is much faster: run
wget https://builds.matomo.org/matomo.zip && unzip matomo.zip
So, I used the wget option to add it to what I believe is the "public www folder", /var/www/html. So the instructions lead me to believe I can go to my_site.com/analytics/ and then view the GUI webpage for further install and setup. However, this doesn't work as it takes to a 404 page that's setup for the rest of my site. I also don't know that I'd expect it to work as none of the files or folders in Matomo are named "analytics" -- I've also tried my_site.com/matomo for the record. So, this is to say, I don't know where the Matomo page is presented.
I don't have any experience with Matomo, but from the question I understood that you want to install two software X as CMS and Y as Matomo.
Your web server(I assume Apache is the web server) will serve all request to the following path: /var/www/html/index.php. Which belong to software X. Your request my_site.com/matomo will be served to software X, and because X doesn't expect this request it will output 404 Not Found error.
The first solution: which is the bad solution and harder solution is to edit /var/www/html/index.php and combine it with Y index.php if request have matomo in the URL.
The second solution: which is the optimal and better solution is to separate X and Y. It could be done in several ways:
You can combine all X files in a folder under /var/www/html/x, and all Y files in folder under /var/www/html/y. Then you can access x using the following URL my_site.com/x and y using my_site.com/y.
If the first way in not possbile because you need to have X as root URL like my_site.com. Then you can combine all Y file under the following folder /var/www/html/matomo. Then you need to create sub domain (virtual host for Y).
Create virtual host using Ubuntu and Apache:
sudo touch /etc/apache2/sites-available/matomo.my_site.com.conf
Then edit the file using your favorite text editor I will use nano
sudo nano /etc/apache2/sites-available/matomo.my_site.com.conf
and past the following code:
<VirtualHost *:80>
ServerAdmin admin#my_site.com
ServerName matomo.my_site.com
DocumentRoot /var/www/html/matomo/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Change my_site.com to your domain.
Then you need to enable the virtual host
sudo a2ensite /etc/apache2/sites-available/matomo.my_site.com.conf
Then restart apache to see the result.
sudo systemctl restart apache2
Your matomo will be under the following URL matomo.my_site.com
If you are not using Ubuntu or Apache, tell me what are you using to update my answer.
You don't need to fix anything in index.php. Analytics counters can be added to the layout (~/themes/mytheme/layout/mylayout.htm) of the page between the
<head>
...
</head>
or
<body>
...
</body>
according to the instructions of your meter
See https://github.com/octobercms/october/issues/1615. You need to add the folder you want to allow access to as an exclusion to the October CMS .htaccess, and then also disable the line that disables running any PHP file other than index.php.
So replace RewriteEngine On with
RewriteEngine On
# Allow access to Matomo
RewriteRule ^(matomo)($|/) - [L]
and then comment out RewriteCond %{REQUEST_FILENAME} \.php$ so it becomes # RewriteCond %{REQUEST_FILENAME} \.php$.

Laravel – Include external Project

In a Laravel project I have to include multiple projects, so that they are accessible at /example.
These projects have the structure of
/example
- index.php
- main.css
- app.js
(Usually there are more files then that.)
I have tried to use Redirect::to("example/index.php"), however this breaks all the <link>'s & <src> (where I would need to prepend /example to all of them.
This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.
What is the best way to include such external projects?
This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.
That's an excellent approach. Rather keep Laravel as Laravel and host the stuff just outside of your Laravel project.
Since you're using Apache, here's how to create a Virtual Host for that external project.
Please note - I'm assuming that your project lives in /var/www.
Decide on a URL for that project - I would use example.mylaravelproject.com. But anything will do.
Confirm the path of your project folder. For this example, we'll assume it's /var/www/example/
Run the following command (assuming you're using Ubuntu) - sudo nano /etc/apache2/sites-available/example.mylaravelproject.com.conf
Ensure the new file has the following contents:
<VirtualHost *:80>
ServerAdmin <your email address here>
ServerName example.mylaravelproject.com
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file
Run the following command sudo a2ensite example.mylaravelproject.com.conf
Run sudo nano /etc/apache2.conf
Make sure that this line appears somewhere in this file (preferrably in a <Directory> tag - AddType application/x-httpd-php .php
Then restart Apache by issuing the following command sudo service apache2 restart
Technically now your site has a valid vhost and should be working.
If you're doing this on a local environment and want to access your example project via the browser, you'll need to complete a few more steps:
sudo nano /etc/hosts - again, assuming that you're running Ubuntu
Add this line somewhere to your project: localhost example.mylaravelproject.com
Save and close that file. You should now be able to access that url via your browser.
If these steps don't work, it's likely that Apache isn't parsing the PHP files. If that's the case, try these links for some good answers on making Apache parse PHP:
Apache 2 server on ubuntu can't parse php code inside html file
Apache Virtual Host not parsing PHP

Apache can't find localhost/~user directory

Hi every one I'm setting up apache following a tutorial on OS X Yosemite.
I can get to the "It works" page from default WebServer directory but when setting up my own user directory apache doesn't find it anymore. I created the Sites directory in my User folder.
Then I created the username.conf in /etc/apache2/users I also have a Guest.conf there that's not mentioned in my tutorial but I don't know if it is the problem and I'd rather ask than delete it without knowing.
my username.conf file :
<Directory "/Users/mathiashintjens/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I used sudo chmod 644 mathiashintjens.conf to changes privileges then sudo apachectl restart
Then I created an index.html file in my ~/Sites directory and yet I still can't open it in my browser using http://localhost/~mathiashintjens/
I have installed MAMP in the past so maybe here lies the problem?
If anyone could help me it would be really cool.
Thanks in advance!

Display all files in MAMP htdocs through browser

I recently purchased a new MacBook Pro (10.8 OS) and installed MAMP 3.0 (not MAMP-Pro) but I have been searching the web on how to display all files when viewing a folder within the htdocs directory such as: htdocs/stackoverflow VIA the browser (Chrome or Firefox). This is a feature that I do not have a problem with in Windows using either WAMP or XAMPP when navigating to the localhost/directory/contents. I do understand that localhost must be accessed through locahost:8888 or whatever port it has been modified to. I do not have an issue starting or stopping the MAMP server and everything is executable through NetBeans 8.0 when I set a .php file as the index:
So just to be clear, if I have a directory under htdocs (htdocs/foobar/) filled with several .php files I want to be able to view them in the sub-directory of htdocs instead of a blank browser (tested within Chrome and Firefox). I would imagine this is a security setting I am missing in the configuration? How would I enable, for local development, the ability to view all files, directories, and contents VIA the web browser? If it helps or may be an issue I am using NetBeans 8.0 as my IDE for PHP.
Windows:
localhost
-stackoverflow
--foo.php
--bar.php
--humpday.php
Mac:
localhost:8888
-stackoverflow
--empty in browser (chrome or Firefox)
I have searched to see if this a php.ini feature, MAMP 3 documentation has nothing on this, and Netbeans shows nothing per the search.
Ok after much research and the help from Kevbot and Matt Thompson I was able to figure out what to do and it is as followed:
You should enable all hidden files in Mac that are default hidden. To do this open a terminal (Finder > Applications > Utilities > Terminal) I originally referenced this site but it was wrong in regards to showing hidden files for OSX 10.8:
WRONG:
defaults write com.apple.Finder AppleShowAllFiles YES
RIGHT:
defaults write com.apple.finder AppleShowAllFiles YES
After doing so I held down the option + clicking Finder at the same time to prompt Relaunch of Finder.
You will need to navigate to MAMP (in this case MAMP 3.0 non-pro) in the Applications folder to MAMP > conf > apache > httpd.conf.
Open file in a text editor and search for Options Indexes. It was line 202 for me.
Change:
<Directory />
Options Indexes FollowSymLinks
AllowOveride None
</Directory>
TO:
<Directory />
Options Indexes FollowSymLinks
AllowOveride All
</Directory>
Create an .htaccess file in the desired directory and add:
Options +Indexes
IndexOptions +FancyIndexing
Launch/relaunch MAMP. Do note that if you have an index anything (.php, .html. .xhtml, etc. etc.) will show this instead of the directory listing
Actual Answer:
You need to modify the .htaccess file in your root directory.
I was able to get this to work with no issues. In your .htaccess, add the following:
Options +Indexes
IndexOptions +FancyIndexing
DirectoryIndex somethingRandom.html
Here is what each line does:
Line 1 specifies to allow the indexing of files.
Line 2 tells the browser to display more information regarding the files
Line 3 tells the browser the default index file is not index.php or index.html. Just set the file to something that will never exist.
Old Answer:
There are several things you can do to configure MAMP.
You don't have to access MAMP with localhost:8888, you can access it with just localhost with the following changes. If you open the MAMP program, and select:
Preferences
Ports
Set to default Apache and MySQL ports
Then, you can access your server through localhost in the web browser. Also, if you want to switch development folders (using a subfolder of htdocs as it's own site) you can configure those as well. Select the following from the MAMP program window:
Preferences
Apache
Select (a folder inside of htdocs)
Now, when you access localhost in the browser, that folder will be your root folder until you change it back to htdocs.
And just to make sure, did you remember to "Start Servers?"
Hope this helps.

Koala-Framework Website doesn't show first page

I got a question about a special php framework called Koala-Framework.
I've set up an apache2 on my virtual ubuntu OS, added a virtual host reserved only for my first website with this cms, also added the hosts entry and followed the tutorial on http://www.koala-framework.org/about/cms/installation , but if I enter the local domain (in my case the configured kwf-cms-demo.localhost), I'm only redirected to see the folder-structure and not the downloaded demo-website...
Which DocumentRoot the virtual hosts needs to be redirecting? (Because I think this could be the root of this problem...)
PS:
/var/www/kwf-cms-demo$ php bootstrap.php setup returns:
Application seems to be set up already. (update file exists)
so, I think the setup has to be finished without any problem...
Seems Apache isn't starting up the bootstrap.php because the rewrite rules in .htaccess are not honored.
Enable mod_rewrite like that:
sudo a2enmod rewrite
Also see point 5 here:
http://www.koala-framework.org/about/server_requirements/ubuntu_example_configuration

Categories