How to set up smartphones and PCs. Informational portal

Installing apache on windows 7. Installing Apache, PHP, MySQL

We continue to build the local server on our local machine. In this article, we will get acquainted with the installation of an integral part of the local server on the Windows 7 platform, the Apache web server.

Note that a later version of Apache 2.4.18 works for manual installation.


Apache version 2.4.18

Before launching the installer, decide on the installation location of the local server. The local server with its components is placed on the system drive of your computer. And:

  • Apache is installed in the directory: .
  • PHP is installed in the directory: [С:\php]
  • MySQL by default:

How to install the MySQL server as a Windows service I described in the article:. How to install the PHP interpreter I will write in the article: Installing PHP.

1. Run the Apache MSI installer.
installation of Apache MSI first window 2. Meet and agree with the Apache license

3. Next, get acquainted with the documents

4. On this page, you need to fill in the data of our local server:
  • Server Domian: localhost;
  • Server Name: localhost;
  • Admin email: any.

Important: For all users, specify port 80.

5. On this page, switch to

6. On the next page, we understand why we switched to . We now have the ability to specify a custom folder for installing Apache. What we do is by specifying a pre-created directory: [С:\www].

7. On the next page, click and get the result.



In the system tray we get and see the Apache button.

How to check if Apache is running on a computer

Checking the operation of the Apache server. To do this, in the address bar, write the address: http://localhost and we see the inscription "It work!", Which means "Works".

How to turn off Apache on a computer

Apache is not always needed and there is no point in keeping it open. To turn it off, go to the tray and on the right button of the Apache icon, we see three control buttons:

  • Apache monitoring;
  • open servers;
  • exit.

The latter, of which it turns off.

That's all! Apache MSI installation is complete. We remember the Apache installation folder, this will be needed when setting up a local server.

Article Dictionary:

  • Distribution- a form of distribution of programs and software.
  • Release— software version.

This article describes how to install Apache 2.4 + PHP 5.6 + MySQL 5.6 on Windows 7 / 8 / 8.1 / 10

Before you continue reading, do you really need to install and configure all this under Windows? Maybe you should pay attention to and not waste your time and nerves setting the same thing directly in Windows? In any case, read the article about. Perhaps it will save you not only time, but also health.

This instruction will be useful for novice WEB developers who are going to install the Apache WEB server with the latest PHP interpreter on their Windows PC. Of course, it's much easier to install a build like Denwer or resort to using installers and not worry about the settings. However, every web developer must understand the process of the WEB-server, the process of its installation and configuration.

If you want to install PHP 7, then please refer to the article.

If during the process of assembling the server according to this instruction you encountered problems and still consider yourself a WEB developer, then it would be the right step to sort out the problems that have arisen, and not write in a comment that the instruction is shit. Working instruction. Proven by time and hundreds of installations. Be careful when following simple steps. Performing steps manually and analyzing situations, if it doesn't work, will add skill to you as a developer. If you are not a WEB-developer and do not plan to be one, then look for a simple installation method on the Internet - this instruction is not for you.

Please note that under Windows XP these versions VC11 it will be impossible (or extremely difficult) to start.

Preparatory work

Make sure you have Windows 7 or newer. If you have Windows XP, this guide will not help you, because the version of Apache described here does not work under Windows XP.

Remove any WEB servers you installed before, go to services and make sure there are no Apache or IIS services there. If you already have a web server installed, the second one in parallel will most likely not work at all.

If you have Skype, be sure to disable the use of port 80 in the settings. Ultimately, you must ensure that no service is using port 80.

For work, it is very desirable to have a file manager that allows you to create files with any extensions, or, even better, a code editor like Sublime Text or Notepad ++ or a full-fledged IDE.

The folder structure may be different, but this instruction is written for a specific structure and, if you follow it, everything is guaranteed to work.
Before you start, create on disk D folder USR, inside which create 5 subfolders: apache, php, tmp, www, log. Exactly. No version numbers.

In catalog www create index files (using a file manager or code editor) that will be needed to check that everything works:

  • index.html with content: It works!
  • index.php with content:

If you don't have a file manager / code editor / IDE, download the archive with these two . But, if you consider yourself a WEB developer, you must acquire tools.

Add the following to the PATH system variable:

;D:\USR\apache;D:\USR\apache\bin;D:\USR\php;

Remarks!

The line numbers shown in the sample configuration files may differ for other versions of apache and php.
All commands, including editing files, must be carried out on behalf of the Administrator.

Installing Apache 2.4

Although for simple development in PHP there is no need for a separate WEB server (PHP has its own WEB server, which is almost always enough to develop one project), it is still recommended to install and configure the Apache WEB server, if only because the programmer must be aware of these subtleties. Ultimately, you will have to work with a WEB server and have to deal with its configuration. So let's get started.

  1. Loading Apache 2.4 binaries VC11 under your system at the link http://www.apachelounge.com/download/VC11/ Most likely you have a 64-bit OS, so you will need a file with a name like httpd-2.4. xx-win64-VC11.zip
  2. If you need any additional modules, you can download them there (no need for a basic installation)
  3. Unzip the contents of the folder Apache24 from the downloaded archive D:\USR\apache. Please note that in D:\USR\apache you need to put not the Apache24 folder from the archive, but its contents. Nothing needs to be installed.
  4. Change the value in the file ServerRoot to "d:/USR/apache" ( line 37) and value DocumentRoot(and Direcroty) to "d:/USR/www" ( lines 242 and 243). You should also uncomment line 218 and change it to: ServerName localhost:80
  5. Change the log storage parameters in the same file (find the parameters and change them): ErrorLog "D:/USR/log/apache-error.log" CustomLog "D:/USR/log/apache-access.log" common
  6. Install the Apache service (as Administrator). Open a command prompt as Administrator and paste the following line there: D:\USR\apache\bin\httpd.exe -k install
  7. We monitor error messages during the installation of the service. If everything is done correctly, there should be no errors. If after executing the line the command line did not appear again, then you did something wrong. Just use the copy and paste functions to avoid mistakes when reprinting.
  8. Create a desktop shortcut for D:\USR\apache\bin\ApacheMonitor.exe and / or put it into autoload (to open the autoload window in WIN8, you must press WIN + R, then enter shell:Startup and click OK)
  9. We start ApacheMonitor. A shortcut will appear in the system tray. Click on it with the left button, select Apache24 -> Start.
  10. In the browser, go to http://localhost/ - you should see It works!
  11. If you didn’t see such an inscription, we figure out what went wrong (read the logs, google, try to figure out the problem on our own, since we decided to understand the intricacies of the web server)

Installing PHP 5.6

  1. Downloading the latest version VC11x86Thread Safe or VC11x64Thread Safe link http://windows.php.net/download/ . Please note that you need VC11 and precisely Thread Safe. Bit depth should be the same as Apache. The file you need will most likely be named something like: php-5.6.11-Win32-VC11-x86.zip or php-5.6.11-Win32-VC11-x64.zip
  2. Extract the contents of the archive to D:\USR\php. As with Apache, nothing needs to be installed.
  3. To file D:\USR\apache\conf\httpd.conf add lines: LoadModule php5_module "d:/USR/php/php5apache2_4.dll" AddHandler application/x-httpd-php .php # Path to php.ini file PHPIniDir "D:/USR/php"
  4. And change the value DirectoryIndex on the index.html index.php (line 276)
  5. Using ApacheMonitor restart Apache (Apache24 -> Restart)
  6. We go to the browser http://localhost/index.php and make sure that PHP is working.
  7. Making a copy of the file D:\USR\php\php.ini-development With name D:\USR\php\php.ini
  8. Using the search, we find, uncomment and change the parameters: extension_dir = "D:/USR/php/ext" sys_temp_dir = "D:/USR/tmp" extension=php_mysql.dll extension=php_mysqli.dll extension=php_openssl.dll date.timezone = Europe/Zaporozhye
  9. Execute on the command line php -m to view a list of connected modules.
  10. Restart Apache using ApacheMonitor

Virtual hosts in Apache

  1. If several projects are being debugged on the computer, then virtual hosts (sites) may be needed. For example, we will consider two virtual hosts: s1.localhost and s2.localhost. For convenience, we will create folders with the same names, which is not necessary in a real system.
  2. Please note that when using virtual hosts, the DocumentRoot Apache config file no longer makes sense. The server's main host (which will be available at http://localhost/) is now first virtual host in the virtual hosts config file!
  3. First you need to add the following lines to the c:\Windows\System32\drivers\etc\hosts file: 127.0.0.1 s1.localhost 127.0.0.1 s2.localhost

    You need to do this on behalf of the Administrator. It is desirable to reboot after that, but in practice this was not required. If the file cannot be modified (permissions), you can copy it to the desktop, edit it, and then copy it back.

  4. Create folders for virtual hosts D:\USR\www\s1.localhost and D:\USR\www\s2.localhost where the files will be located. Create a file in each folder index.html with content S1 and S2 accordingly (to control that everything works as it should)
  5. Then we create folders for logs: D:\USR\log\s1.localhost and D:\USR\log\s2.localhost- logs of each of the sites will be stored here. Actually, logs can be stored in one folder, but I'm used to doing it this way - it's more convenient for me.
  6. Next, you need to enable support for virtual hosts. In file D:\USR\apache\conf\httpd.conf uncomment the line Include conf/extra/httpd-vhosts.conf
  7. Next, edit the file d:\USR\apache\conf\extra\httpd-vhosts.conf- it should look like this (each virtual host has its own VirtualHost block): ServerAdmin [email protected] DocumentRoot "D:/USR/www/s1.localhost" ServerName s1.localhost ServerAlias ​​www.s1.localhost ErrorLog "D:/USR/log/s1.localhost/error.log" CustomLog "D:/USR/log/s1 .localhost/access.log" common ServerAdmin [email protected] DocumentRoot "D:/USR/www/s2.localhost" ServerName s2.localhost ServerAlias ​​www.s2.localhost ErrorLog "D:/USR/log/s2.localhost/error.log" CustomLog "D:/USR/log/s2 .localhost/access.log" common
  8. First virtual host s1.localhost will now be the main host of the system, since its block comes first in the configuration file, i.e. will be available upon login.

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 a website address is entered in the address bar, when the Enter key is pressed, the browser generates a request sent to a remote computer - a web server.

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

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

Apache supports a huge number of operating systems and hardware platforms, and is often used under the Windows operating system. It is also important that this web-server is 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 field " Administrator's Email Address"Specify your email address, click" Next"And set the switch to" Custom».




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 control icon should appear in the tray. You can stop and restart it by clicking on the icon with the left mouse button.

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

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

If a page appeared with the inspiring inscription “It works! ”, then Apache was installed successfully and 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 of any graphical configurator even in the Microsoft Windows environment, which is rather unusual for most users.

The server is configured by manually editing the httpd.conf configuration file. However, contrary to the notions of the incomprehensibility and complexity of this process, there is nothing complicated in this operation for two reasons: firstly, in order to make a server that is configured for acceptable and comfortable operation from a newly installed Apache, you need to change the configuration file there is very little data, and secondly, the httpd.conf comments contain a lot of useful information needed to figure out the configuration.

What is necessary?

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

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 the lines that begin with a hash sign are text comments, and the web server settings are lines that do not start with a hash symbol.

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

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

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

List of used parameters:

options. The following options are possible:

  • Includes - use of SSI is allowed;
  • IncludesNOEXEC – SSI usage 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 displayed, and if this option is not present, a notification will be issued that access is denied;
  • ExecCGI - execution of CGI scripts is allowed;
  • FollowSymLinks - the server follows the existing symbolic links of the directory (used in Unix systems);
  • SymLinksIfOwnerMatch - the server follows the existing symbolic links of the directory only if the target file has the same owner with the link;
  • All - all of the above together are allowed;
  • None - all of the above together is prohibited;
  • MultiViews - the ability to select specific content and display it depending on the preferences of the browser (even if everything is enabled (Options All. 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 the 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 - only hosts that are not in Deny and are in Allow are allowed access.

Based on the above, try setting up your server. In the httpd.conf file, the Directory directive by default exists in two instances at once - 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:

  • Of the possible functionality of the existing server, indexes in directories and symbolic links are allowed;
  • The possibility of parametric overriding 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 the Apache Monitor or the apache –k restart command on the command line. Setting up the site root folder is now complete.

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

If the page opened successfully, there is a chance that instead of Cyrillic characters you will see unreadable characters. They appear 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 determines the encoding from the page itself, then, for example, Mozilla Firefox and Opera have absolutely no inclination to such actions, and the method of setting the encoding in the browser manually can hardly be called convenient. Therefore, you need to configure Apache to provide the required encoding by default.

Look in the httpd.conf file for the line that starts with AddDefaultCharset . Most likely, the ISO-8859-1 encoding is indicated there, in which there are no 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 site will work in any browser.

In the Apache server, it is quite simple to set up work with several sites. The addresses that can be used for them are 127.0.0.2, 127.0.0.3, etc. In this case, only the one that is the default site (127.0.0.1) will be visible over the network, but this is not critical for local work. The section of the httpd.conf file that configures everything you need to do this is at the very end and is called VirtualHosts .

This description is suitable for any edition of Windows 7/8/8.1.

Apache web server installation

First of all, let's download the Apache distribution from the site: http://www.apachelounge.com/download/ . In the list of distributions Apache 2.4 binaries VC11, we need to download "httpd-2.4.7-win64-VC11.zip".

After downloading, open the archive httpd-2.4.7-win64-VC11.zip

We extract the Apache24 folder from it to the C:\ drive partition

Now we need to tweak the config a bit before installing Apache. Open the httpd.conf file (located here: C:\Apache24\conf) preferably through a convenient editor, such as notepad++. Find the line (217) ServerName www.example.com:80 and change it to ServerName localhost:80

Here we need to specify the full path to the httpd.exe file, which is located in the Apache folder. In our case, this is C:\Apache24\bin\httpd.exe. We type the command C:\Apache24\bin\httpd.exe -k install and press Enter.

If you get the following error while running the program: failed to open the winnt service manager perhaps you forgot to log in as administrator, go to the following folder: C:\Users\your_username_here\AppData\Roaming\Microsoft\Windows\Start Menu\Programs \System Tools, run command prompt as administrator

And repeat the installation command.

Installation completed. Open the bin directory (full path: C:\Apache24\bin\) and run the file: ApacheMonitor.exe. The Apache icon will appear in the system tray, with which you can quickly start / stop the Apache service, click start (start):

Now let's check the functionality. We open the browser, and in the address bar we write http://localhost/ (you can just localhost). If the installation was successful, you should see a page that says It works!

PHP installation (manual)

Do we need Apache without PHP? Of course not, that's nonsense! Therefore, next we will consider the manual (without using the installer) installation of PHP.

Download PHP (Zip archive) from the site: http://windows.php.net/download/ . We need a version: VC11 x64 Thread Safe.

Unpack the contents of the archive into the C:\PHP directory (we create the PHP folder ourselves). Next, in the C:\PHP folder, we find two files php.ini-development and php.ini-production. These files contain basic settings. The first file is optimized for developers, the second for production systems. The main difference is in the settings: developers are allowed to display errors on the screen, while for production systems, error output is disabled for security reasons.

Let's do a few things before proceeding with the PHP installation. Open Control Panel → Appearance and Personalization → Folder Options → View tab, find the line “Hide extensions for known file types”, and if there is a check mark, uncheck it and click “Apply”.

We continue the installation. And so, select the file you need (I chose php.ini-development). The selected file will just need to be renamed a bit. Right click on the file → Rename → erase "-development", leaving only php.ini

Now we open php.ini, we need to make a few changes (be careful when making changes, if there is a semicolon at the beginning of the line, it will need to be removed):

  1. Find the extension_dir option (line 721) and change the ext folder path to match the PHP installation path. For me it looks like this:
    extension_dir = "C:\PHP\ext"
  2. Find the upload_tmp_dir option (line 791). Here you need to specify the path to the temporary folder. I chose c:\windows\temp. Together:
    upload_tmp_dir = "C:\Windows\Temp"
  3. Find the session.save_path option (line 1369). Here you also need to specify the path to the temporary folder:
    session.save_path = "C:\Windows\Temp"
  4. In the Dynamic Extensions section, you need to uncomment several lines (remove the semicolon at the beginning) corresponding to the PHP modules that you may need to work: 866, 873, 874, 876, 886, 895, 900

Save changes and close.

Now back to the Apache settings. We will have to edit the Apache config a bit. We go to the C:\Apache24\conf folder and open the httpd.conf file.

Go to the end of the file and at the very bottom add the following lines:

# Charset AddDefaultCharset utf-8 # PHP LoadModule php5_module "C:/PHP/php5apache2_4.dll" PHPIniDir "C:/PHP" AddType application/x-httpd-php .php

The path to the php folder is the one you chose during the installation process (if you installed in a different directory).

In the same file we find the following lines (lines approximately 274-276):

DirectoryIndex index.html

Before index.html we add index.php with a space. The result is:

DirectoryIndex index.php index.html

For the changes to take effect, restart the Apache service (tray icon - Apache monitor). If the service restarts, that's a good sign. If not (an error will pop up) - look for errors in the configuration files. Check all paths carefully.

To verify that PHP is working, open the C:\Apache24\htdocs folder (this contains the default website files). Create an index.php file in this folder with the following content:

Now open http://localhost/ (or just localhost) in your browser. If everything went well, you will see a similar page:

If instead of a page with information about php, you get a page with the inscription "It works!", then just click refresh the page.

Installing MySQL

Open the distribution download page: http://dev.mysql.com/downloads/installer/5.6.html and download Windows (x86, 32-bit), MSI Installer 5.6.16 250.8M. After clicking on the Download button, you will see a registration form, you can skip it by clicking on the link below ("No thanks, just start my download!").

We launch the installer, after a short download we see the following window:

Click Install MySQL Products, the following window appears, in which we accept the license agreement (tick) and click Next>

The next window prompts us to check if there is a newer version of MySQL, check the Skip... (skip) checkbox and click Next >

In the next window, we are prompted to select the type of installation, select Custom and click Next>:

In the next window, we are given the opportunity to select the necessary components: uncheck MySQL Connectors, in Application uncheck MySQL Workbench CE 6.0.8 and MySQL Notifier 1.1.5, in MySQL Server 5.6.16 uncheck Development Components and Client C API library ( shared) and click Next >

The next window tells us what exactly will be installed, just click Execute

After successful installation, click Next >

In the next window, we are informed that next we will configure our server a little, click Next>

In the first settings window, check the Show Advanced Options checkbox, leave the rest as is and click Next >

In the next window, we are prompted to set an administrator (root) password. This password is better not to lose! Set a password and click Next >

In the next window, we erase the number 56 in the input field, leave the rest as it is and click Next>

Click Next >

Click Next >

It remains to check whether the installation was successful. (win 8): Go to the start menu → go to applications (down arrow) → find MySQL5.6 Command Line Client (terminal for working with MySQL on the command line) → open it. Next, enter the administrator password (root). If the password is correct, you will be taken to the command prompt (mysql>). Enter the command: show databases; (semicolon at the end is required). As a result, you should see a list of databases (at least two - information_schema and mysql). This means that the server is working correctly. Close the command line by executing the exit command.

Add the following line to the C:\Windows\System32\drivers\etc\hosts file: 127.0.0.1 localhost. In the same file, delete or comment out (put a # sign at the beginning of the line) the line::1 localhost (if it is initially commented out, then you do not need to do anything with it).

Installation and basic configuration of phpMyAdmin

Open the download page http://www.phpmyadmin.net/home_page/downloads.php and choose to download the archive ending in *all-languages.7z or *all-languages.zip (at the time of this writing, the latest version was phpMyAdmin 4.1.9 ). Create a phpmyadmin folder in C:\Apache24\htdocs and extract the files of the downloaded archive there.

Let's check how it works. Open the browser and go to the address http://localhost/phpmyadmin/. This window should open:

Now we need to create a configuration file for MySQL. Go to the phpmyadmin folder and create a config folder there. Open the following address in a browser: http://localhost/phpmyadmin/setup/

Now, in order to configure the connection settings to MySQL, click on the "New Server" button, a new window opens for us, in the "Server Host" column, localhost must be replaced with 127.0.0.1:

We save the settings (click Apply) and we will automatically be returned to the previous page. We select the default language - Russian, the default server is 127.0.0.1, the end of the line is Windows. At the bottom, click Save and then Download.

The resulting file (config.inc.php) is saved to the phpMyAdmin installation root (C:\Apache24\htdocs\phpmyadmin). We close the page, we will no longer need it.

That's all. We return to the page http://localhost/phpmyadmin/. Now you can log in to the system as the root user (enter the password that you specified when setting up MySQL for the root user). Testing the connection to MySQL. If everything went well (you were able to log into phpMyAdmin), delete the config folder from the phpmyadmin folder.

Download Apache 2.2 web server distribution here: httpd-2.2.20-win32-x86-openssl-0.9.8r.msi . Based on the installation of this distribution, this article is written. All versions of the Apache HTTP server below 2.2.20 are affected by a serious vulnerability, information on which can be read using the link at the bottom of the page. To date, the previously popular and considered the most stable branch of Apache 1.3 is already outdated and the developers of the Apache HTTP server are recommended to install the latest stable version of Apache 2.2. The newest versions of Apache are available on the official website: Apache HTTP Server. Information on how to choose an Apache distribution is published in the article.

Installing Apache 2.2 on Windows

Installing and running the Apache 2.2 server on Windows XP using a binary distribution with an integrated installer is not difficult (the instructions in the article are for the most part applicable to installation in Windows Vista and Windows 7, testing was done exclusively for installing Apache on Windows XP).

It should be noted that if the computer is connected to the local network/Internet - sites running Apache, by default, can be accessed by all users of the local network or the Internet.

After running the Apache 2.2 installer file "httpd-2.2.20-win32-x86-openssl-0.9.8r.msi", click the "Next" button, agree to the license agreement. In the "Network Domain" and "Server Name" fields, enter "localhost" (without quotes). "Administrator`s Email Address" - administrator's email, for example: [email protected] Leave the "For All Users, on Port 80, as a Service -- Recommendend" field selected by default, which makes Apache available to all system users on port 80 as an automatically started service when Windows starts.

The next step of the wizard (Setup Type) is to select the type of installation: typical (Typical) and selective (Custom). Select "Custom" and click "Next". Next, you need to change the installation path to "C:\apache2.2.20" by clicking the "Change" button and leave the default components as they are. After clicking "Next" and "Install" Apache HTTP Server will be installed.

During the installation process, 2 black windows will appear, which will close automatically (you cannot close them manually). If the installation is successful, a new icon will be displayed near the Windows system clock. If the icon has a green triangle - Apache is running, a red square indicates that the service did not start for some reason.

By typing http://localhost/ in the address bar of the browser, a page with a large, bold inscription: "It Works" should appear, which will indicate that Apache is working as expected. If Apache is running and "It Works" does not appear, you should look for the cause in the firewall and read the section of this article: "Errors when starting Apache".

You can find out the cause of the failure, or rather see the error message when starting Apache, using the Windows console ("Start" -> "Run" -> cmd -> "OK") by manually starting the service. Apache management commands via console:

    httpd.exe -k start (Start)
    httpd.exe -k stop (Stop)
    httpd.exe -k restart (Restart)

To prevent Windows from giving an error:

"httpd.exe" is not internal or external
command, executable program, or batch file.

It is necessary to set the path to the Apache bin directory in Windows to the Path variable, which can later be useful for quickly launching Apache command line utilities, such as htpasswd.exe. This can be done by opening the "Start" menu, finding "My Computer" and right-clicking on it and selecting "Properties" from the list that appears. Next, select the "Advanced" tab and click the "Environment Variables" button. In the "System Variables" window, select the "Path" variable and click the "Edit" button. At the very beginning of the "Variable values" field, add the path to the Apache bin directory:

Adding path to Windows Path variable to Apache bin directory

C:\apache2.2.20\bin;

In order for changes to Path to take effect, you must to restart a computer.

Errors when starting Apache

Starting the Apache server manually will be very useful for detecting errors when connecting PHP as a module and further configuring it. When starting and restarting Apache using the standard console, error messages, unfortunately, are not displayed.

One of the most common errors when starting Apache is that port 80 is busy with another program, such as Skype or ISS. As a result, when starting the server with the httpd.exe -k start command, we get the following message:

httpd.exe: Could not reliably determine the server"s fully qualified domain name, using 192.168.1.2 for ServerName
(OS 10048) + svўey ЁrchЁh ° rkhё yufeyu sheyayuy No. chyutreshkh rfёher ёyukhёr (yaЁyuЄyuyuy / ёhЄhtyushchrfЁhyo / yayuёЄ). : make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down
Unable to open logs
Note the errors or messages above, and press the key to exit. thirty...

The message "could not bind to address 0.0.0.0:80 no listening sockets available" indicates that port 80 is already taken. You can see which process is occupying the 80th port by running netstat -anb on the Windows command line and waiting a few minutes until the entire list is displayed. Now you need to configure the software that interferes with Apache to a different port (in the program settings), remove it, or reconfigure Apache to a different port.

In order to remove a non-critical, but annoying error: "httpd.exe: Could not reliably determine the server"s fully qualified domain name, using 192.168.1.2 for ServerName", you need to uncomment the line in httpd.conf:

ServerName localhost:80

You can also start and stop a Windows service with the following commands from the Windows command line:

    net start apache2.2 (Start)
    net stop apache2.2 (Stop)

But in this case, the error messages when starting Apache will not be informative.

You can also view the status of the Apache HTTP server using Windows services: "Start" -> "Control Panel" -> "Administrative Tools" -> "Services" -> "Apache 2.2". You can also stop and start the HTTP server here.

Apache setup

Basic Apache configuration file httpd.conf located by default in the conf directory, which is located in the root of the Apache installation directory (if Apache is installed according to the instructions in the article - the Apache directory: C:\apache2.2.20). The Apache configuration file can be accessed via: "Start" -> "All Programs" -> "Apache HTTP Server 2.2" -> "Configure Apache Server" -> "Edit the Apache httpd.conf Configuration File".

All comment lines in the httpd.conf file, which are not understood by the Apache HTTP server and serve only as text explanations for the administrator, begin with the "#" character. By removing all comments from the Apache configuration file, you can greatly facilitate further perception and editing of server settings. Before removing the comments, it is advisable to save the original httpd.conf in the same folder where it was under a different name, for example: httpd.conf.original.

When deleting comments in the Apache configuration file, you should be careful not to delete anything superfluous. Only the line starting with "#" should be deleted. For example, in the example below, you should leave all lines that do not start with the "#" character: .

Arbitrary part of Apache httpd.conf configuration file

#
# This should be changed to whatever you set DocumentRoot to.
#

# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None

Before you start configuring the Apache HTTP server, it should be noted that all file paths in httpd.conf should be shared forward slash "/", rather than the backward "\" that is used on Windows. This is necessary to avoid some problems.

An example of using the "correct" forward slash "/" in file paths in httpd.conf

ServerRoot "C:/apache2.2.20"

Also, you should know that in order for the settings changed in httpd.conf to take effect, each time after editing them, you must restart or stop and restart the Apache server.

Connecting PHP as an Apache Module

We find in httpd.conf a lot of lines starting with LoadModule and inserting after the last one:

LoadModule php5_module "c:/php5.2.17/php5apache2_2.dll"
PHPIniDir "c:/php5.2.17"

The first line loads the php5apache2_2.dll module, the second one tells the PHP interpreter where to look for the main PHP configuration file - php.ini. In previous versions of PHP, it was necessary to move php.ini to the Windows main directory, which caused some confusion when configuring PHP.

Next, we tell Apache that the index.php file is also an index file that runs when the client requests it (for example, http://www.. To do this, change the parameters of the directive DirectoryIndex on the:

DirectoryIndex index.php index.html

After saving the settings file, you need to reload Apache for the changes to take effect. It is advisable not to even reboot, but turn Apache off and on using the command line, so that in case of errors, you can see the error message.

Now we need to make sure that the PHP scripts are being executed. To do this, in the directory C:\apache2.2.20\htdocs\ you need to create a phpinfo.php file with the following content:

phpinfo();

After that, opening the page in the browser at http://localhost/phpinfo.php, a page with information about the settings of the PHP interpreter will appear. If instead, the script code is displayed, then the PHP module is not connected.

Apache log files

From the Apache log files, you can learn a lot of interesting things, for example, why did Apache not start? By default, the main log files are stored here: C:\apache2.2.20\logs. You can change their location by configuring the appropriate httpd.conf parameters:

  • ErrorLog- path to the error log.
  • CustomLog- path to the access log.

Apache VirtualHost

Apache virtual hosts are used to handle several different sites by one Apache server. Detailed information on the VirtualHost directive: " ". Below is an example of how to open multi-site support in Apache installed on Windows.

First, you need to create a main folder where the files of all sites will be stored: C:\www. In this directory, we will create two subfolders: mysite.lc and phpmyadmin.lc, which will contain Apache files and configs for sites: http://mysite.lc and http://phpmyadmin.lc. Next, in each of the mysite.lc and phpmyadmin.lc folders, we create three more subfolders: conf, log and public. As a result, the structure should look like this:

The domain zone "lc" (short for English "local") will serve as a definition that the site being opened is located on the local computer. In order for Windows to redirect all requests to local sites to the right place, you need to edit host file(for example, using notepad) located in the directory: C:\WINDOWS\system32\drivers\etc\. After "127.0.0.1 localhost" (although, in fact, the location of the added lines in the file can be anywhere), you need to add two lines and save the changes:

127.0.0.1 mysite.lc
127.0.0.1phpmyadmin.lc

Now we enter in the address bar of the browser the address http://mysite.lc and http://phpmyadmin.lc , after which a page will open in it with a large, bold inscription: "It Works".

The hosts file is polled by the system every time you try to connect to any domain, so you don't need to restart anything for changes made to it to take effect. Another thing is if you try to open the http://mysite.lc domain before saving the data in hosts. At the same time, the browser will most likely write to the DNS cache information that the domain does not exist, and when you re-open this page with the hosts file already modified, the result will not change. In this case, to achieve the desired result, you need to try to flush the DNS cache: "Start" -> "Run" -> "cmd" -> ipconfig /flushdns . If this does not help, try opening the sites in other browsers. An extreme measure that 100% helps is restarting the computer.

It's time to "explain" to Apache that each site has its own directories, which is what container directives are for. . But before that, we need to create and edit two files called index.php, which will be test sites, and place them in the "public" subfolder.

Text of index.php file for C:\www\mysite.lc\public\

echo "mysite" ;

Text of index.php file for C:\www\phpmyadmin.lc\public\

echo "phpmyadmin" ;

Now in the conf folders we create the vh.conf configuration files for virtual hosts:

vh.conf for mysite.lc in directory C:\www\mysite.lc\conf\


# Main site name
ServerName mysite.lc

# Additional Sayia Names
# *.mysite.lc - all subdomains for mysite.lc are available
ServerAlias ​​*.mysite.lc

DocumentRoot "c:/www/mysite.lc/public"
ServerAdmin [email protected]

# Paths to site logs
ErrorLog "c:/www/mysite.lc/log/error.log"
CustomLog "c:/www/mysite.lc/log/access.log" combined

# Site directory settings

order allow,deny
Allow from all

vh.conf for phpmyadmin.lc in directory C:\www\phpmyadmin.lc\conf\


ServerName phpmyadmin.lc
ServerAlias ​​*.phpmyadmin.lc
DocumentRoot "c:/www/phpmyadmin.lc/public"
ServerAdmin [email protected]
ErrorLog "c:/www/phpmyadmin.lc/log/error.log"
CustomLog "c:/www/phpmyadmin.lc/log/access.log" combined

order allow,deny
Allow from all

In httpd.conf, from the very bottom, we start virtual hosts and load the vh.conf configuration file for each site:

Setting up virtual hosts in httpd.conf

# Connecting virtual hosts
NameVirtualHost *:80

To apply the new settings, restart the Apache server.

Article last updated: 2011/09/08

Apache - installation and configuration.

Everything is fine. Apache is running on the local machine. Apache is running on the local network. But from the Internet, the Apache server is not available.

The entire local network is connected to the Internet through a UserGate 4 proxy server.
Made a rule to publish a web server, but Apache is not accessible from the Internet

With any value of the Listen port in httpd.conf, when Start is displayed in a black window for 30 seconds "Only one usage of each socket address is normally allowed: make_sock: could not bind to address ... no listening sockets available, shutting down Unable to open logs"
listen address...
80 0.0.0.0:80
8080 0.0.0.0:8080
1234 0.0.0.0:1234
127.0.0.1:80 127.0.0.1:80
At the same time, when typing http://localhost/ in the address bar of the computer, "It works!" is displayed on the screen.
Please tell me what to do.(Windows7,Internet Explorer9)

"For any value of the Listen port" - Most likely you have some other application hanging on port 80. Find it and disable/remove/transfer to another port. How to do this is written in the article. Alternatively, move Apache to a different port.

You write in the article "If instead, the script code is displayed, then the PHP module is not connected." This is exactly what happens to me, although I did everything as written. Can you suggest what could be the reason?

The reason is the same - PHP is not connected. Check what is written in the Apache logs, also look carefully at the Apache configuration file - the section responsible for connecting the PHP module. If you do everything as it is written in the articles, the Apache + PHP + MySQL bundle starts the first time. The material of the articles has been tested by real successful installations.

Your question is not clear to me.

The instructions tactfully kept silent about what needs to be added to httpd.conf

This line is optional - PHP will work without this directive.

Several virtual hosts are not working. I've been fighting for three months now, then I'll try one thing, then another. All settings are made as described here. One localhost works. If you "Push" into the folder localhost / www any directory and go there at the address localhost / directory, it works. And no more (((((
What could be the reason? Windows XP SP3, but ZverCD edition - could this be the reason?
Help plzzz...

The reason is definitely not in the assembly of Windows. After you have done everything as in the instructions, what error does the browser give after accessing mysite.lc and phpmyadmin.lc?

The first site is registered localhost, the second site.ru. In the Windows hosts file, both hang on 127.0.0.1.
When you try to go to site.ru, it searches for a host for a long time and then writes "Cannot display the page." At the root of the directory, the index.php and index.html files lie, and in any case, if you go to localhost/site.ru (simple html is duplicated there), everything opens there. Or if you comment out the default host (localhost) in Virtualhosts, then when typing localhost, the site site.ru opens.
Maybe instead of localhost it is necessary to prescribe a different name?

After changing the hosts file, try restarting your computer. If you first try to open site.ru in the browser, and only after that change the hosts file, the site will not open. Next, run the ping command in cmd on localhost and site.ru. If site.ru pings (127.0.0.1) - the problem is in the Apache settings. Also, try to disable all antiviruses / firewalls for the duration of the test - perhaps the problem is in them. If nothing helps - reinstall Apache again, fully following all the instructions in the article (procedure, names of test sites, etc.) - everything should work. And after everything has worked, start trying to independently adjust the configs.



PHPIniDir "c:/php"
the error is "Failed to start the APACHE2 service on the local computer. See the system event log for details. If this service is not developed by Microsoft, contact the service developer and report the service-specific error code 1"
when removing the above lines everything works again

Thank you very much! Everything is working!

My php page started to be interpreted only after adding
AddType application/x-httpd-php .php

"My php page started to be interpreted only after adding
AddType application/x-httpd-php .php"
The same thing, rebooted 10 times, until I got into the Internet and saw that I still need to write this line. Added, and everything immediately worked on Windows 7.

Installed Apache (httpd-2.2.20-win32-x86-no_ssl) under OC Windows 7, it starts, but Firefox does not open the start page with:Its work! Ping 127.0.0.1 localhost passes, settings NOD 32, Skype, vhosts.conf file, which is written in the recommendations, are checked. What is the problem? Help me please!

Is it true that the line "#ServerName localhost:80" in the htpd.conf file should be commented out? I created a CreateDB.php file in which I wrote the essence: "create a database test". he created the database, as I later found out from the console of mysql itself, but in the browser it says "remote server or file not found". At the same time, files like phpinfo.php and all sorts of "hello!" worked without comment

Hello.
The problem is this. Installed Apache2.2.20, PHP5.2.17
It seems that the PHP module is connected, but any attempts
refer http://localhost/phpinfo.php do not lead
to the result. I will give the text from the error / log file
Apache/2.2.20 (Win32) PHP/5.2.17 configured -- resuming normal operations
Server built: Aug 30 2011 21:54:15
Parent: Created child process 8012
Child 8012: Child process is running
Child 8012: Acquired the start mutex.
Child 7488: Released the start mutex
Child 8012: Starting 64 worker threads.
Child 7488: All worker threads have exited.
Child 8012: Starting thread to listen on port 80.
I don’t know what to do. Can you tell me.

Good article, but you forgot to mention that when connecting php as a module, you also need to add a configuration for it:

After the lines "
LoadModule php5_module "c:/php5.2.17/php5apache2_2.dll"
PHPIniDir "c:/php5.2.17"
"

You need to write something like "

AddType text/html .php

Correction (tags are worn out)

"less than"IfModule php5_module"greater than"
"less than"Location /"greater than"
AddType text/html .php
AddHandler application/x-httpd-php .php
"less than"/Location"greater than"
"sign less"/IfModule"Sign greater than"

Apache machine (httpd-2.0.64-win32-x86-no_ssl.msi) is running. After installing PHP - php-5.2.17-Win32-VC6-x86.zip everything works. But after pasting in httpd.conf:
LoadModule php5_module "c:/php/php5apache2_2.dll"
PHPIniDir "c:/php"

The error is "Failed to start the service php5apache2_2.dll
and, accordingly, Apache does not start, what could be the reason????
PS. I did not find the answer here!

To Alex
Sorry it's late, but maybe it will help someone. In the parameter of the LoadModule directive, you need to specify a dll that corresponds to the version of Apache. Those. in your case it should be php5apache2.dll

Top Related Articles