• Apache setup. Setting up MySQL. Setting up PHP. Or a local DIY development environment. Installing Apache on Windows (7)

    The article describes installing Apache 2.4 + PHP 5.6 + MySQL 5.6 on operating system Windows 7/8/8.1/10

    Before you continue reading, pay attention to whether you really need to install and configure all this under Windows? Maybe you should pay attention and not waste your time and nerves setting up 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 versions of PHP interpreter on their Windows PC. Of course, it’s much easier to install an assembly like Denwer or resort to using installers and not worry about the settings. However, every WEB developer obliged understand the process of operation of the WEB server, the process of its installation and configuration.

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

    If in the process of assembling the server according to these instructions you encountered problems and still consider yourself a WEB developer, then it would be the right step to understand the problems that have arisen, and not write in the comments that the instructions are crap. The instructions are working. Tested by time and hundreds of installations. Be careful when performing 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 an easy installation method on the Internet - this instruction not for you.

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

    Preparatory work

    Make sure you have Windows 7 or later. If you have Windows XP, these instructions will not help you, since the version of Apache described here does not work under Windows XP.

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

    If you have Skype, be sure to disable the use of port 80 in the settings. Ultimately, you need to make sure 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 begin, create on disk D folder USR, inside which create 5 subfolders: apache, php, tmp, www, log. That's right. Without specifying version numbers.

    In the catalog www create index files (using file manager or code editor), which 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 files. But, if you consider yourself a WEB developer, you must acquire the tools.

    Add to the PATH system variable:

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

    Notes!

    The line numbers given in the example configuration files may differ for other versions of apache and php.
    All commands, including editing files, must be performed as 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 built in, which is almost always enough for the development of one project), it is still recommended to install and configure the Apache WEB server, if only because the programmer must know these subtleties. Ultimately, you will have to work with the WEB server and have to deal with its configuration. So let's get started.

    1. Loading Apache 2.4 binaries VC11 for 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, they can be downloaded there (for basic installation no need)
    3. Unzip the contents of the folder Apache24 from the downloaded archive to D:\USR\apache. Please note that in D:\USR\apache you need to put not the Apache24 folder from the archive, but its contents. There is no need to install anything.
    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. We change the log storage parameters in the same file (find the parameters and change): ErrorLog "D:/USR/log/apache-error.log" CustomLog "D:/USR/log/apache-access.log" common
    6. Install the Apache service (on behalf of the Administrator). Open a command prompt as Administrator and insert the following line there: D:\USR\apache\bin\httpd.exe -k install
    7. We monitor error messages during service installation. If everything is done correctly, there should be no errors. If, after executing the line, the command line does not appear again, then you did something wrong. Simply use the copy and paste functions to avoid typing errors.
    8. Create a shortcut on the desktop for D:\USR\apache\bin\ApacheMonitor.exe and/or place it in startup (to open the startup window in WIN8, press WIN+R, then enter shell:Startup and click OK)
    9. Launch ApacheMonitor. A shortcut will appear in the system tray. Left-click on it and select Apache24 -> Start.
    10. In the browser go to http://localhost/ - you should see It works!
    11. If you don’t see such an inscription, we figure out what went wrong (we read the logs, google, try to figure out the problem ourselves, since we decided to understand the intricacies of the web server)

    Installing PHP 5.6

    1. Download the latest version VC11 x86Thread Safe or VC11 x64Thread Safe via the link http://windows.php.net/download/. Please note that you need VC11 and exactly Thread Safe. The bit width 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. Extracting the contents of the archive into D:\USR\php. As with Apache, there is no need to install anything.
    3. To file D:\USR\apache\conf\httpd.conf add the lines: LoadModule php5_module "d:/USR/php/php5apache2_4.dll" AddHandler application/x-httpd-php .php # Path to the php.ini file PHPIniDir "D:/USR/php"
    4. And change the value DirectoryIndex on index.html index.php (line 276)
    5. Using ApacheMonitor we 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. Performed in command line php -m to view the list of connected modules.
    10. Restart Apache using ApacheMonitor

    Virtual Hosts in Apache

    1. If you are debugging several projects on your computer, you may need virtual hosts (sites). As an 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 at all necessary in a real system.
    2. Please note that when using virtual hosts, the parameter DocumentRoot Apache configuration file no longer makes sense. The main host of the server (which will be accessible at http://localhost/) is now first virtual host in the virtual hosts configuration 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

      This must be done on behalf of the Administrator. It is advisable to reboot after this, but in practice this was not required. If you can't change the file (permissions), you can copy it to your desktop, change it, and then copy it back.

    4. Creating folders for virtual hosts D:\USR\www\s1.localhost And D:\USR\www\s2.localhost, in which the files will be located. Create a file in each folder index.html with content S1 And S2 accordingly (to check that everything is working as it should)
    5. Then we create folders for logs: D:\USR\log\s1.localhost And D:\USR\log\s2.localhost- logs for each site 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 line Include conf/extra/httpd-vhosts.conf
    7. Next we 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, because its block comes first in the configuration file, i.e. will be available upon entry to

    Below I have written instructions as on local computer with Windows 7 - set up an Apache server and install PHP, MySql and phpMyAdmin on it.

    Installing Apache

    Download the distribution from Apache server from http://httpd.apache.org/download.cgi. Select version 2.2.22 and download the installer for windows. On your home computer you are unlikely to need SSL, select “ Win32 Binary without crypto (no mod_ssl) (MSI Installer)«.

    Before installation, turn off Skype, or disable the use of port 80 in the Skype settings, as this will interfere with the installation.

    Install Apache by running the installation file. All installation steps are standard.

    Click Next.

    We agree with the license.

    Enter data into all three text fields. You can enter a non-existent domain like test.test or example.com. This data is needed to create a basic configuration file. Under text fields one of the most important settings- install Apache as a service or as regular program. Select “for All Users, on port 80, as a Service - Recommended” - install as a service.

    Select Custom (custom installation).

    Selecting components and installation location. You can leave all the default values.

    Click Install.

    We complete the installation.

    Installation is complete. An Apache icon will appear in the tray, with which you can quickly stop/start.

    We check the functionality. Go to your browser at http://localhost/ If everything is done correctly, you will see the inscription “It Works!” Congratulations, the first step has been completed successfully.

    Note.

    I recommend immediately enabling support for CNC links; to do this, uncomment the line LoadModule rewrite_module modules/mod_rewrite.so in the file httpd.conf. It is in the folder conf in the place where you installed Apache.

    It was like this:
    (codecitation)#LoadModule rewrite_module modules/mod_rewrite.so(/codecitation)

    It should look like this:
    (codecitation)LoadModule rewrite_module modules/mod_rewrite.so(/codecitation)

    Here and henceforth, uncommenting means removing the comment sign - #, which is located at the beginning of the line.

    To be continued.

    Preparing folders

    I really don’t like having everything lying around, so first let’s create folders where our programs and websites will be located.
    Create a “Server” folder on the “C:\” drive (or wherever is more convenient for you):
    C:\Server\
    Let's create 2 folders in it:
    C:\Server\web – this is the folder in which we will have programs
    C:\Server\domains – and our websites will be in this folder
    So, in the \web\ folder we will create 3 folders for apache, php, mysql:
    C:\Server\web\apache\
    C:\Server\web\php\
    C:\Server\web\mysql\
    Next, go to the domains folder and create the \localhost\ folder
    C:\Server\domains\localhost\
    Inside the folder we will have 2 subfolders: public_html – for site files; logs - for text files, which records “who” accessed the site and what errors appeared in the operation of the site.
    C:\Server\domains\localhost\public_html\
    C:\Server\domains\localhost\logs\
    This concludes the folder structure, let's move on to configuring Apache.

    Apache setup

    To install Apache, we need Apache itself (Cap). Since we have Windows 8.1 x64, we will install Apache x64.
    To download, follow the link:
    www.apachelounge.com/download/win64
    and download “httpd-2.4.6-win64.zip”. We also need for normal operation"Redistributable package Microsoft Visual C++ 2010 (x64)". To do this, download it from this link:
    www.microsoft.com/ru-ru/download/details.aspx?id=14632
    and install.
    After our archive has been downloaded from Apache, let's open it. Having opened the archive, we will see the “Apache24” folder, go into it. Many folders and program files will appear, unpack everything into the previously prepared folder:
    C:\Server\web\apache\
    It should look like this:
    C:\Server\web\apache\bin\
    C:\Server\web\apache\cgi-bin\
    C:\Server\web\apache\conf\
    C:\Server\web\apache\error\
    C:\Server\web\apache\htdocs\
    C:\Server\web\apache\icons\
    C:\Server\web\apache\include\
    C:\Server\web\apache\lib\
    C:\Server\web\apache\logs\
    C:\Server\web\apache\manual\
    C:\Server\web\apache\modules\
    We don't need folders such as \cgi-bin\, \htdocs\, \icons\ and \manual\ - you can delete them.
    Let's go to the folder:
    C:\Server\web\apache\conf\
    And open the Apache configuration file - “httpd.conf” with any text editor. In this file, each line contains directives for Apache settings, and lines starting with the # sign (hash) are a comment and explanation. Let's start setting up:

    Apache configuration file

    # Apache directive
    ServerRoot “C:/Server/web/apache”
    # Listen on local IP port (80 by standard)
    Listen 127.0.0.1:80
    # next we will include extension libraries for Apache
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule php5_module "C:/Server/web/php/php5apache2_4.dll"
    # tell Apache that files from php extension, should be treated as PHP scripts
    AddHandler application/x-httpd-php .php
    # specify the location of the php settings file
    PHPIniDir “C:/Server/web/php”
    # change the server name
    ServerName 127.0.0.1:80
    # change directory access

    Options Includes Indexes FollowSymLinks
    AllowOverride All
    Allow from all


    # directory with our sites
    DocumentRoot “C:/Server/domains”
    # index files, by priority.

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

    # folder for log files
    ErrorLog “C:/Server/domains/logs/error.log”
    CustomLog “C:/Server/domains/logs/access.log”
    # add alias for phpMyAdmin, and correct alias for cgi

    Alias ​​/pma “C:/Server/domains/phpMyAdmin”
    ScriptAlias ​​/cgi-bin/ “C:/Server/web/apache/cgi-bin/”

    # correct the path for cgi

    AllowOverride None
    Options None
    Require all granted

    # file types


    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Other configs:



    BrowserMatch "MSIE 10.0;" bad_DNT


    RequestHeader unset DNT env=bad_DNT

    This completes the configuration of httpd.conf.
    Additional configs were included in the Apache httpd.conf configuration file:
    Include conf/extra/httpd-mpm.conf
    Include conf/extra/httpd-autoindex.conf
    Include conf/extra/httpd-vhosts.conf
    Include conf/extra/httpd-manual.conf
    Include conf/extra/httpd-default.conf
    Let’s open the file “C:\Server\web\apache\conf\extra\httpd-mpm.conf” and quickly go through it.
    # indicate where we will store the pid file:

    PidFile “C:/Server/web/apache/logs/httpd.pid”

    We leave the remaining parameters unchanged. Let's open the file “httpd-autoindex.conf”, change only the lines with the path there:
    Alias ​​/icons/ "c:/Server/web/apache/icons/"

    Options Indexes MultiViews
    AllowOverride None
    Require all granted

    Apache Hosts File

    # using domain localhost as an example

    DocumentRoot "C:/Server/domains/localhost/public_html"
    ServerName localhost
    ErrorLog "C:/Server/domains/localhost/logs/error.log"
    CustomLog "C:/Server/domains/localhost/logs/access.log" common


    # add phpMyAdmin for the future (don't forget to create a folder)

    DocumentRoot "C:/Server/domains/phpmyadmin/public_html"
    ServerName localhost
    ErrorLog "C:/Server/domains/phpmyadmin/logs/error.log"
    CustomLog "C:/Server/domains/phpmyadmin/logs/access.log" common

    This ends file editing. Next, in the remaining files we edit only the paths:
    File "httpd-manual.conf":
    AliasMatch ^/manual(?:/(?:da|de|en|es|fr|ja|ko|pt-br|ru|tr|zh-cn))?(/.*)?$ "C:/ Server/web/apache/manual$1"

    No changes are made to the “httpd-default.conf” file. This completes the Apache configuration setup.

    PHP setup

    Since we have Windows 8.1 x64 and Apache x64 installed and configured, then php should be x64.
    Let's go to the site:

    and download the php archive of the latest version. We need php as a module, i.e. To do this, download Thread Safe. After the archive has been downloaded, open it and transfer the contents to the “C:\Server\web\php\” folder. Let's create two empty folders “tmp” and “upload”. Next, in this folder, look for the “php.ini-development” file and rename it to “php.ini”. Open the file in a text editor and change the directives (commenting lines in the file begins with a semicolon).

    Setting up php.ini

    short_open_tag = On
    zlib.output_compression = On
    post_max_size = 64M
    include_path = ".;C:\Server\web\php\includes"
    extension_dir = "C:/Server/web/php/ext"
    upload_tmp_dir = "C:/Server/web/php/upload"
    upload_max_filesize = 64M
    extension=php_bz2.dll
    extension=php_curl.dll
    extension=php_gd2.dll
    extension=php_mbstring.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    extension=php_pdo_mysql.dll
    extension=php_sockets.dll
    extension=php_sqlite3.dll
    ; in the section we indicate the time zone of our server (http://php.net/date.timezone)
    date.timezone = "Asia/Yekaterinburg"
    session.save_path = "From:/Server/web/php/tmp/"


    On this php settings ends.

    Setting up MySQL

    We install MySQL x64 as a socket under Windows. Download the archive from latest version MySQL x64:
    dev.mysql.com/downloads/mysql
    At the bottom of the page we find Windows (x86, 64-bit), ZIP Archive and click on the “Download” button. You will be redirected to the registration page on the site. Click at the bottom of the page “No thanks, just start my download” to start downloading the MySQL archive. After the archive has been downloaded, open it and transfer all the contents of the folder to “C:\Server\web\mysql\”
    Now open the MySQL settings file – “C:\Server\web\mysql\my-default.ini”. We delete all its contents and enter our data there.
    port=3306
    host=127.0.0.1
    port=3306
    bind-address=127.0.0.1
    enable-named-pipe
    basedir="C:/Server/web/mysql/"
    datadir="C:/Server/web/mysql/data/"
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    That's it. In the configuration file, we indicated that scripts can access the server both via local IP and via a socket connection.
    There's just a little bit left to do. Let’s add the paths to Apache and MySQL to the system variable “PATH”, for this:
    1. Drag your mouse cursor to the lower right corner of the screen
    2. Click the Search icon and enter: control panel
    3. Select System->Advanced ( Additional options systems)
    4. Select Environment Variables ( Environment Variables), in the System Variables menu, find the PATH variable and click on it.
    5. Enter the paths to Apache and MySQL:
    ;C:\Server\web\apache\bin;C:\Server\web\mysql\bin
    Next, we will install the Apache and MySQL services. To do this, use the keyboard shortcut “Win ​​+ X”, a drop-down menu will appear in the lower left corner. Select "Command Prompt (Administrator)".
    On the command line, enter to install Apache:
    httpd –k install
    For MySQL installations:
    mysqld.exe --install MySQL --defaults-file=”C:\Server\web\mysql\my-default.ini”
    Let's set a password for the MySQL user. To do this, start the MySQL service with the command:
    NET start MySQL
    After the service has started, set a password:
    mysqladmin –u root password YourPassword
    We have registered two sites in the “httpd-vhosts.conf” file; in order for the browser to see them, the names of the sites must be added to the “hosts” file. Let's go to the folder:
    C:\Windows\System32\Drivers\etc\
    open the “hosts” file with any text editor (run as administrator) and add to the end of the file:
    127.0.0.1 localhost
    127.0.0.1 phpmyadmin
    Save the file.
    For the convenience of starting and stopping the Apache and MySQL services, we will create the files start-server.bat and stop-server.bat.
    To do this, let's go to the “C:\Server\” folder and create these two files.
    Contents of “start-server.bat”:
    @echo off
    NET start Apache2.4
    NET start MySQL
    Contents of “stop-server.bat”:
    @echo off
    NET stop Apache2.4
    NET stop MySQL
    Setting up Apache, PHP and MySQL is now complete. In order to test the server, let's create a file "index.php" with the contents in the "C:\Server\domains\localhost\public_html" folder:

    Next, let’s start our server; to do this, run “start-server.bat” as an administrator. Once the server has started, open your browser and enter “localhost” in the address bar.
    The PHP information page should appear.

    Preparing folders

    I really don’t like having everything lying around, so first let’s create folders where our programs and websites will be located.
    Create a “Server” folder on the “C:\” drive (or wherever is more convenient for you):
    C:\Server\
    Let's create 2 folders in it:
    C:\Server\web – this is the folder in which we will have programs
    C:\Server\domains – and our websites will be in this folder
    So, in the \web\ folder we will create 3 folders for apache, php, mysql:
    C:\Server\web\apache\
    C:\Server\web\php\
    C:\Server\web\mysql\
    Next, go to the domains folder and create the \localhost\ folder
    C:\Server\domains\localhost\
    Inside the folder we will have 2 subfolders: public_html – for site files; logs – for text files that record “who” accessed the site and what errors appeared in the site’s operation.
    C:\Server\domains\localhost\public_html\
    C:\Server\domains\localhost\logs\
    This concludes the folder structure, let's move on to configuring Apache.

    Apache setup

    To install Apache, we need Apache itself (Cap). Since we have Windows 8.1 x64, we will install Apache x64.
    To download, follow the link:
    www.apachelounge.com/download/win64
    and download “httpd-2.4.6-win64.zip”. We also need for normal operation “Distributable Microsoft package Visual C++ 2010 (x64)". To do this, download it from this link:
    www.microsoft.com/ru-ru/download/details.aspx?id=14632
    and install.
    After our archive has been downloaded from Apache, let's open it. Having opened the archive, we will see the “Apache24” folder, go into it. Many folders and program files will appear, unpack everything into the previously prepared folder:
    C:\Server\web\apache\
    It should look like this:
    C:\Server\web\apache\bin\
    C:\Server\web\apache\cgi-bin\
    C:\Server\web\apache\conf\
    C:\Server\web\apache\error\
    C:\Server\web\apache\htdocs\
    C:\Server\web\apache\icons\
    C:\Server\web\apache\include\
    C:\Server\web\apache\lib\
    C:\Server\web\apache\logs\
    C:\Server\web\apache\manual\
    C:\Server\web\apache\modules\
    We don't need folders such as \cgi-bin\, \htdocs\, \icons\ and \manual\ - you can delete them.
    Let's go to the folder:
    C:\Server\web\apache\conf\
    And open the Apache configuration file – “httpd.conf” with any text editor. In this file, each line contains directives for configuring Apache, and the lines starting with the # sign (hash) are comments and explanations. Let's start setting up:

    Apache configuration file

    # Apache directive
    ServerRoot “C:/Server/web/apache”
    # Listen on local IP port (80 by standard)
    Listen 127.0.0.1:80
    # next we will include extension libraries for Apache
    LoadModule rewrite_module modules/mod_rewrite.so
    LoadModule php5_module "C:/Server/web/php/php5apache2_4.dll"
    # we tell Apache that files with the php extension should be treated as php scripts
    AddHandler application/x-httpd-php .php
    # specify the location of the php settings file
    PHPIniDir “C:/Server/web/php”
    # change the server name
    ServerName 127.0.0.1:80
    # change directory access

    Options Includes Indexes FollowSymLinks
    AllowOverride All
    Allow from all


    # directory with our sites
    DocumentRoot “C:/Server/domains”
    # index files, by priority.

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

    # folder for log files
    ErrorLog “C:/Server/domains/logs/error.log”
    CustomLog “C:/Server/domains/logs/access.log”
    # add alias for phpMyAdmin, and correct alias for cgi

    Alias ​​/pma “C:/Server/domains/phpMyAdmin”
    ScriptAlias ​​/cgi-bin/ “C:/Server/web/apache/cgi-bin/”

    # correct the path for cgi

    AllowOverride None
    Options None
    Require all granted

    # file types


    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Other configs:



    BrowserMatch "MSIE 10.0;" bad_DNT


    RequestHeader unset DNT env=bad_DNT

    This completes the configuration of httpd.conf.
    Additional configs were included in the Apache httpd.conf configuration file:
    Include conf/extra/httpd-mpm.conf
    Include conf/extra/httpd-autoindex.conf
    Include conf/extra/httpd-vhosts.conf
    Include conf/extra/httpd-manual.conf
    Include conf/extra/httpd-default.conf
    Let’s open the file “C:\Server\web\apache\conf\extra\httpd-mpm.conf” and quickly go through it.
    # indicate where we will store the pid file:

    PidFile “C:/Server/web/apache/logs/httpd.pid”

    We leave the remaining parameters unchanged. Let's open the file “httpd-autoindex.conf”, change only the lines with the path there:
    Alias ​​/icons/ "c:/Server/web/apache/icons/"

    Options Indexes MultiViews
    AllowOverride None
    Require all granted

    Apache Hosts File

    # using domain localhost as an example

    DocumentRoot "C:/Server/domains/localhost/public_html"
    ServerName localhost
    ErrorLog "C:/Server/domains/localhost/logs/error.log"
    CustomLog "C:/Server/domains/localhost/logs/access.log" common


    # add phpMyAdmin for the future (don't forget to create a folder)

    DocumentRoot "C:/Server/domains/phpmyadmin/public_html"
    ServerName localhost
    ErrorLog "C:/Server/domains/phpmyadmin/logs/error.log"
    CustomLog "C:/Server/domains/phpmyadmin/logs/access.log" common

    This ends file editing. Next, in the remaining files we edit only the paths:
    File "httpd-manual.conf":
    AliasMatch ^/manual(?:/(?:da|de|en|es|fr|ja|ko|pt-br|ru|tr|zh-cn))?(/.*)?$ "C:/ Server/web/apache/manual$1"

    No changes are made to the “httpd-default.conf” file. This completes the Apache configuration setup.

    PHP setup

    Since we have Windows 8.1 x64 and Apache x64 installed and configured, then php should be x64.
    Let's go to the site:

    and download the php archive of the latest version. We need php as a module, i.e. To do this, download Thread Safe. After the archive has been downloaded, open it and transfer the contents to the “C:\Server\web\php\” folder. Let's create two empty folders “tmp” and “upload”. Next, in this folder, look for the “php.ini-development” file and rename it to “php.ini”. Open the file in a text editor and change the directives (commenting lines in the file begins with a semicolon).

    Setting up php.ini

    short_open_tag = On
    zlib.output_compression = On
    post_max_size = 64M
    include_path = ".;C:\Server\web\php\includes"
    extension_dir = "C:/Server/web/php/ext"
    upload_tmp_dir = "C:/Server/web/php/upload"
    upload_max_filesize = 64M
    extension=php_bz2.dll
    extension=php_curl.dll
    extension=php_gd2.dll
    extension=php_mbstring.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    extension=php_pdo_mysql.dll
    extension=php_sockets.dll
    extension=php_sqlite3.dll
    ; in the section we indicate the time zone of our server (http://php.net/date.timezone)
    date.timezone = "Asia/Yekaterinburg"
    session.save_path = "From:/Server/web/php/tmp/"


    This completes the php configuration.

    Setting up MySQL

    We install MySQL x64 as a socket under Windows. Download the archive with the latest version of MySQL x64:
    dev.mysql.com/downloads/mysql
    At the bottom of the page we find Windows (x86, 64-bit), ZIP Archive and click on the “Download” button. You will be redirected to the registration page on the site. Click at the bottom of the page “No thanks, just start my download” to start downloading the MySQL archive. After the archive has been downloaded, open it and transfer all the contents of the folder to “C:\Server\web\mysql\”
    Now open the MySQL settings file – “C:\Server\web\mysql\my-default.ini”. We delete all its contents and enter our data there.
    port=3306
    host=127.0.0.1
    port=3306
    bind-address=127.0.0.1
    enable-named-pipe
    basedir="C:/Server/web/mysql/"
    datadir="C:/Server/web/mysql/data/"
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    That's it. In the configuration file, we indicated that scripts can access the server both via local IP and via a socket connection.
    There's just a little bit left to do. Let’s add the paths to Apache and MySQL to the system variable “PATH”, for this:
    1. Drag your mouse cursor to the lower right corner of the screen
    2. Click the Search icon and enter: control panel
    3. Select System->Advanced
    4. Select Environment Variables, from the System Variables menu, find the PATH variable and click on it.
    5. Enter the paths to Apache and MySQL:
    ;C:\Server\web\apache\bin;C:\Server\web\mysql\bin
    Next, we will install the Apache and MySQL services. To do this, use the keyboard shortcut “Win ​​+ X”, a drop-down menu will appear in the lower left corner. Select "Command Prompt (Administrator)".
    On the command line, enter to install Apache:
    httpd –k install
    to install MySQL:
    mysqld.exe --install MySQL --defaults-file=”C:\Server\web\mysql\my-default.ini”
    Let's set a password for the MySQL user. To do this, start the MySQL service with the command:
    NET start MySQL
    After the service has started, set a password:
    mysqladmin –u root password YourPassword
    We have registered two sites in the “httpd-vhosts.conf” file; in order for the browser to see them, the names of the sites must be added to the “hosts” file. Let's go to the folder:
    C:\Windows\System32\Drivers\etc\
    open the “hosts” file with any text editor (run as administrator) and add to the end of the file:
    127.0.0.1 localhost
    127.0.0.1 phpmyadmin
    Save the file.
    For the convenience of starting and stopping the Apache and MySQL services, we will create the files start-server.bat and stop-server.bat.
    To do this, let's go to the “C:\Server\” folder and create these two files.
    Contents of “start-server.bat”:
    @echo off
    NET start Apache2.4
    NET start MySQL
    Contents of “stop-server.bat”:
    @echo off
    NET stop Apache2.4
    NET stop MySQL
    Setting up Apache, PHP and MySQL is now complete. In order to test the server, let's create a file "index.php" with the contents in the "C:\Server\domains\localhost\public_html" folder:

    Next, let’s start our server; to do this, run “start-server.bat” as an administrator. Once the server has started, open your browser and enter “localhost” in the address bar.
    The PHP information page should appear.

    Well, we've talked enough about the web server, it's time for us to install it and try it out. There is a list of the most common web servers; when choosing, the specific tasks for which it is deployed are taken into account. Let's choose the free Apache web server. I consider it ideal for entry-level and mid-level sites. Of course, you can take the easy route - install a ready-made Denwer combine, as most beginners do, but in our case, in addition to the result, theoretical knowledge is also important. And after today’s lesson your skill will definitely improve :)

    We go to the project download page - http://httpd.apache.org/download.cgi and download the latest stable version for Windows in the form of an MSI installer (in my case it was apache_2.2.14-win32-x86-no_ssl.msi). Let's start the installation. The first dialog that can mislead us is the dialog for entering information about the server:

    We will configure our server after installation, but now let’s not worry too much and enter localhost in the “Network Domain” and “Server Name” fields, and your email address in the “Administrator’s Email Address” field (about what localhost, we will talk later). We do not touch the lower switches. Click “Next”, agree with the typical installation, “Next” again will prompt you to select the directory in which the web server will be installed:

    In my opinion the path is too long, let's shorten it to C:\Program Files\Apache. We continue the installation and wait for it to finish. After closing the installer, the Apache monitor icon will appear in the tray:

    This utility allows you to start, stop, restart our web server, and find out its status. Apache itself was installed as a service that will automatically start when the computer boots:

    Now let's remember what we talked about in the article. As you remember, each computer connected to the network has its own IP address. But even if your computer doesn't have a single network connection, it has at least one internal IP address. This address is 127.0.0.1 . It is the same on all computers and points to the computer itself. That is, if you specify the server address 127.0.0.1 to a network client application, the client will try to connect to the server located on your own computer. Next we talked about domain names, which are resolved into IP addresses by DNS servers. The internal address 127.0.0.1 has its own internal domain name - localhost. Moreover, to convert this name into an address, the computer does not need to contact the DNS server, since this correspondence is built into the computer itself.

    Let's launch a web browser and enter the localhost domain in the address bar:

    I hope you understand what happened? The localhost domain was resolved to IP address 127.0.0.1, the web browser connected to the web server at this address and port 80 and requested the home page using HTTP. That is, our web server is working, it sent the browser a page with the inscription “It works”.

    Let's start setting up our web server, which boils down to editing the Apache configuration files. First you need to get a convenient, practical and at the same time simple text editor. If you already have one, congratulations, but if you are an unhappy Notepad user, I can suggest the editor. Go to folder C:\Program Files\Apache\conf and rename the file httpd.conf V httpd.conf.bak, so that if something happens you have the initial configuration at hand. Create a new file httpd.conf with the following content:

    ServerRoot "C:/Program Files/Apache" Listen 80 LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule asis_module modules/mod_asis.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule authn_default_module modules/mod_auth n_default.so LoadModule authn_file_module modules /mod_authn_file.so LoadModule authz_default_module modules/mod_authz_default.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule autoindex _module modules/mod_autoindex.so LoadModule cgi_module modules/mod_cgi.so LoadModule dir_module modules/ mod_dir.so LoadModule env_module modules/mod_env.so LoadModule include_module modules/mod_include.so LoadModule isapi_module modules/mod_isapi.so LoadModule log_config_module modules/mod_log_config.so LoadModule mime_module modules/mod_mime.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule rewrite_module modules/mod_rewrite .so LoadModule setenvif_module modules/mod_setenvif.so ServerName localhost AccessFileName .htaccess ServerTokens prod LogLevel error ErrorLog "logs/error.log" DefaultType text/plain AddDefaultCharset UTF-8 DirectoryIndex index.html Order allow,deny Deny from all Satisfy All TypesConfig conf/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz LogFormat "\nclient=%h\ntime=%(%d.%m.%Y %H:%M:%S)t\npage=%U%q\nreferer=%(Referer)i\nreqmethod=%m \nhost=%(Host)i\nagent=%(User-agent)i\n\n" mylog

    Let's figure it out. ServerRoot- the path where our web server is installed. Pay attention to the slashes. Listern- indicates the port number that the web server will “listen” to, as well as, if necessary, the IP address (if your computer has several connections and you need to accept connections through only one of them). We specified port 80, which is standard for web servers. LoadModule loads a web server module; modules allow you to get additional features. Our configuration file contains a list of standard modules. AddDefaultCharset- default encoding, set to Unicode (UTF-8). The rest is of little concern to us for now.

    And now the most important thing. Have you forgotten why we are installing a web server? That's right, to work on our future sites. There is a concept root directory- this is the directory where the site’s content is located, that is, the files from which it consists. By default in our Apache the root directory is the directory . Going there you will find a single file there under the name index.html. This is the same file that contains the main page with the inscription "It works" at http://localhost. The fact is that if the request (which, by the way, is called a url) does not contain a file name, then the web server looks for a file with one of the standard names. These names (more precisely, one name - index.html) are written in our configuration file:

    DirectoryIndex index.html

    Thus, when asked http://localhost the web server will look for the file C:\Program Files\Apache\htdocs\index.html, upon request http://localhost/docs - C:\Program Files\Apache\htdocs\docs\index.html(if docs- folder), upon request http://localhost/news.html - C:\Program Files\Apache\htdocs\news.html and so on.

    When building a web site, it is convenient to have not one, but, say, three local (located on the local machine) domains on which you can independently test your sites. Apache allows you to serve multiple sites, that is, you do not have to install your own copy of the web server for each domain (in addition, we remember that only one server application can run on a specific port on a computer). Multiple domain names can refer to the same IP address. Apache, in turn, can, depending on the domain name passed in the HTTP request (remember the Host parameter, article “Principles of Web Server Operation”), search for files in a specific root directory. This technology is called "virtual host".

    So, localhost matches the address 127.0.0.1, let's create three more internal domains test-domain1, test-domain2 and test-domain3 that will match the same address. Open the file in a text editor C:\WINDOWS\system32\drivers\etc\hosts. In this file you can set the correspondence between domain names and IP addresses. Here we will find the same localhost correspondence to the address 127.0.0.1. Add the following lines to the end of the file:

    127.0.0.1 test-domain1 127.0.0.1 test-domain2 127.0.0.1 test-domain3

    Before contacting the DNS server, a match is looked for in this file, and if successful, the request is canceled and the found address is used.

    The next step is for each domain name to create its own root directory and tell our web server about it. Delete in the folder C:\Program Files\Apache\htdocs file index.html and create three folders there: test-domain1, test-domain2 And test-domain3, in each of these folders there is a folder log- for logs and folder www- actually, the root directory for the domain. At the end of the file C:\Program Files\Apache\conf\httpd.conf add the following:

    NameVirtualHost *:80 ServerName test-domain1 DocumentRoot "C:/Program Files/Apache/htdocs/test-domain1/www" ErrorLog "C:/Program Files/Apache/htdocs/test-domain1/log/error.log" CustomLog "C:/Program Files/Apache/htdocs/test-domain1/log/access.log" mylog ServerName test-domain2 DocumentRoot "C:/Program Files/Apache/htdocs/test-domain2/www" ErrorLog "C:/Program Files/Apache/htdocs/test-domain2/log/error.log" CustomLog "C:/Program Files/Apache/htdocs/test-domain2/log/access.log" mylog AllowOverride All Options -Indexes ServerName test-domain3 DocumentRoot "C:/Program Files/Apache/htdocs/test-domain3/www" ErrorLog "C:/Program Files/Apache/htdocs/test-domain3/log/error.log" CustomLog "C:/Program Files/Apache/htdocs/test-domain3/log/access.log" mylog AllowOverride All Options -Indexes

    Three blocks VirtualHost describe our three virtual hosts. Each is given its own root directory - DocumentRoot, path to error log - ErrorLog and access log - CustomLog.

    In the root directory of each domain, create a file index.html with the contents "Hello from test-domain1", "Hello from test-domain2" and ""Hello from test-domain3". For configuration changes to take effect, you must restart Apache (left click on the Apache monitor icon -> Restart) If no errors were made, everything should work:

    Congratulations, you now have a web server configured with three local hosts. Expanse for a webmaster :) It's time to start learning the basics of web construction.