Computer literacy, assistance and repair

Configuring Apache. Installing and configuring the Apache server What apache configuration files should not allow

Apache HTTP Server is a complex software product that runs on different platforms and in different operating systems Worldwide. Therefore, for it to work correctly on the installed system, it must be configured.
By default, Apache settings are located in the httpd.conf file in the conf directory. The following will describe the main directives of the httpd.conf file and their commonly used meanings.

Editing the httpd.conf file

1. To load the mod_rewrite module, find and uncomment (remove the “#” symbol at the beginning of the line) this line:
LoadModule rewrite_module modules/mod_rewrite.so
2. To load the PHP interpreter, you need to add the following line to the end of the module loading block:
LoadModule php5_module "C:/php/php5apache2_2.dll"
3. Define the directory containing the PHP configuration file by adding the following line below:
PHPIniDir "C:/php"
4. Find and uncomment the line:
ServerName localhost:80
5. Find the line:
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
Assign the root directory for site management (you already created it a little earlier):
DocumentRoot "C:/apache"
6. Find this block:

Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all

And replace it with the following:

Options Includes Indexes FollowSymLinks
AllowOverride All
Allow from all

7. Delete or comment out the original directory control block (we won't need it), which without comments looks something like this:

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

8. Find the block:

DirectoryIndex index.html

Replace it with:

DirectoryIndex index.html index.htm index.shtml index.php

9. Find the line:
ErrorLog "logs/error.log"
Replace with the following (in this case it will be more convenient to view the global server error file):
ErrorLog "C:/apache/error.log"
10. Find the line:
CustomLog "logs/access.log" common
Change to:
CustomLog "C:/apache/access.log" common
11. For SSI to work (server-side enablement), the following lines are located in the block , you need to find and uncomment:
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
12. Add below, in the same block , two lines:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
13. Finally, find and uncomment the lines:
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-manual.conf
Include conf/extra/httpd-default.conf
Save changes and close the "httpd.conf" file

Now open the file "httpd-vhosts.conf" located in the "conf\extra" directory and make the following changes in it:

The existing virtual host example blocks should be commented out or deleted and the following inserted:

DocumentRoot "C:/apache/localhost/www"
ServerName localhost
ErrorLog "C:/apache/localhost/error.log"
CustomLog "C:/apache/localhost/access.log" common

Example of creating a virtual host

If you need to install your own virtual hosts, do the following:

Open the file "httpd-vhosts.conf" and create a block in it with approximately the following content:

# The folder where your host's root will be.
DocumentRoot "C:/apache/test.ru/www"
# The domain by which you can access the virtual host.
ServerName test.ru
# Alias ​​(additional name) of the domain.
ServerAlias ​​www.test.ru
# The file where errors will be written.
ErrorLog "C:/apache/test.ru/error.log"
# Host access log file.
CustomLog "C:/apache/test.ru/access.log" common

Then in the "apache" directory, create a folder "test.ru" (just like that, with a dot), in which, in turn, create a folder "www".

The next step in creating a virtual host is to modify the C:\WINDOWS\system32\drivers\etc\hosts file of the operating system. Open this file and add two lines to it:
127.0.0.1 test.ru
127.0.0.1 www.test.ru

Now restart the Apache server with the "Restart" shortcut located in the "Start" menu, open the browser, enter test.ru or www.test.ru in the address bar and you will find yourself in your virtual host. Just be careful, now you can get to the original site with the name of the virtual host (www.test.ru if it exists) only by commenting out or deleting the line: 127.0.0.1 www.test.ru, in the above-mentioned "hosts" file.

Apache documentation, with the server running, is available at http://localhost/manual/

Installation and configuration of the Apache web server is completed.

Creating batch files to start and stop services

Agree that manually editing the "hosts" file every time you start services is not convenient, so for a more convenient, simultaneous start of Apache, MySQL services, and changing the "hosts" file, we will create two batch files: for starting and stopping, which will perform all routine work automatically.

When using virtual hosts, you need to create two files in the C:\apache directory: vhosts-off.txt - containing the initial contents of the "hosts" file and vhosts-on.txt - containing all virtual hosts. Please note that when creating new virtual hosts you will need to add them to the vhosts-on.txt file and not to C:\WINDOWS\system32\drivers\etc\hosts. Look at the examples below.

File vhosts-off.txt (can contain one single line):
127.0.0.1 localhost

Example of a vhosts-on.txt file with virtual hosts www.test.ru and test.ru:

127.0.0.1 localhost
127.0.0.1 www.test.ru
127.0.0.1 test.ru

In the same directory C:\apache, create two batch files: start-webserver.bat – to start services and replace the “hosts” file, and stop-webserver.bat – to stop services and clear the “hosts” file.

Launch file start-webserver.bat:

@echo off
echo.
if not exist C:\apache\vhosts-on.txt goto no_vhosts
echo Create virtual hosts:
copy /v /y C:\apache\vhosts-on.txt C:\WINDOWS\system32\drivers\etc\hosts
echo.
:no_vhosts
NET start Apache2.2
NET start MySQL

Stop file stop-webserver.bat:

@echo off
echo.
if not exist C:\apache\vhosts-off.txt goto no_vhosts
echo Restore hosts file:
copy /v /y C:\apache\vhosts-off.txt C:\WINDOWS\system32\drivers\etc\hosts
echo.
:no_vhosts
NET stop Apache2.2
NET stop MySQL

If you do not use virtual hosts or want to start services without replacing the "hosts" file, simply remove the files vhosts-on.txt and vhosts-off.txt from the C:\apache directory.

httpd.conf - Apache server configuration

Apache is configured by placing directives in plain text configuration files. Apache server main configuration file - httpd.conf.
Other configuration files can be added using the Include directive. Any directive can be set in any of these configuration files.
Apache 2.4 is configured with files located in a subdirectory (by default) - conf(C:\Program Files\Apache Software Foundation\Apache2.4\conf\). These are the same files as for configuration on OS Unix, but there are several directives specifically intended for Windows.

The main Apache HTTP 2.4 server configuration file is usually called - httpd.conf.

It contains directives and parameters that control the operation of the Web server, virtual servers, as well as all Apache 2.4 software modules. . Apache is a modular server. This means that only the most basic functionality included in the main server. Extension of functions is available using dynamically loaded modules. Configuration files contain one directive per line. The backslash "\" can be used as the last character on a line to indicate that the directive continues to the next line. There should be no other characters or spaces between the backslash and the end of the line. Directives in configuration files are case insensitive, but directive arguments are often case sensitive. Lines that begin with the "#" character are considered comments, and are ignored. Comments cannot be included on the line after a configuration directive. Empty lines and spaces before the directive are ignored.

Directive is a configuration command that controls one or more aspects of the Apache server's behavior.
Directives placed in the main configuration files apply to the entire server .

To check configuration files for syntax errors, the command is used httpd.exe -t.

When installing Apache 2.4 the following were entered:

In Network Domain - server-apache24.ru
in Server Name - www.server-apache24.ru
in Administrator's Email Adress - [email protected]

Hence, server-apache24.ru- will be the name of the main Apache server site.

The main Apache server site is configured in the file - httpd.conf.

Making changes to the Apache server configuration file - httpd.conf

To access the main Apache server site by domain name - server-apache24.ru, create a directory on the disk - C:\server-apache24.ru

server-apache24.ru

  • C:\server-apache24.ru
    • logs
      • access.log
      • error.log
    • www
      • index.html

directory server-apache24.ru

At the root of the disk C: need to create a directory server-apache24.ru
In him Necessarily there should be folders:
logs with "empty" files access.log And error.log
And
www with file index.html

See the lines in the httpd.conf file -
209 ServerAdmin [email protected]
218 ServerName www.server-apache24.ru:80
243 DocumentRoot "C:/server-apache24.ru/www"
245

httpd.conf - configuring Apache 2.4 server

httpd.conf.
The directives of the main configuration file apply to the entire server

All entries, except those highlighted in red, must be commented out. Lines starting with character "#" - these are comments.

# # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See for detailed information. # In particular, see # # for a discussion of each configuration directive. # # Do NOT simply read the instructions in here without understanding # what they do. They"re here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for many # of the server"s control files begin with " /" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so "logs/access_log" # with ServerRoot set to "/usr/local/apache2" will be interpreted by the # server as " /usr/local/apache2/logs/access_log", whereas "/logs/access_log" # will be interpreted as "/logs/access_log". # # NOTE: Where filenames are specified, you must use forward slashes # instead of backslashes (e.g., "c:/apache" instead of "c:\apache"). # If a drive letter is omitted, the drive on which httpd.exe is located # will be used by default. It is recommended that you always supply # an explicit drive letter in absolute paths to avoid confusion. # # ServerRoot: The top of the directory tree under which the server"s # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non -local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same ServerRoot for multiple httpd daemons, you will need to change at # least PidFile. # ServerRoot "C:/Program Files/Apache Software Foundation/Apache2.4" # # Mutex: Allows you to set the mutex mechanism and mutex file directory # for individual mutexes, or change the global defaults # # Uncomment and change the directory if mutexes are file-based and the default # mutex file directory is not on a local disk or is not appropriate for some # other reason. # # Mutex default:logs # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 80 # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule" lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l") do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so # LoadModule access_compat_module modules/mod_access_compat.so LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule allowmethods_module modules/mod_allowmethods.so LoadModule asis_module modules/mod_asis.so LoadModule auth_basic_module modules/mod_auth_basic.so #LoadModule auth_digest_module modules/mod_auth_digest.so #LoadModule authn _anon_module modules/mod_authn_anon.so LoadModule authn_core_module modules/mod_authn_core. so #LoadModule authn_dbd_module modules/mod_authn_dbd.so #LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_file_module modules/mod_authn_file.so #LoadModule authn_socache_module modules/mod_authn_socache.so #LoadModule auth nz_ldap_module modules/mod_authnz_ldap.so LoadModule authz_core_module modules/mod_authz_core.so #LoadModule authz_dbd_module modules/mod_authz_dbd.so #LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_host_module modules/mod_authz_host.so #LoadModule authz_owner_module modules/mod_authz_owner.so Load Module authz_user_module modules/mod_authz_user.so LoadModule autoindex_module modules/mod_autoindex.so # LoadModule buffer_module modules/mod_buffer.so #LoadModule cache_module modules/mod_cache.so #LoadModule cache_disk_module modules/mod_cache_disk.so #LoadModule cern_meta_module modules/mod_cern_meta.so LoadModule cgi_module modules/mod_cgi.so #LoadModule charset_lite_module modules /mod_charset_lite.so #LoadModule data_module modules /mod_data.so #LoadModule dav_module modules/mod_dav.so #LoadModule dav_fs_module modules/mod_dav_fs.so #LoadModule dav_lock_module modules/mod_dav_lock.so #LoadModule dbd_module modules/mod_dbd.so #LoadModule deflate_module modules/mod_deflate.so LoadModule di r_module modules/mod_dir. so #LoadModule dumpio_module modules/mod_dumpio.so LoadModule env_module modules/mod_env.so #LoadModule expires_module modules/mod_expires.so #LoadModule ext_filter_module modules/mod_ext_filter.so #LoadModule file_cache_module modules/mod_file_cache.so #LoadModule filter_module modules /mod_filter.so #LoadModule headers_module modules/mod_headers.so #LoadModule heartbeat_module modules/mod_heartbeat.so #LoadModule heartmonitor_module modules/mod_heartmonitor.so #LoadModule ident_module modules/mod_ident.so LoadModule imagemap_module modules/mod_imagemap.so LoadModule include_module modules/mod_include.so #LoadModule info_module module s/mod_info .so LoadModule isapi_module modules/mod_isapi.so #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_by traffic.so #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so #LoadModule ldap_module modules/mod_ldap.so # LoadModule logio_module modules/mod_logio.so LoadModule log_config_module modules/mod_log_config.so #LoadModule log_debug_module modules/mod_log_debug.so #LoadModule log_forensic_module modules/mod_log_forensic.so #LoadModule lua_module modules/mod_lua.so LoadModule mime_module modules/ mod_mime.so #LoadModule mime_magic_module modules/ mod_mime_magic.so LoadModule negotiation_module modules/mod_negotiation.so #LoadModule proxy_module modules/mod_proxy.so #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so #LoadModule proxy_connect_module modules/mod_proxy_connect.so #Lo adModule proxy_express_module modules/mod_proxy_express.so #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so #LoadModule proxy_html_module modules/mod_proxy_html.so #LoadModule proxy_http_module modules/mod_proxy_http.so #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so # LoadModule ratelimit_module modules/mod_ratelimit.so #LoadModule reflector_module modules/mod_reflector.so #LoadModule remoteip_module modules/mod_remoteip.so #LoadModule request_module modules/mod_request.so #LoadModule reqtimeout_module modules/mod_reqtimeout.so #LoadModule rewrite_module modules/mod_rewrite.so #LoadModule sed_module modules/mod_sed.so #Load Module session_module modules /mod_session.so #LoadModule session_cookie_module modules/mod_session_cookie.so #LoadModule session_crypto_module modules/mod_session_crypto.so #LoadModule session_dbd_module modules/mod_session_dbd.so LoadModule setenvif_module modules/mod_setenvif.so #LoadModule slotmem_plain _module modules/mod_slotmem_plain.so #LoadModule slotmem_shm_module modules/mod_slotmem_shm. so #LoadModule socache_dbm_module modules/mod_socache_dbm.so #LoadModule socache_memcache_module modules/mod_socache_memcache.so #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #LoadModule speling_module [email protected]#ServerAdmin [email protected] # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName www.server-apache24.ru:80 # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # blocks below. # AllowOverride none Require all denied # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something"s not working as # you might expect, make sure that you have specifically enabled it # below. # # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # # DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.4/htdocs" was DocumentRoot "C:/server-apache24.ru/www" # was # # Possible values ​​for the Options directive are "None", "All", # or any combination of : # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # //httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # # Options Indexes FollowSymLinks was Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # # AllowOverride None was AllowOverride All # # Controls who can get stuff from this server. # Require all granted AddHandler server-parsed .shtml .shtm .html .htm # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # DirectoryIndex index.html # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # Require all denied # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a # container, that host"s errors will be logged there and not here. # # ErrorLog "logs/error.log" was ErrorLog c:/server-apache24.ru/logs/error.log # # LogLevel: Control the number of messages logged to the error_log. # Possible values ​​include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%(Referer)i\" \"%(User-Agent)i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %> s %b \"%(Referer)i\" \"%(User-Agent)i\" %I %O" combinedio # # The location and format of the access logfile (Common Logfile Format). # If you do not define any access logfiles within a # container, they will be logged here. Contrariwise, if you *do* # define per- access logfiles, transactions will be # logged therein and *not* in this file. # # CustomLog "logs/access.log" common was CustomLog c:/server-apache24.ru/logs/access.log common # # If you prefer a logfile with access, agent, and referer information # (Combined Logfile Format) you can use the following directive. # #CustomLog "logs/access.log" combined # # Redirect: Allows you to tell clients about documents that used to # exist in your server"s namespace, but do not anymore. The client # will make a new request for the document at its new location. # Example: # Redirect permanent /foo //www.server-apache24.ru/bar # # Alias: Maps web paths into filesystem paths and is used to # access content that does not live under the DocumentRoot. # Example: # Alias ​​/webpath /full/filesystem/path # # If you include a trailing / on /webpath then the server will # require it to be present in the URL. You will also likely # need to provide a section to allow access to # the filesystem path. # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias ​​# directives as to Alias. # # ScriptAlias ​​/cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.4/cgi-bin/" was ScriptAlias ​​/cgi-bin/ "C:/server-apache24.ru/cgi-bin/" # # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # #Scriptsock cgisock # # "C:/Program Files/Apache Software Foundation/Apache2.4/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # # AllowOverride None Options None Require all granted # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig conf/mime.types # # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress . Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php # # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi AddHandler cgi-script .cgi .pl # For type maps (negotiated resources): #AddHandler type-map var # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # AddType text/html .shtml AddOutputFilter INCLUDES .shtml # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # #MIMEMagicFile conf/magic # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 //www.server-apache24.ru/subscription_info.html ErrorDocument 404 C:/server-apache24.ru/www/404error .html ErrorDocument 500 C:/server-apache24.ru/www/500error.html # # MaxRanges: Maximum number of Ranges in a request before # returning the entire resource, or one of the special # values ​​"default", "none" or "unlimited". # Default setting is to accept 200 Ranges. #MaxRanges unlimited # # EnableMMAP and EnableSendfile: On systems that support it, # memory-mapping or the sendfile syscall may be used to deliver # files. This usually improves server performance, but must # be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise # broken on your system. # Defaults: EnableMMAP On, EnableSendfile Off # #EnableMMAP off #EnableSendfile on # Supplemental configuration # # The configuration files in the conf/extra/ directory can be # included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as # necessary. # Server-pool management (MPM specific) #Include conf/extra/httpd-mpm.conf # Multi-language error messages Include conf/extra/httpd-multilang-errordoc.conf # Fancy directory listings Include conf/extra/httpd-autoindex .conf # Language settings Include conf/extra/httpd-languages.conf # User home directories Include conf/extra/httpd-userdir.conf # Real-time info on requests and configuration #Include conf/extra/httpd-info.conf # Virtual hosts Include conf/extra/httpd-vhosts.conf # Local access to the Apache HTTP Server Manual #Include conf/extra/httpd-manual.conf # Distributed authoring and versioning (WebDAV) #Include conf/extra/httpd-dav. conf # Various default settings Include conf/extra/httpd-default.conf # Configure mod_proxy_html to understand HTML4/XHTML1 Include conf/extra/proxy-html.conf # Secure (SSL/TLS) connections #Include conf/extra/httpd-ssl .conf # # Note: The following must be present to support # starting without SSL on platforms with no /dev/random equivalent # but a statically compiled-in mod_ssl. # SSLRandomSeed startup builtin SSLRandomSeed connect builtin # # uncomment out the below to deal with user agents that deliberately # violate open standards by misusing DNT (DNT *must* be a specific # end-user choice) # # #BrowserMatch "MSIE 10.0;" bad_DNT # # #RequestHeader unset DNT env=bad_DNT #


Changes .
Team - httpd.exe -k restart, allows any operations the Apache server is performing to complete and forces Apache to re-read the configuration file.


Troubleshooting errors when installing Apache server

Apache comes with a utility called Apache Service Monitor. With it, you can see and manage the status of all installed Apache services on any computer on the network.

Restarting Apache 2.4

Because changes in the main configuration files will only take effect when the Apache server is started or rebooted,
you need to restart the server.

ApacheMonitor

The ApacheMonitor icon can be seen by clicking on the button - show hidden icons

Double left click on the icon Apache Service Monitor.

You can restart the Apache server by clicking the button Restart
in the Apache Service Monitor window.
Or - Stop and then - Start.

If you only made changes to the httpd.conf file,

then entering in address bar browser - localhost or - 127.0.0.1 ,
you will see a page - Error 403.

Access forbidden!

You don"t have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.

Error 403

127.0.0.1
Apache/2.4.4 (Win64)

Access is denied!

You do not have permission to access the requested directory. There is no index document or the catalog is read-protected.
If you think this is a server error, please contact your webmaster.

Error 403

Login with administrator rights to the command line - Administrator - Command Line
and enter:
"C:\Program Files\Apache Software Foundation\Apache2.4\bin\httpd.exe" 2> C:\errapache.txt

Microsoft Windows (c) 2016 Microsoft Corporation. All rights reserved. C:\Windows\system32> "C:\Program Files\Apache Software Foundation\Apache2.4\bin\httpd.exe" 2> C:\errapache.txt C:\Windows\system32>

On disk C:/ a file will be created errapache.txt


AH00112: Warning: DocumentRoot does not exist AH00112: Warning: DocumentRoot does not exist (OS 10048) Typically only one use of a socket address (protocol/network address/port) is allowed. : AH00072: make_sock: could not bind to address [::]:80 (OS 10048) Typically only one use of a socket address (protocol/network address/port) is allowed. : AH00072: make_sock: could not bind to address 0.0.0.0:80 AH00451: no listening sockets available, shutting down AH00015: Unable to open logs

AH00112: Warning:
C:/Program Files/Apache Software Foundation/Apache2.4/docs/dummy-host.server-apache24.ru
C:/Program Files/Apache Software Foundation/Apache2.4/docs/dummy-host2.server-apache24.ru
They don't exist.

But the main thing is OS errors 10048:

Could not bind to address [::]:80
could not bind to address 0.0.0.0:80

Go to the command line and enter:
netstat -aon

Administrator: Command Line

Microsoft Windows (c) 2016 Microsoft Corporation. All rights reserved. C:\Windows\system32> netstat -aon Active connections Name Local address External address PID status TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 1612 TCP [::]:80 [::]:0 LISTENING 1612 TCP 127.0.0.1:49693 127.0.0.1:49694 ESTABLISHED 5612 TCP 127.0.0.1:49694 127.0.0.1:49693 ESTABLISHED 5612 TCP 127.0.0.1:51341 0.0.0.0:0 LISTENING 3920 TCP 127.0.0.1:52006 0.0.0.0:0 LISTENING 3708 TCP 19 2.168.0.100:139 0.0.0.0:0 LISTENING 4 TCP 192.168.0.100:51330 34.226.135.28:443 ESTABLISHED 1232 TCP 192.168.0.100:51345 52.196.85.70:443 ESTABLISHED 1232 TCP 192.168.0.100: 52796 88.212.253.127:21 ESTABLISHED 1128 TCP 192.168.0.100:53160 151.101.112.134 :443 CLOSE_WAIT 3712 TCP 192.168.0.100:53161 151.101.112.134:443 CLOSE_WAIT 3712 TCP 192.168.0.100:53162 151.101.128.134:443 CLOSE_WAIT 3712 TCP 192.168.0.100:53176 151.101.112.134:443 ESTABLISHED 3712 TCP 192.168.0.100:53179 151.101 .128.233:443 CLOSE_WAIT 3712 TCP 192.168.0.100:53192 151.101.112.64:443 CLOSE_WAIT 3712 TCP 192.168.0.100:53223 23.61.217.175:443 CLOSE_WAIT 3 712 TCP 192.168.0.100:53230 185.29.133.52:443 CLOSE_WAIT 3712 TCP 192.168.0.100: 53246 2.18.74.149:443 CLOSE_WAIT 3712 TCP 192.168.0.100:53271 52.205.235.141:443 ESTABLISHED 5236 C:\Windows\system32>

The Process ID, better known as the PID, is a unique number. Each process running on the system has a unique identifier.
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 1612
TCP [::]:80 [::]:0 LISTENING 1612

Open Task Manager

Only Apache2.4 service has PID - 1612

In the catalog C:/Program Files/Apache Software Foundation/Apache2.4/conf/extra/
open the file in Notepad - httpd-vhosts.conf

Before making any changes, do backup copy file - httpd-vhosts.conf.

Replace in VirtualHost sections
on

httpd-vhosts.conf - contents of the Apache 2.4 server configuration file

# Virtual Hosts # # Required modules: mod_log_config # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at #

In the catalog C:\Windows\System32\drivers\etc\
open the file in Notepad - hosts
And add the line to it:

127.0.0.1 localhost www.server-apache24.ru server-apache24.ru

Restart the Apache server by clicking the button Restart
in Apache Service Monitor.

Enter into the address bar of your browser - server-apache24.ru
and you will see the index page of the main website of the Apache2.4 server that you created

The site index page should be located in the www subdirectory (C:\server-apache24.ru\www\)

After installing Apache 2.4 server, go to the command line and enter the commands:

httpd.exe -t

You will receive two warnings.

Administrator: Command Line

Microsoft Windows (c) 2016 Microsoft Corporation. All rights reserved. C:\Windows\system32> cd C:\Program Files\Apache Software Foundation\Apache2.4\bin\ C:\Program Files\Apache Software Foundation\Apache2.4\bin> httpd.exe -t AH00112: Warning: DocumentRoot does not exist AH00112: Warning: DocumentRoot does not exist Syntax OK C:\Program Files\Apache Software Foundation\Apache2.4\bin>

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 the range of popular configurations, they expand the scope of tasks to be 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 secure operation. 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 a local option used on a single machine to duplicate the development of resources hosted on external servers. Setting to is acceptable, but not very popular. Configuring Apache on CentOs gives more options and is used to organize servers on 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 a particular operating system with additional software often plays a role.

The Linux family is small in terms of the number of “relatives” on the line of one or another system kernel. The differences are more of a social nature - 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 choose Windows Server.

Shifting local development priorities

It is difficult to assess the role of the global network in the development of programming, but it is easy to notice a real shift in the center of gravity: local applications have become customary to run as a web resource. It’s easy to write a program for a local computer - these include 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.

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

Preparing to install Apache

Back in the era of the “beginning of beginnings,” the Unix operating 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 latest version 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. Apache's main configuration file is 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. Because this is the way to Windows system, then 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 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.

Window (1) command line- installation of the service, window (2) - list of services in which the server was declared, window (3) - source file index.html, located at C:/SCiB/localhost/www, window (4) - 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 best solution. Before applying the knowledge, you should familiarize yourself with the current version of the 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 a site to another hosting provided a good solution - a 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. Installing the server, server language and database is essentially just a collection of files, starting services, a hosts file and default paths in the operating system 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 its compact design, this server bears 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 Apache virtual hosts is 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 the 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 a very simple procedure that 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 intricacies of the process of running a server at maximum load or perform local development on a Windows computer, no additional knowledge is required.

Difficulties may arise on Linux systems. Significantly different ideas about file system, user and group rights, as well as organizing 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. In the event of a 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 needed. 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.

Concepts: configuration, directives. Configuration files, directives. Basic configuration directives. Server processes. Control access to directories and files.

Configuration (Latin configuratio - mutual arrangement) is a special logical and methodological technique, a mental technique for synthesizing knowledge of different subjects, different ideas about the same object.

Directives, g. (from Latin directio - direction). General guidance given by a superior authority to a subordinate (workstation server, etc.) .

Configuration file is a file with a fairly simple format. Each line represents a keyword and one or more arguments. For simplicity, most lines contain only one argument. Anything following the # symbol is a comment and is ignored.

Apache is configured by changing service files in the /etc/httpd/conf/ directory. The main configuration file of the web server is httpd.conf. Configuration directives can be placed in various files, which include file_name.conf in the main Include construct.

If the location of a file or directory is specified implicitly in the configuration file (explicit location begins at the root of the file system - with the "/" character), Apache uses the directory specified in the ServerRoot directive to determine the actual location of the target.

Description of Apache modules and configuration directives

Directives can be used at the following levels:

A server configuration level - the directive can only be used in the main configuration file.

Level V - the directive can be used differently for different virtual hosts.

D level - for any directory, you can set your own settings using a directive of this level.

H level of .htaccess files - the directive is allowed to be used in .htaccess files in places where they are allowed by the server.

At any point, the use of the filename parameter in the directive specifies an absolute (starting with "/") or relative path to the file from the ServerRoot directory.

CORE - web server core (Apache core module)

AccessConfig filename

Sets the location of the configuration file. The default system configuration file is conf/access.conf; To cancel reading this file, it is recommended to set /dev/null.

AccessFileName file file ...

Sets the names of the access files used to configure on-the-fly configuration by default - .htaccess.

AddModule module module ... [A]

Activates a dynamically loaded module supplied as a separate library file.

AddModule module module ...

Activates a dynamically loaded module, supplied as a separate library file or compiled inside the main httpd module.

AllowOverride param param ...

Sets the rules by which Apache uses directives in internal .htaccess files;

None - ignores;

All - uses all directives;

Options - allows the use of Options and XBitHack;

Indexes - directory indexing management directives;

FileInfo - directives for managing file types and their handlers;

AuthConfig - directives for accessing Auth* directories;

Limit - allow/deny/order directives.

AuthName realm

AuthType type

Used to specify a method for requesting and transmitting a username and password to access website directories. Most often they use Basic, less often - Digest and others.

BindAddress address [A]

Specifies the address at which Apache will accept connections. You can use hostname, IP address or *.

ClearModuleList[A]

The directive clears the list of loaded modules. After this directive, you need to use AddModule directives to work with the necessary modules.

ContentDigest on|off

Enables or disables MD5 data hash forwarding. It is calculated for all transmitted pages and is not cached.

CoreDumpDirectory dirname [A]

Points Apache to the directory in which memory dump files (core) created in case of emergency errors will be saved.

DefaultType mimetype

Sets the MIME type sent to clients if Apache cannot determine the type via the mime.types file or AddType directives. Default is set to text/plain.

...

Combines a group of directives that specify Apache's behavior when accessing documents located in a given directory. It is allowed to use name masks - symbols *, ? according to shell rules. If a mask is used, a tilde ~ is placed in front of the name.

...

Defines a group of directories specified by a regular expression and sets the rules for Apache to work with directories and files in this group.

DocumentRoot dirname

Indicates to the server the location of the root of the directory tree below which is the web server's data structure.

ErrorDocument filename|string|URL

In case of an error, it redirects to the specified pages. You can also set a comment to the situation that has arisen, which should begin with a single quotation mark. Example:

ErrorDocument 500 http://foo.example.com/cgi-bin/tester

ErrorDocument 404 /cgi-bin/bad_urls.pl

ErrorDocument 401 /subscription_info.html

ErrorDocument 403 "Sorry can"t allow you access today"

ErrorLog filename

Error log file name. If the parameter line begins with (/), then the path to the file must be specified from ServerRoot; if it begins with (|), then error messages are passed to the specified command on standard input. In particular, in this way, for example, you can implement saving the log directly in the SQL DBMS or save them immediately compressed, transferring, for example, to gzip. Apache versions 1.3 and later output messages to syslog by default if the system supports this feature; but this can be disabled using syslog:facility.

...

File access control. Sections are processed in the same order as in the configuration file, after the directive sections have been read and .htaccess files, but before the directory sections are read . The argument must contain the file name or a mask containing "?" - any character, "*" - any string. With the additional ~ symbol, extended regs can be used. expressions (see REGULAR EXPRESSIONS section in grep(1)) For example: will correspond to commonly used graphic files on the Internet.

...

Same as , but uses regular expressions.

It only relates to starting Apache and forking processes in the environment and with the rights corresponding to the given name.

HostNameLookups on|off|double

Controls the ability to determine the visitor's hostname using reverse DNS. It works slowly and is considered disabled by default. Double indicates that the host name should be subject to additional checking to ensure that the name matches the IP address of the host that sent the request.

IdentityCheck on|off

Enable RFC1413 authentication. Enabling the function will significantly increase the server access time.

...

And should only be executed if this option is defined in Apache internal structures. The [!] sign preceding a parameter indicates that the directive block will be read only if the parameter is not defined.

...

Indicates that directives placed inside a block formed by a pair of directives And should only be executed if this module is compiled in Apache. The [!] sign preceding the module indicates that the directive block will be read only if the parameter is not defined.

Include filename [A]

The directive allows you to include configuration files in the server configuration.

KeepAlive on|off [A]

Allows a client to request multiple files sequentially without breaking the TCP connection.

KeepAliveTimeout sec [A]

Specifies the time (in seconds) before the TCP connection is closed that Apache will wait for the next request from the client.

...

Allows you to specify which HTTP method (for example GET or POST) the contents placed inside belong to. ... access restriction commands.

The following methods can be used: GET, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK.

Listen port [A]

Forces Apache to listen to the specified addresses and ports. For example, to force the server to listen on ports 80 and 8000, use:

To make Apache run on different interfaces with specified port numbers, use:

Listen 192.170.2.1:80

Listen 192.170.2.5:8000

ListenBacklog length [A]

The maximum length of the connection processing queue.

...

Details in apache-manual :)

...

Details in apache-manual

Lockfile filename [A]

The directive sets the path to the lockfile.

LogLevel emerg|alert|crit|error|warn|notice|info|debug

Sets the level of information content of the protocol (log file of the server operation). Using at least crit level is recommended.

MaxClients count [A]

The directive sets a limit on the number of simultaneous requests to the server. In fact, this number cannot exceed the number of child processes of the server, which by default cannot be more than 256. To correct the situation, edit HARD_SERVER_LIMIT in httpd.h and compile it.

MaxKeepAliveRequest count [A]

Allows the client to sequentially request the specified number of files without breaking the TCP connection if KeepAlive is enabled. If the parameter is set to 0, then Apache will only close the connection based on the KeepAliveTimeout parameter.

MaxRequestsPerChild count [A]

The directive sets a limit on the number of requests that an individual child process can handle. If MaxRequestsPerChild is set to 0, the number of requests is unlimited.

MaxSpareServers count [A]

The directive sets the desired maximum number of inactive server processes. The directive is useless if the Microsoft Windows version of Apache is used.

MinSpareServers count [A]

The directive sets the desired minimum number of inactive server processes. The directive is useless if the Microsoft Windows version of Apache is used.

NameVirtualHost port [A]

Indicates that requests to this port-name should be separated by the name of the host being accessed (the HTTP "Host:" header). Allows you to define multiple virtual hosts for one IP address.

Options param param...

Defines Apache action settings for the specified content. All possible settings are described in detail in the apache-manual. Frequently used: Indexes - turns on displaying the contents of the directory if the index file is not found in it (DirectoryIndex directive); ExecCGI - enables the ability to place executable files (cgi, perl scripts) in this directory; Includes - enables the ability to place files in the SSI directory. Each setting is supported by the corresponding module that uses it and may not work if the required module is not loaded. Each Options directive is considered to be in addition to the already known Options defined for the parent directories. Each setting can be prefixed with + or - to enable or disable it in a given context.

PidFile filename [A]

The directive sets the name of the file in which the server writes the process identifier.

Specifies the Apache port - a number from 0 to 65535 (note that some ports may be used by other protocols, see /etc/servises). The standard port for the http protocol is 80.

require userid|groupid|valid-user|file-owner|group-owner [A]

Determines which users have access to the directory.

Require user userid - only these users have access

Require group group-name [group-name] - all users of these groups

Require valid-user - all valid users.

ResourceConfig filename [A]

The server reads further directives from this file after reading httpd.conf. The file name is set relative to ServerRoot. Can be disabled: ResourceConfig /dev/null

RLimitCPU max|sec[ max|sec] [A]

RLimitMEM max|bytes[ max|bytes] [A]

RLimitNPROC max|count[ max|count] [A]

Satisfy any|all [A]

Defines the access policy if Allow and Require are used simultaneously. Used when access to the area is limited by name/password and client address. In this case, the default ("all") requires the client to be verified at the address and enter the correct username and password. In the case of the "any" parameter, the client will gain access if he entered the correct name and password or passed the host restriction. Can be used to restrict access through a password, but allow clients from a specific address without a password.

ScoreBoardFile filename [A]

The directive is required to specify the file name used by the server for communication between child and mother processes. You can find out if this file is required by running Apache and seeing if it creates a file with the given name. If yes, then you need to make sure that it is used by only one copy of Apache.

SendBufferSize bytes [A]

Sets the TCP buffer size.

ServerAdmin email

Sets the email address that the server shows to the client in error messages.

ServerAlias ​​hostname

Specifies an alternative virtual host name.

ServerName hostname

The directive sets the server name; used in link creation. If a name is not specified, the server will try to obtain it from its own IP address.

ServerPath path

The directive sets the legacy pathname for the host.

ServerRoot path [A]

Sets the directory where the server lives. Typically contains conf/ and logs/ subdirectories. Paths for other configuration files are built relative to this directory.

ServerSignature on|ff|mail

Configures the line at the bottom of the server-generated document. Disabled by default, On - shows the server version and ServerName of the virtual host, Email adds a mailto: link to ServerAdmin

ServerTokens Minimal|OS|Full [A]

Controls the header sent to the client by the server describing the server OS and compiled modules.

ServerType standalone|inetd [A]

Determines how the server is started by the system. inetd - runs from the inetd system process. standalone - like a daemon process.

StartServers count [A]

Sets the number of child processes created at startup. The number changes dynamically depending on the load anyway, there is usually no reason to change this setting.

The time that Apache will wait for: receiving a GET request, receiving TCP packets on POST and PUT requests, pause between ACKs when transmitting TCP packets in responses.

UseCanonicalName on|off

Causes Apache to generate the names of the pages it creates using the SERVER_NAME values ​​with SERVER_PORT.

User username

Sets the userid by which the server will respond to requests. To use the directive, the server must be running as root.

...[A]

Directives placed inside a block formed by a pair of directives And I determine the configuration of a given virtual host. Each virtual host must have a unique IP address, port number, or hostname. It makes sense to use this directive if, for example, the server has a network interface for the internal network and another interface for the external network.

mod_env - sets and passes variables for processing in CGI/SSI files

PassEnv variable[ variable] ...

Passes an environment variable (eg HOME) to handlers.

SetEnv variable value

Writes the specified value to the specified environment variable.

UnsetEnv variable[ variable] ...

Resets a variable, making it impossible to read it from handlers.

mod_setenvif - uses conditional expressions to set environment variables

BrowserMatch regex env-variable[=value] ] ... [A]

Uses the passed regular expression as a filter for the User-Agent header from the client browser. On a successful hit, initializes the variable with the given value. If only the variable name is specified, it is initialized with the number 1. If a variable is specified with a preceding "!" - the variable is reset.

BrowserMatchNoCase regex env-variable[=value] ] ... [A]

Acts similarly to BrowserMatch, allowing for differences in character case between the passed User-Agent value and the regular expression used as a filter.

SetEnvIf attribute regex env-variable[=value] ] ... [A]

The action performed by the directive is completely similar to BrowserMatch, but instead of User-Agent any other header can be used: Remote_Host; Remote_Addr; Remote_User; Request_Method; Request_URI; Referrer

SetEnvIfNoCase attribute regex env-variable[=value] ] ... [A]

The difference from SetEnvIf is the same as that of BrowserMatchNoCase from BrowserMatch above.

mod_unique_id - generating a unique environment variable UNIQUE_ID

The variable is generated randomly from the server's IP address, the number of the running process, timestamps and additional internal counters.

The variable is intended for use in compound documents when it is not possible to track the same request using other methods.

mod_mime - designed to determine the mime type of a file when transferring it to the client

AddCharset charset extension ...

For the specified file extensions, tells Apache to pass this charset when responding to the client.

AddEncoding MIME-enc extension ...

For the specified file extensions, tells Apache to transfer the file using the desired MIME encoding.

AddHandler handler-name extension ...

Tells Apache that files with given extensions should be passed to a specific handler. The handler can be either internal (cgi-script and others) or external, described earlier by the Action directive.

AddLanguage MIME-lang extension ...

Establishes a relationship between file extensions and the language code sent in the response.

AddType MIME-type extension ...

Updates the MIME type table with a new mapping of file extensions and MIME code for the response to the client.

DefaultLanguage MIME-lang

Sets the response language to always be sent if this cannot be done by other means.

ForceType MIME-type

Forces a response with the given MIME type in the directory to which the given directive is assigned.

RemoveEncoding extension ...

Removes the MIME encoding code in the response for files with these extensions.

RemoveHandler extension ...

Tells Apache not to run handlers for files with these extensions.

RemoveType extension ...

Resets the MIME type in the response to the client to the default MIME type

SetHandler handler

Forces the call of this handler for all files to which this directive is assigned.

TypesConfig filename [A]

Specifies the location of the MIME type mapping table. Default - conf.mime.types

mod_mime_magic - a module that uses complex rules to determine the MIME type of the file sent in the response

MimeMagicFile filename

Activates a module action using the specified file on a given document area of ​​the web server or on all documents available to Apache.

mod_negotiation - providing negotiation of transmitted data types between the client and server

CacheNegotiatedDocs [A]

Allows caching of documents with consistent content on intermediate proxy servers and the client computer.

LanguagePriority MIME-lang... [A]

Determines the priority of the languages ​​used in the response to the client when it is not possible to precisely determine or find the document language requested by the client.

mod_alias - allows you to place documents in web server directories in a more arbitrary manner

Alias ​​URL-path filesystem-path

Tells Apache that documents located "below" the given URL should be searched "below" the given file system location.

AliasMatch URL-regexp filesystem-path

Defines more complex rules for searching data in the file system by comparing URLs with a regular expression.

Redirect URL-path URL

In response to the request, the URL-path and the documents "below" returns the specified response code (302 by default) and redirects the client to another URL. The status can be specified as a number or symbolically: permanent (301), temp (302), seeother (303), gone (410). For a 410 response code, the response URL must be omitted.

RedirectMatch URL-regexp URL

Similar to Redirect, using a specified regular expression rather than an exact match to compare the passed URL.

RedirectTemp URL-path URL

Similar to Redirect using 302 response code.

RedirectPermanent URL-path URL

Similar to Redirect using 301 response code.

ScriptAlias ​​URL-path filesystem-path

Works similarly to Alias ​​but automatically sets the cgi-handler handler to run for all files inside the target directory.

ScriptMatch URL-regexp filesystem-path

Similar to ScriptAlias, with URL checking using a regular expression.

mod_rewrite - controls the location of documents on the server

In a brief collection of descriptions of Apache directives, it is difficult to describe the tasks solved by this complex module. As a guide to action, it is best to use the special sections of the apache-manual "Module mod_rewrite URL Rewriting Engine" and "URL Rewriting Guide". The easiest way to learn how to use this module is to consider specific problems and their solutions using it.

There is a single main (parent) process that is responsible for creating child processes, which in turn listen to connections and process client requests. Apache always tries to keep a few unused server processes in reserve that are ready to process incoming requests. Thus, clients do not have to wait for new child processes to be created that will be forked before their request is serviced. The StartServers, MinSpareServers, MaxSpareServers, and MaxClients directives control how the parent process creates child processes to service requests.

In general, Apache is very self-contained, so for most websites there is no need to change these directives from their default values.

For sites that must serve more than 256 simultaneous requests, MaxClients may need to be increased, and for sites located on servers with limited memory, MaxClients may need to be lowered to avoid forcing the server to swap memory to disk and back), which will lead to severe slowdowns in work.

Choosing modules is one of the most important steps in ensuring good Apache Web server security. We should be guided by one good rule: the less the better. To enable the functionality we need and provide good protection, the following modules must be enabled:

httpd_core - Apache core, required with every Apache installation.

mod_access - Controls access to server directories depending on the client's IP address or hostname.

mod_auth - Required to authorize users using text files.

mod_dir - Required to look for index files: "index.html", "default.html", etc.

mod_log_config - Provides logging of requests sent to the server. mod_mime - Contains directives that facilitate the organization of various MIME types on the server.

All other Apache modules must be disabled. We can safely turn them off because we won't need them. By disabling unnecessary modules, we prevent an attacker from exploiting a vulnerability that was found in one of these modules.

It is also worth noting that two Apache modules (mod_autoindex and mod_info) are the most dangerous. The first module allows you to automatically index the directory and is enabled by default. To see how it works, enter, for example, http://server_name/icons/ and if there are no index files in this directory, the contents of the entire directory will be displayed. The second module, mod_info, should never be accessible over the Internet because it exposes the entire Apache Web server configuration.

The next question is how to compile modules. It seems to me that the static method is the best (codes are embedded in executable files) rather than the dynamic method (codes are collected at the time the program is launched). By choosing a static method, we also eliminate the need for yet another module, mod_so.

Independent work: Working with the MySQL database server. Creating tables. Inserting, retrieving and updating data in a database.

Laboratory work No. 12. Installing and configuring the Apache web server.

Independent work: Working with the MySQL database server.

A Web server is a very complex software product that runs on different platforms and operating systems. To work correctly on the installed system, it must be configured.

By default, Apache settings are located in the file " httpd.conf"in the catalogue" conf".

You should pay special attention to the path to the files in the Apache and PHP configuration files. You will often have to specify paths to various directories and files. UNIX and Windows operating systems use different directory separators. UNIX uses forward slash (/) and Windows uses backslash (\). Some Apache and PHP directives work with both types of directory separators. But since Apache and PHP were originally developed for UNIX, you can avoid a number of problems by using their "native" format. Therefore, the paths in the configuration files " httpd.conf" And " php.ini" It is recommended to write through a slash in the UNIX format - "/".

Eg:
ScriptAlias ​​"/php_dir/" "c:/php/" File Directives httpd.conf:

Port- specifies the TCP port that is used by Apache to establish the connection. By default, port 80 is specified. The port can also be specified in the directive ServerName.
Port 80 The only reason to set a non-standard port is if you do not have permission to use the standard port. When using a non-standard port, such as 8080, the port number should be specified in the address " http://localhost:8080/".

ServerAdmin- contains the specified address Email Web server administrator. This is the address that will be displayed in case of server errors.
ServerAdmin [email protected] ServerName- contains given name computer for the server.
ServerName localhost:80 ServerRoot- points to the directory containing the Apache Web server files.
ServerRoot "C:/web_server/apache" DocumentRoot- defines the directory in which the Web site files are located.
DocumentRoot "C:/web_server/apache/htdocs" Container

The scope of directives within this container extends to all files and subdirectories within the directory specified in the directive DocumentRoot.

Options FollowSymLinks Includes Indexes
AllowOverride All
Directive AllowOverride set to value ALL, allows you to override the value of the main configuration file " httpd.conf"in files" .htaccess".

Directive Options FollowSymLinks Allows Apache to follow symbolic links.

Directive Options Includes allows the execution of SSI (Server Side Includes) directives in the code of Web site pages.

Directive Options indexes specifies that the contents of a directory should be returned if the index file is missing.

DirectoryIndex- contains given list index files that should be displayed when accessing a directory without specifying a file name.
DirectoryIndex index.html index.htm index.php Directive ScriptAlias​​used to create an alias for the directory " /cgi-bin/", which houses CGI programs and scripts.
ScriptAlias ​​/cgi-bin/ "C:/web_server/apache/cgi-bin/" Next you need to configure the rights and restrictions on the directory cgi-bin.

AllowOverride None
OptionsExecCGI
Order allow, deny
Allow from all
This action necessary to ensure that directory options are not changed, as this could create security problems.

Directive AllowOverride None says that the options in this directory cannot be overridden by files " .htaccess".

Directive OptionsExecCGI Allows execution of CGI scripts.

Directives order allow, deny And Allow from all allow access to the directory.

AddHandler- forces Apache to consider files with the extensions " exe" And " bat", like CGI scripts.
AddHandler cgi-script .bat .exe DefaultType sets the header of files whose type cannot be determined by extension. In this case, all unknown files are treated as regular text files. To process all unknown file extensions as HTML, change the directive as follows:
DefaultType text/html AddDefaultCharset- sets the default encoding if the encoding is not specified in the head of the HTML document.
AddDefaultCharset windows-1251

Related publications