Apache configuration. Apache: installing and configuring a web server


Professional development always focuses on its own tools - this is a guarantee of reliable and efficient fulfillment of obligations. Own hosting and servers for various purposes in a range of popular configurations expand the scope of tasks solved, increase the security and confidentiality of developments.

Native HTTP: Apache, PHP, MySQL

The Apache web server has been firmly in the lead since the last century, as it provides fast, reliable and safe work. A physical machine and server running Linux or Windows is the foundation, HTTP is the add-on, although essentially it is a data transfer protocol. A Windows machine can be used as a server, but preference is given to the Linux family.

Apache on Windows is local option, used on a single computer to duplicate the development of resources hosted on external servers. Setting to is acceptable, but not very popular. Apache setup on CentOs gives more opportunities and is used to organize servers in local and global networks.

It is believed that Apache servers serve more than 50% of all active web resources, the remaining share comes from similar products from Microsoft, Sun, etc. Actually, the physical server and its operating system can be anything. The HTTP server is installed on a ready-made platform and runs in parallel with other applications on it. Apache is considered native to the entire Linux family, but in each specific case it has its own characteristics.

Freeness, simplicity, and reliability distinguish Linux systems and their applications. It doesn't matter what you use: installing and configuring Apache on Ubuntu is not much different from CentOs, Debian or FreeBSD. The saturation of one or another often plays a role operating system additional software.

The Linux family is small in terms of the number of “relatives” on the line of one or another system kernel. The differences are greater social character- in the sense of developers' attachment to the formulation and implementation of the operating system's capabilities.

In reality, to solve a specific problem of raising hosting, you need to decide on the necessary functionality, required performance, conceptual priorities and a specific choice of Linux representative, or settle on Windows Server.

Shifting local development priorities

Difficult to evaluate the role global network in the development of programming, but it is easy to notice the real shift in the center of gravity: local applications It has become customary to execute as a web resource. Just write a program for local computer- these are drivers, antiviruses, small projects with simple functionality. Programming language... VBA, although C/C++ or C# can be used.

Any information project is a web resource in local network company, which may be partially accessible from the global network, for example, to coordinate the actions of employees outside the office who are on the road or on a business trip.

MySQL, PHP, Apache: setting up for a local application means a completely different dynamic of the application and the required functionality. Modern companies, regardless of size, number of employees and field of activity, are seriously considering Internet programming, both local and global.

At the same time, the local can be distributed: the company’s offices can be located anywhere, but this is not the Internet, but a distributed local network of the company.

MySQL, PHP, Apache setup in local form:

  • easily duplicated across network computers;
  • provides the ability to dynamically change the active component or compare it with a sample to evaluate hacking attempts;
  • gives reason to develop a security system that is free of the risk of being attacked by classical network methods.

Considering that MySQL and Apache in a Windows environment are services, and PHP code is plain text processed by the tool ( PHP interpreter), called in right moment time by an HTTP server, then the level of changeability, mobility and portability of the code will be significantly higher than that of local development tools.

Preparing to install Apache

Back in the era of the “beginning of the beginning,” the operating room Unix system defined unspoken principles of loyalty. Since then, everything that was done on Unix-like systems was automatically translated to other platforms. Setting up Apache on Windows is extremely simple, but solving serious problems will require good qualifications and a detailed understanding of the HTTP server configuration.

First of all, you need to download the latest version of the server (today it is version 2.4.33 dated March 17, 2018) from the official website in zip archive format. It should be borne in mind initially that server versions are numerous and offered on many third-party resources, so it is important to choose an official implementation hosted on a trusted web resource.

Previously, it was popular to install a server using a special installer. Now it is common practice to simply deploy a zip archive. This is simpler and makes it possible to understand the essence of the configuration process, which is very important and subsequently allows you to optimize the server for the required load and functionality.

Editing a Configuration File

The server configuration is determined by a set of configuration files located in the conf folder. Main file Apache configurations- httpd.conf.

In the vast majority of cases, it is necessary to make changes to the main file, clarify the contents of the files responsible for ssl and virtual hosts. Other adjustments are usually made along the way as problems arise or problems are solved. Basically, further settings are related to optimizing the operation of Apache or expanding its capabilities.

To successfully launch the server, it is enough to edit only one line (in order - 38th) - and the Apache setup is complete.

In previous versions of the server configuration, it was necessary to make numerous changes to suit the real situation, but now there is a “universal” SRVROOT variable. You just need to specify its correct value (the path to the server location), and everything will work immediately.

Server placement procedure

The location of the server needs to be considered carefully. Apache itself is interesting, but when it is equipped with PHP and MySQL, it is doubly interesting. It's better when everything related to web development is in one place. You can agree to the default paths, but modern programming is not so ideal in its implementation, so you will have to keep your finger on the pulse clearly and often. In addition, when choosing a convenient location, all initialization and configuration files, as well as logs on the operation of installed products, will be available.

The downloaded official Apache zip archive needs to be deployed in the selected location, placing the tool and the job separately. IN in this example the C:\SCiA folder is a tool (Apache24, PHP, MySQL, ...), and the SCiB folder is the work, in fact, of sites that are created, maintained or modernized.

As a result of the first stage of work, only the subfolders bin, cgi-bin, conf, error, ... with all their contents end up in the C:\SCiA\Apache24 folder.

Editing the hosts file

The second step is to properly configure hosts file- an indication of which IP addresses on a given computer are associated with which names. If only one website is being developed or maintained on a computer, then you don’t have to change anything.

Base IP - 127.0.0.1 usually always points to localhost. The working hosts file is located at c:\Windows\System32\drivers\etc and looks like the one shown below.

To place the hosts file in the right place, you need to use the command line in administrator mode. You can prepare the correct contents of the file anywhere in the computer’s file system, but you can write it to the address c:\Windows\System32\drivers\etc only with a tool that has administrator rights. The easiest way to do this is through the command line.

Installing Apache Server

Nothing could be simpler. Just run the command line as an administrator and go to the C:\SCiA\Apache24 folder. Since this is a Windows path, forward slashes are used. In a specific case, the path may be different. But if you can still somehow experiment with the name of the folder to host the holy trinity - Apache, PHP and MySQL, then changing the folder names for each of them is impractical.

In this case, the server archive is deployed in the C:/SCiA/Apache24 folder, therefore, you need to write the command in the bin folder:

  • httpd.exe -k install

The server will test the configuration file and install itself. Most likely, there will be minor errors, but if you edit the configuration file correctly, then all errors will be insignificant and can be quickly corrected.

Command line window (1) - service installation, window (2) - list of services in which the server has appeared, window (3) - original file index.html, located at C:/SCiB/localhost/www, window (4) - the result of the server.

In this example, an intentional mistake was made: instead of setting the value of the SRVROOT variable, numerous edits were made “the old fashioned way”: everything was changed manually. This is not the most The best decision. Before applying knowledge, you should familiarize yourself with current version product. As a rule, things change quickly, and knowledge should be applied “with skill and understanding of the current situation.”

Practice of deploying a zip archive

Modern websites are not always written using content management systems. There is a lot of manual labor. The problem of transferring the site to another hosting caused good decision- zip archive. We collapsed the content in one place and expanded it in another.

Having an installer is a good practice, but the dynamics of modern information technologies doesn’t give you time to write beautiful installations. Using the installation via zip archive deployment is modern, practical and convenient. In this option, configuring Apache is limited to changing the configuration files.

When installing the server, it is important to specify:

  • Where is he located;
  • where the web resource is located (localhost);
  • using ssl;
  • virtual hosts.

The last position is relevant when the server is supposed to develop or maintain several resources at once. For a real developer, this is a mandatory decision: even if he ensures the operation of one site, it would not be superfluous to have a backup option.

Gentleman's sets

The ease of deploying a zip archive is obvious, Apache (installation and configuration) is just two or three clicks. However, the result when installers were popular was equivalent. The developer simply spent more time developing the next version of his product. Server installation, server language and databases are essentially just collections of files, starting services, a hosts file, and default paths in the operating system's path variable.

The appearance of "Denver" and similar gentleman's development kits was a revolutionary step in the area of ​​simplicity and convenience, but one should not be mistaken. Revolution and programming are absolutely incompatible things. The first is the child of a conflict and its stormy resolution, the second is a serious matter that requires absolute calm, punctuality, accuracy, consistency, attentiveness, safety, and reliability.

Setting up an Apache server is a serious procedure that needs to be treated extremely carefully and everything done so that tomorrow you can change and clarify something.

In most cases, the development of web resources is a fairly lengthy process in which the requirements for services (Apache, PHP, MySQL, ...) change quickly, but there is always time to understand the next task and its optimal solution. But this is not a reason to go along with gentlemen's sets. Time flows, but the gentleman does not change, this is a much more compelling argument than the “Denver” declaration - it is simple, fast and accessible.

Multiple sites - one server

Configuring Apache 2.4 for the sake of one host is an unjustified luxury. Despite the compact design, on the shoulders of this server hangs a huge weight of responsibility for most of the active web resources on the Internet. In addition, not all resources have a representative part and are visible on the network.

The server can be used as a database, as a point of information transfer, as a filter, as a parser, as a working mechanism in a more global information process. As a result of the above, setting up virtual Apache hosts- almost always a mandatory procedure.

One server can support as many web resources as you like; to do this, you need to uncomment line 501 in the httpd.conf file:

  • # Include conf/extra/httpd-vhosts.conf

and describe all the necessary hosts in the file

  • extra\httpd-vhosts.conf.

You may need to clarify which ports and IP the server listens to, but this is a separate topic; for the first time you can limit yourself to what you have.

It should be noted that in the example, for the convenience of describing real virtual web resources (and there are many of them), a variable (DOCROOT) was introduced with the path to the shared folder of all web resources accessible through installed server.

Setting up Apache SSL is available in a similar way. In the httpd.conf file, you just need to leave “as is” lines 524 to 531, which are responsible for the operation of SSL.

The Simplicity and Complexity of Apache

The times when setting up a server was truly a difficult task are long gone. Today, setting up Apache is very simple procedure, which does not require special qualifications from the developer.

Three simple steps:

  • expand archive;
  • change the configuration file;
  • install the server.

As a result, Apache is fully functional. If you do not take into account the subtleties of the process of running a server on maximum load or perform local development on a Windows computer, no additional knowledge is required.

Difficulties may arise on Linux systems. Significantly different understanding of the file system, user and group rights, as well as the organization of the process of interaction with other applications require greater competence and understanding from the developer of how Linux computers work.

Setting up Apache on any Linux system opens up much more possibilities for the developer and gives access to the local network and the Internet. According to established tradition, a Windows computer is a local workstation, and the server is internal. A Linux computer is a local network node or a point in the Internet space.

Professional developer environment

Apache is a fundamental building block of the Internet that can be easily configured, used, and becomes the backbone of a company.

This logic assumes the presence of at least one server on the network on the CentOS, Ubuntu, FreeBSD platform, and Windows workstations. It is optimal to have two Linux servers (main and auxiliary), setting up Apache for a local computer in a Windows environment. When virus attack or an unforeseen situation, the auxiliary server will replace the main one, and the main one will be used for repair and restoration. Replace local installation Apache on a workstation (under Windows) can be downloaded from the archive.

This trivial solution can be refined and supplemented in real practice. The size of a company's information flows can determine the desired configuration and number of servers required. Actually, Apache is designed to work under load, but nothing prevents you from distributing the responsibilities of one server over several. A solution that takes into account the characteristics of a specific company is always more promising than adapting a third-party option.

Apache is the most popular free web server. As of 2016, it is used on 33% of all Internet sites, which is approximately 304 billion sites. This web server was developed back in 1995 as a replacement for the popular NCSA that server and fixed many of its problems. Rumor has it that his name comes from a patchy, as he was fixing NCSA errors. Now, it is a cross-platform program that supports Windows, Linux and MacOS and provides sufficient flexibility, customization and functionality. The program has a modular structure, which allows you to expand its functionality almost indefinitely using modules.

You can install Apache on Linux using a few commands, but the program provides a very large number of settings that can be changed, as well as modules that, when enabled, will work better. This article will cover installing and configuring Apache, we will use Ubuntu as the main system, but you can repeat these steps in any other distribution. We will look at not only installing the program itself, but also how to configure it, setting up apache virtual hosts, as well as the most useful modules.

At the moment, the most a new version programs 2.4; therefore, setting up Apache 2.4 will be considered. As I already said, in Linux program installs in literally a couple of commands. To install on Ubuntu, first update the system to the latest version:

sudo apt update
$ sudo apt upgrade

Then install apache2:

sudo apt install apache2

In other distributions, the program package is called either this or httpd and installing it will not cause you any difficulties.

After installation is complete, you need to add the web server to startup so as not to start it manually after turning on the computer:

sudo systemctl enable apache2

Apache setup

Gone are the days when Apache configuration was stored in a single file. But it’s correct: when everything is distributed in its own directories, it’s easier to navigate the configuration files.

All settings are contained in the /etc/apache/ folder:

  • File /etc/apache2/apache2.conf responsible for basic settings
  • /etc/apache2/conf-available/*- additional web server settings
  • /etc/apache2/mods-available/*- module settings
  • /etc/apache2/sites-available/*- virtual host settings
  • /etc/apache2/ports.conf- ports on which apache runs
  • /etc/apache2/envvars

As you noticed, there are two folders for conf, mods and site. These are available and enabled. When you enable a module or host, a symbolic link is created from the available folder to the enable folder. Therefore, it is better to perform settings in the available folders. Generally speaking, you could do without these folders, take everything and dump everything into one file the old fashioned way, and everything would work, but no one does that now.

First let's look at main file configurations:

vi /eta/apache2/apache2.conf

Timeout- indicates how long the server will try to continue the interrupted transmission or reception of data. 160 seconds will be enough.

Keep Alive On- a very useful parameter, it allows you to transfer several files in one connection, for example, not only the html page, but also images and css files.

MaxKeepAliveRequests 100 - maximum amount requests per connection, the more, the better.

KeepAliveTimeout 5- connection timeout, usually 5-10 seconds are enough to load a page, so you don’t need to set any more, but you also don’t need to break the connection before all the data has loaded.

User, Group- user and group on behalf of which the program will run.

HostnameLookups- record domain names in logs instead of IP addresses, it is better to disable it to speed up work.

LogLevel- level of error logging. By default, warn is used, but to make the logs fill out more slowly, just enable error

Include- all include directives are responsible for connecting the configuration files discussed above.

Directory directives are responsible for setting access rights to a particular directory in the file system. The syntax here is:


Parameter value

The following basic options are available here:

AllowOverride- indicates whether .htaccess files should be read from this directory; these are the same settings files and have the same syntax. All - allow everything, None - do not read these files.

DocumentRoot- sets from which folder documents should be taken to be displayed to the user

Options- indicates which web server features should be allowed in this folder. For example, All - allow everything, FollowSymLinks - follow symbolic links, Indexes - display the contents of the directory if there is no index file.

Require- sets which users have access to this directory. Require all denied - deny everyone, Require all granted - allow everyone. You can use the user or group directive instead of all to explicitly specify the user.

Order- allows you to control access to the directory. Accepts two values: Allow,Deny - allow for everyone except those specified or Deny,Allow - deny for everyone except those specified..ru.

All these directives are not used here, since we are happy with the default values, but in .htaccess files they can be very useful.

We are left with the /etc/apache2/ports.conf file:

It contains only one directive, Listen, which tells the program which port it should work on.

The last file is /etc/apache2/envvars, you are unlikely to use it, it contains variables that can be used in other configuration files.

Setting up an Apache server via htaccess

.htaccess files allow you to configure your Ubuntu web server to behave in a specific directory. All instructions specified in this file are executed as if they were wrapped in a tag if they were in the main file.

It is important to note that in order for the server to read instructions from .htaccess, the settings for this folder in the main or virtual host file must not contain AllowOverride None for all settings to work you need AllowOverride All.

Otherwise, any configuration of the Apache server can be done here, from enabling modules to normal change access to the folder. Since we have already considered all the parameters, let’s just give a couple of examples:

Order Deny,Allow
Deny from all

Denies everyone access to this folder, important to apply for configuration folders. Most often, .htaccess is used to work with the mod_rewrite module, which allows you to change requests on the fly:

RewriteEngine on
RewriteRule ^product/([^/\.]+)/?$ product.php?id=$1 [L]

But this is a very broad topic and is beyond the scope of this article.

Configuring Apache Modules

As I already said, Apache is a modular program, its functionality can be extended using modules. All available loader modules and module configuration files are located in the /etc/apache/mods-available folder. And activated in /etc/apache/mods-enable.

But you don't have to analyze the contents of these folders. Configuring Apache 2.4 by adding modules is done using special teams. You can view all running modules with the command:

You can enable the module with the command:

sudo a2enmod module_name

And disable:

sudo a2dismod module_name

After enabling or disabling modules, you need to restart apache:

sudo systemctl restart apache2

When one of these commands is executed, a symbolic link to a module file with the extension load is created or deleted in the mods-available directory. You can look at the contents of this file, there is only one line. For example:

vi /etc/apache2/mods-available/deflate.load

This means that the module could be activated simply by adding this line to the apache2.conf file. But it is customary to do just that to avoid confusion.

The module settings are located in the same folder, only in a file with the .conf extension instead of load. For example, let's look at the settings of the same module for deflate compression:

vi /etc/apache2/mods-available/deflate.conf

The files in the conf-available folder are the same modules, only they are installed separately from apache, these can be configuration files to enable the php module or any other programming language. Everything works exactly the same here, only the commands for enabling and disabling these modules are slightly different:

a2enconf module_name

a2disconf module name

As you have seen, enabling modules is very simple. Let's enable a few necessary but not enabled by default modules:

sudo a2enmod expires
$ sudo a2enmod headers
$ sudo a2enmod rewrite
$ sudo a2enmod ssl

The expires and headers modules reduce the load on the server. They return a Not Modified header if the document has not changed since the last request. The expiries module allows you to set the time for which the browser should cache the received document. Rewrite allows you to change requested addresses on the fly, very useful when creating CNC links, etc. And the last one to enable support for SSL encryption. Don't forget to restart apache2 after completing the settings.

Configuring Apache Virtual Hosts

It would not be entirely convenient if only one website could be hosted on one physical machine. Apache can support hundreds of sites on a single computer and serve the correct content for each one. Virtual hosts are used for this. The server determines which domain the request is coming to and serves the required content from the folder of this domain.

Apache hosts settings are located in the /etc/apache2/hosts-available/ folder. To create a new host, just create a file with any name (it’s better to end with the host name) and fill it with the necessary data. You need to wrap all these parameters in a directive VirtualHost. In addition to the parameters discussed here, the following will be used:

  • ServerName- primary domain name
  • ServerAlias- additional name by which the site will be accessible
  • ServerAdmin- administrator email
  • DocumentRoot- folder with documents for this domain

For example:

vi /etc/apache2/sites-available/test.site.conf

A web server is a program that runs on a local or remote machine, and its main purpose is to allow the user to view web documents. When the website address is entered in the address bar, when you press the Enter key, the browser generates a request sent to the remote computer - the web server.

Apache HTTP server (short for a patchy server) is one of the most popular and widespread programs created for web developers and Internet resource administrators. According to independent researchers, Apache is installed on 50% of the computers of all HTTP server users.

The main advantages of Apache are stability, speed and flexibility, and they are due to its modular organization, as well as the fact that development is carried out by open group programmers, albeit under the official name Apache Software Foundation.

Apache supports a huge number of operating systems and hardware platforms, and is quite often used under the Windows operating system. It is also important that this web server distributed completely free of charge.

How to install the Apache server for the Windows 7 operating system will be discussed in this article.

Installing Apache

First of all, you need to download the latest version of the Apache distribution without SSL support and run the installation. In the welcome window, you need to click on “ Next", read the developer’s license agreement and confirm your agreement with it.

Then, in the installation window, you need to fill in the fields as shown in the picture below, and in the “ Administrator's Email Address» indicate your address Email, click “Next” and set the switch to the “Custom” position.




Next, you need to create a www directory on drive C and specify it as the installation folder for Apache, click “Next” in this and “Install” in the next window. When the installation is complete, click on “Finish".

If everything went well, the Apache web server management icon should appear in the tray. You can stop and restart it by left-clicking on the icon.

By right-clicking on the same icon, you can go to different system services operating system or open the Apache monitor.

To check if the installed Apache server is running, type http://localhost in the address bar of your browser

If a page appears with the encouraging inscription “It works! ", this means that the Apache installation was successful and it is functioning correctly.

Basic web server setup

Although Apache is very convenient and extremely reliable, not everyone is ready to use it as a local server for a number of reasons, and the main one is the absence, even in the Microsoft Windows environment, of any graphical configurator, which is quite unusual for most users.

The server is configured using manual editing httpd.conf configuration file. However, contrary to ideas about the incomprehensibility and complexity of this process, there is nothing complicated in this operation for two reasons: firstly, in order to make a server out of the newly installed Apache that is configured for an acceptable and comfortable work, you need to change very little data in the configuration file, and secondly, the httpd.conf comments contain a lot of useful information necessary to understand the configuration.

What is necessary?

  • Run Apache under Windows platform 7;
  • Store the files of the future website in a user-friendly directory (for example, C:www);
  • Do not experience problems with encoding, and in particular with the display of the Cyrillic alphabet;
  • Ability to work with several sites simultaneously.

To successfully solve these problems, go to the Apache installation folder, find and open the httpd.conf file in the conf subfolder. Please note that lines starting with “hash” are text comments, and lines that do not have a “hash” icon at the beginning are used as web server settings.

First you need to configure the directory that will be used by the server as the website folder. Find the line in the text that starts with DocumentRoot. This directive determines which folder will be the root.

Correct it to DocumentRoot “C:/www”. It should be clarified that the slashes in this file should be slanted to the right, and not to the left, as you are probably already used to Windows users. After the above manipulations, the problem with the location of your site is solved.

Options (defines which server functions will be available) AllowOverride (defines which directives from .htaccess can override those in httpd.conf) Order (sets certain rules for accessing the server)

List of parameters used:

Options. The following options are possible:

  • Includes – use of SSI allowed;
  • IncludesNOEXEC – use of SSI is allowed with restrictions (#include and #exec are not allowed);
  • Indexes – the use of index files is allowed, and if the URL points to a site directory (for example, www.domain.ru/dir/) in which there is no index file, the contents of this directory will be shown, and if this option is not present, an alert will be issued that access is prohibited;
  • ExecCGI - execution CGI scripts allowed;
  • FollowSymLinks – the server follows the existing symbolic links of the directory (used in Unix systems);
  • SymLinksIfOwnerMatch – the server follows existing directory symbolic links only if the target file has the same owner as the link;
  • All – all of the above together is allowed;
  • None – all of the above together is prohibited;
  • MultiViews – the ability to select specific content and display it depending on browser preferences (even if Options All is enabled. Specified separately).

AllowOverride. Options:

  • AuthConfig – allows you to use directives for authorization;
  • FileInfo – allows the use of directives for working with various types of documents;
  • Indexes – allows the use of directives for working with indexing files;
  • Limit – allows the use of directives to determine access to the host;
  • Options – allows the use of directives to work with certain specific directory functions;
  • All – all of the above together;
  • None – none of the above together.

Order. Options:

  • Deny, Allow – Deny is defined before the Allow directive, access is allowed by default, except for hosts that are specified in the line following Deny from;
  • Allow,Deny – Allow is defined before the Deny directive, access is denied by default, except for hosts that are specified in the line following Allow from;
  • Mutual-failure – access is allowed only to those hosts that are absent in Deny and present in Allow.

Based on the above, try setting up your server. In the httpd.conf file, the default Directory directive exists in two copies - And . The first option should not be touched, so in the second, set the parameters as follows:

Options Indexes FollowSymLinks AllowOverride None Order allow, deny Allow from all

In other words, the following options are selected for the C:/www folder and all its subfolders:

  • Among the possible functionality of the existing server, indexes in directories and navigation through symbolic links are allowed;
  • The possibility of parametric override using .htaccess files is completely absent, however, given that you have full access to the server, it is not relevant - everything can be configured via httpd.conf;
  • Access to the web server is allowed from all hosts.

Now, save the httpd.conf file and restart Apache using Apache Monitor or using the apache –k restart command on the command line. Setting up the site's root folder is complete.

You should check if you did everything correctly. Create a simple web page in the C:www folder, open your browser and enter http://127.0.0.1/your_created_page. The page should open. Otherwise, you must carefully check all changes to the httpd.conf file for correctness.

If the page opens successfully, there is a chance that instead of Cyrillic characters you will see unreadable characters. They can be displayed for two reasons. First, the web server provides your browser that requested the page with a default encoding. Secondly, oddly enough, this encoding is not Cyrillic.

If the notorious Internet Explorer in such cases, it determines the encoding from the page itself, then, for example, Mozilla Firefox and Opera have absolutely no inclination for such actions, and the method of manually setting the encoding in the browser can hardly be called convenient. Therefore, you need to configure Apache to return the required encoding by default.

Find the line in the httpd.conf file that starts with AddDefaultCharset . Most likely, the ISO-8859-1 encoding is indicated there, which does not contain Cyrillic characters. Change ISO-8859-1 to windows-1251, save the file and restart Apache. Now the correct display of the Russian language on your website will work in any browser.

IN Apache server It’s quite easy to set up work with multiple sites. Addresses that can be used for them are 127.0.0.2, 127.0.0.3, etc. In this case, only the default site (127.0.0.1) will be visible on the network, but this is not critical for local work. The section of the httpd.conf file, in which everything necessary for this is configured, is located at the very end and is called VirtualHosts.

Apache is the most used Internet server on Linux systems. Internet servers are used to serve Internet pages upon request from client computers. Clients typically request and view Internet pages using Internet browser applications such as Firefox, Opera, Chromium or Mozilla.

Users enter a uniform resource locator (URL) to identify an Internet server by its fully qualified domain name (FQDN) and the path to the desired resource. For example, to see the home page of the Ubuntu website, the user must enter only the FQDN:

www.ubuntu.com

SymLinksIfOwnerMatch- Follows symbolic links if the target file or directory has the same owner as the link.

httpd settings

This section covers some basic configuration settings service httpd.

LockFile- The LockFile statement sets the path to the lockfile when the server is compiled with the USE_FCNTL_SERIALIZED_ACCEPT or USE_FLOCK_SERIALIZED_ACCEPT option. It must be saved on a local disk. It is worth leaving the default value unless the log directory is located on an NFS share. Otherwise, the original value should be changed to the directory local disk with read permissions only for root.

PidFile- the PidFile instruction sets a file in which the server writes its process ID (pid). This file should only be readable by root. In most cases, this parameter should be left unchanged.

User - User instructions sets the userid used by the server to respond to requests. This setting determines the server's access rights. Any files that are inaccessible to this user will also be inaccessible to visitors to your site. The default user is "www-data".

Group- the Group instruction is similar to the User directive. Group sets the group under which the server will respond to requests. The default value is also "www-data".

Apache2 modules

Apache2 is a modular server. This means that only the most basic functionality is included in the core of the server. Advanced features are available through modules that can be loaded into Apache2. Default basic set modules are included in the server at the compilation stage. If the server is compiled to use dynamically loaded modules, then the modules can be compiled separately and added at any time using the instruction LoadModule. Otherwise Apache2 must be recompiled to add or remove modules.

Ubuntu compiles Apache2 with the ability to load modules dynamically. Configuration directives can be included based on the presence of the corresponding module in the block .

You can install additional Apache2 modules and use them with your Internet server. For example, run the following command in a terminal to install the MySQL authorization module:

Sudo apt-get install libapache2-mod-auth-mysql

Look for additional modules in the /etc/apache2/mods-available directory.

Use the a2enmod utility to enable the module:

Sudo a2enmod auth_mysql sudo service apache2 restart

Similarly, a2dismod will disable the module:

Sudo a2dismod auth_mysql sudo service apache2 restart

Setting up HTTPS

Module mod_ssl adds an important feature for the Apache2 server - the ability to encrypt connections. Therefore, when your browser connects using SSL, the https:// prefix is ​​used at the beginning of the URL in the navigation bar.

Module mod_ssl available in the apache2-common package. Run the following command in a terminal to enable this module:

Sudo a2enmod ssl

The default settings for HTTPS are in the file /etc/apache2/sites-available/default-ssl. For Apache2 to provide HTTPS, key and certificate files are also required. Initial setting up HTTPS uses the certificate and key generated by the ssl-cert package. These are fine for testing, but must be replaced with a certificate that matches your site or server. For information on creating keys and obtaining certificates, see the Certificates section.

To configure Apache2 for HTTPS, enter the following:

Sudo a2ensite default-ssl

The /etc/ssl/certs and /etc/ssl/private directories are used by default. If you installed the certificate and key in other directories, be sure to change the SSLCertificateFile and SSLCertificateKeyFile options accordingly.

With Apache2 now configured to HTTPS, let's restart the service to allow the new settings:

Sudo service apache2 restart

Depending on how you issued your certificate, you may need to enter passphrase when Apache2 starts.

You can access the pages of the secure server by typing https://your_hostname/url/ in the address bar of your browser.

Record Sharing Rights

In order for more than one user to have write access to the same directory, you must grant write access to the group that unites them. The following example grants write permission to the /var/www directory for the group "webmasters".

Sudo chgrp -R webmasters /var/www sudo find /var/www -type d -exec chmod g=rwxs "()" \; sudo find /var/www -type f -exec chmod g=rws "()" \;

If access must be granted to more than one group per directory, use Controlled Access Lists (ACLs).

Apache is the most popular web server on the Internet, serving more than half of active sites.

In this article we will look at common configuration files and basic Apache settings on Ubuntu/Debian system

Note: Apache files differ depending on the distribution, so this article is not suitable for RHEL users.

Installing Apache on Ubuntu/Debian

If the Apache web server is not yet installed, use the commands:

sudo apt-get update
sudo apt-get install apache2

To verify that the installation was successful, open your browser to the IP address of your server. The Apache welcome page should appear on your screen:

It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.

Apache File Hierarchy

In Ubuntu and Debian Apache stores configuration files in the /etc/apache2 folder.

cd /etc/apache2
ls -F
apache2.conf envvars magic mods-enabled/sites-available/
conf.d/ httpd.conf mods-available/ ports.conf sites-enabled/

This folder contains a number of simple text files and subdirectories. The most important of them:

  • apache2.conf: main server configuration file. Almost all configurations can be performed in it.
  • ports.conf: This file specifies the ports that virtual hosts listen on. Check this file when setting up SSL.
  • conf.d/: This directory controls certain aspects of Apache configuration. For example, it is often used to define SSL configuration and standard security policies.
  • sites-available/: This directory stores all available virtual hosts, which determine what content will be served on the site. These hosts are not active.
  • sites-enabled/: This directory defines active virtual hosts. Typically it contains symbolic links to files defined in the sites-available directory.
  • mods-/: These directories work in the same way as sites-available and sites-enabled. They store modules.

As you can see, Apache configurations are not limited to the main configuration file, they are distributed among several files and directories. This configuration structure can be expanded with new files.

Apache configuration file

Basic Apache settings are stored in /etc/apache2/apache2.conf.

This file contains three main sections: Apache global settings, default server settings, and virtual host configurations.

On Ubuntu and Debian, most of the file is dedicated to global settings, and the default server configuration and virtual host settings are handled at the end of the file using the Include directive.

At the end of the file you will find many Include settings. They define modules, add a ports.conf document, certain files from the conf.d/ directory and setting up virtual hosts from the sites-enabled/ directory.

Let's focus on the global settings of the Apache web server.

Apache Global Settings

This section covers important Apache global settings options.

Timeout

By default, this parameter is set to 300. This means that the server has a maximum of 300 seconds to complete each request. In most cases, this value is very large, and it is recommended to reduce it to 30-60 seconds.

KeepAlive

If this setting is On, the server will allow the client to request multiple objects within a single connection. If the parameter is set to Off, then each new request will create an individual connection. This behavior can lead to overload of a site with high traffic.

MaxKeepAliveRequests

This setting allows you to define the maximum number of requests per connection. This allows you to increase Apache performance.

A value of 0 will allow the web server to process an unlimited number of requests within a single connection.

KeepAliveTimeout

This parameter sets the time interval between requests. If the client has not created another request within the specified time. The web server will terminate the connection. If this client subsequently makes a request, the server will create a new connection.

MPM Settings

To find out which modules Apache was compiled with, open a terminal and type:

apache2 -l
Compiled in modules:
core.c
mod_log_config.c
mod_logio.c
prefork.c
http_core.c
mod_so.c

As you can see, in this case the web server is compiled with the prefork.c module and the apache2.conf file.

Virtual Host Configurations

The default virtual host is located in the default file in the sites-available directory.

To get acquainted general format virtual host, open this file:

sudo nano /etc/apache2/sites-available/default

ServerAdmin webmaster@localhost
DocumentRoot /var/www

Options FollowSymLinks
AllowOverride None


Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

. . .

By default, the virtual host processes requests on port 80.

This does not mean that the web server will necessarily process every request on that port. Apache can override configurations.

Top Level Virtual Host Settings

These settings are set in the Virtual Host section and apply to the entire virtual host.

The ServerAdmin parameter specifies the contact email address to use if problems occur on the server. This address can be pasted into the error page. To do this, the ServerSignature parameter (in the /etc/apache2/conf.d/security file) must be set to Email.

The ServerName directive specifies the domain name or IP address of the server. This is a per-virtual host setting that can override the default settings if it matches the ServerName value.

The ServerAlias ​​parameter allows you to add site aliases - alternative names and paths leading to the same content. For example, a domain alias is often set to www.

DocumentRoot specifies the directory in which the web server stores the content of this virtual host. On Ubuntu, the default for this is /var/www.

Directory settings

The virtual host configuration has a special section for configuring the processing of individual file system directories. These settings can also be overridden.

First, the virtual host proposes a set of rules for the / directory (root directory). This section will provide basic virtual host configuration as it relates to all files that are served on the file system.

By default, Ubuntu does not impose any restrictions on file system. Apache recommends adding a few standard access restrictions, for example:


Options FollowSymLinks
AllowOverride None
Order Deny,Allow
Deny from All

This will block access to all content unless subsequent directory definitions indicate otherwise.

The AllowOverride parameter allows you to override configurations using .htaccess files. To override settings, the .htaccess file must be in the content directory. By default this feature is disabled.

Alias ​​and ScriptAlias ​​settings

Sometimes the Alias ​​and ScriptAlias ​​parameters appear before the Directory section.

The Alias ​​directive allows directories outside of DocumentRoot to be added to the content being served.

ScriptAlias ​​works in a similar way, but contains the path to the directories with executable files.

For example, such a line in the virtual host for example.com will allow access to content in the /path/to/content/ directory when requesting example.com/content/.

Alias ​​/content/ /path/to/content/

Remember that when opening access to additional directories, you need to set limited privileges on them.

Enabling Sites and Modules in Apache

Once you have created the virtual host file, you can enable it. To do this, you need to create a symbolic link to a file in the sites-enabled directory:

sudo a2ensite virtualhostfile

Once your site is enabled, restart Apache to allow the web server to re-read the configurations:

sudo service apache2 reload

To disable the virtual host, you need to remove the symbolic link from sites-enabled:

sudo a2dissite virtualhostfile

After this you need to restart the web server again:

sudo service apache2 reload

You can enable or disable the Apache module using following commands(respectively):

a2enmod
a2dismod

They work the same as the previously mentioned a2ensite and a2dissite commands. After enabling or disabling the module, you need to restart the web server.

Conclusion

This article only covers basic settings Apache web server files. Apache's feature set can be greatly expanded using modules.

If you need Additional Information about the web server, please contact







2024 gtavrl.ru.