Development

Apache alias; Map URL to a filesystem location

Apache alias is the method to use the filesystem other than under the document root.

Setting an alias directory with Apache means that when going to the specified URL path it will point to the set directory instead.

This is great when using block storage, as you can avoid putting the webserver onto the slower HDD.

The first step is to edit the Apache config files, Assuming your server has SSL:

sudo nano /etc/apache2/sites-enabled/000-default.conf

sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf

Include the alias, its format is:

Alias [URL path] [Diretory path]

Alias "/images" "/block_storage/images

Put this inside the <VirtualHost *:80> tag in the conf files.

The example above means that when I go to https://serverhostname.com/images it will be loading from /block-storage/images.

Next edit the main Apache configuration file:

sudo nano /etc/apache2/apache2.conf

Add the following in making sure to edit to the location to where your alias is set to

<Directory /block_storage/images/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Now make sure this location has the right permissions for www-data

sudo chown -R www-data:www-data /block_storage/images
sudo chmod -R g+rw /block_storage/images

All that’s left is to restart Apache

sudo systemctl restart apache2

And an Apache alias has been set up.

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago