Freedom, Community & Sustainability

3 - Install your websites and configure Apache

October 25, 2014 -- William
Last modified on September 2017
Duration: +- 30 minutes

Here starts the fun part. Once your server is up and running, it's time to install a website! If you already have a website just transfer the files to the folder /var/www/html using FTP and import your databases using phpMyAdmin. We've covered FTP and phpMyAdmin on the previous section, let me know in the comments if you have trouble doing this.

Install ownCloud (optional)

Since the title of the tutorial said "Cloud", we are going to install ownCloud, an open-source cloud platform that is easy to install and use. If you don't have any website to install you can have just a cool cloud server that will make this tutorial worth while. Follow the short instructions on this page to have it up and running in no time: ownCloud packages

Set ownership of website files and folders

The Apache "default user” is usually set to “www-data”. In order for Apache to be able to handle your sites correctly you should set Apache as the owner of these folders (to avoid permissions problems). You can double check the name of your Apache user typing:

ps aux | grep apache

Then you can set the ownership of your website folders to this user

chown -R www-data:www-data /var/www/html/path/to/website/folder

Configure Apache

If you don't do anything fancy, the default Apache configuration should be ok. If you were able to see the message "It's working" when you enter the IP address of your server in a browser, you are good to go. If not, there are some things you can check before going into a full troubleshooting session.

Check that Apache is running!

sudo service apache2 start

Open the file /etc/apache2/sites-available/000-default.conf and check that the web server is pointing to the correct folder where your site is located:

DocumentRoot /var/www/html/path/to/the/site

Check that the site you are trying to access is enabled:

a2ensite [name_of_site_otherwise_"000-default"]

If you need more help configuring Apache, read our tutorial dedicated to Apache configuration. I recommend reading it anyway because it can give you a broader view of the many tricky aspects of Apache.

Clean URLs

One particular point that I want to stress is the rewriting of URLs, in particular if you are using a CMS to manage your site. CMSs will often want you to enable clean URLs and this is both a configuration of Apache and of your CMS. On the Apache side, you need to enable mod_rewrite:

a2enmod rewrite

If that does not work, check the configuration of your virtualhost. A very permissive insecure way of enabling clean URLs is to include the following lines in /etc/apache2/sites-available/[yoursite].conf. This should make clean URLs work anyway but don't do this on a production server or create other rules in your .htaccess files to protect your folders.

<Directory /var/www/*>
AllowOverride All
Require all granted
Satisfy Any
Allow from all

Add new comment