Basic Website Configuration on a 1&1 Cloud Server with Linux

Table of Contents

Introduction

Learn more about the default website configuration on a 1&1 Cloud Server with Linux, including the locations of useful files and folders and where you can find the Apache configuration and log files. We will also give you advice on organizing multiple domain websites.

Requirements

  • A 1&1 Cloud Server running Linux (CentOS 7 or Ubuntu 16.04) with Apache installed and running.
  • One or more domain names pointed to the server.

For information on how to set up domain name DNS, see the article Initial Setup: Point a Domain to a Cloud Server.

Note: Apache is installed and running on a Standard installation by default. If your server was created with a Minimal installation, you will need to install and configure Apache before you proceed.

The Default Website

The default website on a new server is located at /var/www/html. Any files uploaded to this directory can be seen at the server's IP address. This is also the default website for any URL which is pointed to the server, but which has not been set up in Apache as a virtual host.

For more information on how to set up virtual hosts in Apache so that you can serve multiple websites from the same server, see the article Add an Apache Virtual Host on CentOS 7 and Ubuntu 16.04.

Apache Configuration Files Location

The server's Apache configuration files control all aspects of the websites being hosted on the server, including directory access, file permissions, file locations, and more.

These files are found at:

  • CentOS 7: /etc/httpd/
  • Ubuntu 16.04: etc/apache2

Warning: Editing Apache Configuration Files

When editing the Apache configuration files, a small mistake in syntax can crash the Apache web server. When this happens, the websites hosted on your server will become unreachable, or all URLs may be pointed to the default website.

You can check the syntax of all of the Apache configuration files with the command:

sudo apachectl configtest

This will return any errors, if they are found. For example, consider the following error:

root@localhost:/etc/apache2# apachectl configtest
AH00112: Warning: DocumentRoot [/var/www/example.com/html] does not exist
(2)No such file or directory: AH02291: Cannot access directory '/var/www/example.com/logs/' for error log of vhost defined at /etc/apache2/conf-enabled/example.com.conf:1
AH00014: Configuration check failed
Action 'configtest' failed.
The Apache error log may have more information.

This error reports:

  1. The problem: The DocumentRoot directory /var/www/example.com/html does not exist.
  2. Where the syntax error is found: Line 1 of file /etc/apache2/conf-enabled/example.com.conf.

If a problem occurs, check the main Apache error log. You can view the last 20 lines of the main error log with the command:

  • CentOS 7: tail -20 /var/log/httpd/error.log
  • Ubuntu 16.04: tail -20 /var/log/apache2/error.log

Main Server Apache Log Files Location

The server's Apache log files record visitors and errors on the default website. This is also where many Apache errors are stored, which makes it a valuable tool for troubleshooting Apache problems.

  • CentOS 7: /var/log/httpd
  • Ubuntu 16.04: /var/log/apache2

Organizing Multiple Websites

If you plan to add other websites to a server, it is wise to take a few moments to plan out the file structure first. Apache serves websites from (almost) every directory you choose, but keeping a default file structure makes it easier to work with the sites, and easier to find issues when they occur.

By common convention, hosted websites are stored in directories named after their URL or website name:

/var/www/example.com/
/var/www/my-site/

Each directory contains all of the files relevant to that website, for example:

/var/www/example.com/html
/var/www/example.com/logs
/var/www/example.com/cgi-bin

The standard format for naming the Apache log files is error.log and access.log so these are typically found at:

/var/www/example.com/logs/error.log
/var/www/example.com/logs/access.log

Comments

Tags: InitialSetup / Apache