Syed Jahanzaib Personal Blog to Share Knowledge !

December 27, 2012

Short notes for Ubuntu’s Apache


 

1- Howto Disable DIRECTORY BROWSING in apache2

If you want to disable directory browsing on every folder. edit file

nano /etc/apache2/sites-available/default

and Change the Options

‘Indexes FollowSymLinks MultiViews’
to
‘Options FollowSymLinks MultiViews’

(means Remove the Indexes word).
and restart apcache2 service

service apcahe2 restart


 

OR to Disable Directory Browsing for specific folder in Apache (In Ubuntu its apache2), Remove the following directive from your required folder.

Indexes

For example,  you want to remove directory browsing for /var/www/backup folder.
Edit the below file /etc/apache2/sites-enabled/000-default by using following command

nano /etc/apache2/sites-enabled/000-default

The Default config is below.

Alias /backup /var/www/backup
<Directory /var/www/backup>
DirectoryIndex index.html
Options Includes Indexes FollowSymLinks MultiViews
</Directory>

Change it below

Alias /backup /var/www/backup
<Directory /var/www/backup>
#DirectoryIndex index.html
Options Includes FollowSymLinks MultiViews
</Directory>

Save & Exit , then Restart APACHE Service by

service apache2 restart


2- Howto create Alias/Virtual Folder

To create Alias/VF, for example /var/www/backup
Edit the below file, and add the data as showed below

nano /etc/apache2/sites-enabled/000-default

Alias /backup /var/www/backup
<Directory /var/www/backup>
DirectoryIndex index.html # Change as per requirement
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride None
order allow,deny
allow from all
</Directory>

Save & Exit , then Restart APACHE Service by

service apache2 restart

 


 

3- Howto Password Protect Apache Folder with .htaccess

If you want to password protect specific folder in Apache so un authorized users cannot access it, use the following method. There are other better methods available, You can follow them for best practices. I just did it this way.

First Create password file

htpasswd -c /etc/apache2/passwd zaibtest

(Replace zaibtest with your required username, It will ask you for password, enter password you like to set for user zaibtest. Also you can save this file anywhere you like)

Now protect your required folder, for example I want to protect /var/www/backup folder, then use the following directives in in /etc/apache2/sites-enabled/000-default

nano /etc/apache2/sites-enabled/000-default

Alias /backup /var/www/backup

<Directory /var/www/backup>
#DirectoryIndex user.php
AuthType Basic
AuthName “Please enter valid user password to access Zaib’s Data”
AuthUserFile /etc/apache2/passwd
Require valid-user
Options Includes Indexes FollowSymLinks MultiViews
AllowOverride ALL
order allow,deny
allow from all
</Directory>

Save & Exit , then Restart APACHE Service by

service apache2 restart

Now try to access the folder, it will ask you the password.

asking-password

.
After providing valid id password, you can access your folder. (I use it to download backup data from remote location)

access-granted


 

4- APACHE2 ERROR WHEN RESTART SERVICE

YOU SEE THIS ERROR WHEN RESTART APCAHE2 SERVICE ….


apache2: Could not reliably determine the server’s fully qualified domain name,

 … waiting ..
apache2: Could not reliably determine the server’s fully qualified name

If you see above error whil restarting apach service, To fix that problem, you need to add and directive in the the httpd.conf file. Open the terminal and type,

nano /etc/apache2/httpd.conf

By default httpd.conf file will be blank. Now, simply add the following line to the file.

ServerName localhost

Save & EXIT.

Now restart the server.

service apache2 restart
This time, you will not see any error. 🙂

Howto set default page to other

Open file `etc/apache2/mods-available/dir.conf`

nano /etc/apache2/mods-available/dir.conf

and add your page like

DirectoryIndex admin.php index.html index.cgi index.pl index.php index.xhtml index.htm
Save & restart apache2 service
service apache2 restart
done.

Regard’s
Syed Jahanzaib

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: