Installing and configuring apache php. How to Install Local Apache Server with Php, MySQL, phpMyAdmin on Windows Machine

Apache for Windows XP

Currently, all current versions of Apache run on Windows 7 SP1, Vista SP2, 8 / 8.1, 10, Server 2008 SP2 / R2 SP1, Server 2012 / R2, Server 2016.

Thus, it is currently not possible to run modern versions of Apache on Windows XP. Also Apache will not work on Windows Server 2003.

On Windows XP, you can only run Apache 2.2. Moreover, your Windows XP system must have Service Pack 3.

Before proceeding, I recommend that you upgrade to a newer Windows version- starting from the seven, you can install any modern version of Apache and PHP. Old versions of Apache and PHP may contain bugs. If you plan to use a local web server to learn web application administration and PHP programming, then Windows XP is not the best platform - here you will be dealing with long outdated software.

If I haven't convinced you, then follow this step by step instructions to run Apache on Windows XP.

Creating the web server structure

Let's create the directory structure of our server. The main idea is to separate executable files and site files from databases. This is convenient for server maintenance, including backup.

At the root of the disk C:\ create a directory server. In this directory, create 2 subdirectories: bin(for executable files) and data.

Go to directory data and create subfolders there D.B.(for databases) and htdocs(for websites).

How to Install Apache on Windows XP

Select Custom installation:

Change the installation folder to C:\Server\bin\Apache2.2\:

Once the installation is complete, open http://localhost/ :

Go to directory C:\Server\bin\Apache2.2\conf\ and open the file httpd.conf any text editor.

In it, we need to replace a number of lines.

#ServerName localhost:80

ServerName localhost:80

DocumentRoot "C:/Server/bin/Apache2.2/htdocs"

DocumentRoot "C:/Server/data/htdocs/"

DirectoryIndex index.html

DirectoryIndex index.php index.html index.htm

# 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

# AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride All

#LoadModule rewrite_module modules/mod_rewrite.so

LoadModule rewrite_module modules/mod_rewrite.so

We save and close the file. That's it, Apache setup is complete! Restart the web server or restart your computer for the changes to take effect.

Place your sites in a folder C:\Server\data\htdocs\.

How to Install PHP on Windows XP

On Windows XP, with this version of Apache, only PHP 5.4 will work, the latest version is PHP 5.4.9, this is the file that we download from the archive.

Download and install the "Microsoft Visual C++ 2008 Redistributable Package (x86)" file for this version of PHP.

In folder C:\Server\bin\ create another folder named PHP, unpack the contents of the downloaded file into it php-5.4.9-Win32-VC9-x86.zip.

In file C:\Server\bin\Apache2.2\conf\httpd.conf add lines at the very end

PHPIniDir "C:/Server/bin/PHP" AddHandler application/x-httpd-php .php LoadModule php5_module "C:/Server/bin/PHP/php5apache2_2.dll"

Now in a folder C:\Server\bin\PHP\ find the file php.ini development and rename it to php.ini.

Open this file php.ini in any text editor, look for the line

; extension_dir = "ext"

and replace it with

Extension_dir = "C:\Server\bin\PHP\ext\"

Now find the group of lines:

;extension=php_bz2.dll ;extension=php_curl.dll ;extension=php_fileinfo.dll ;extension=php_gd2.dll ;extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ;extension=php_imap.dll ;extension =php_interbase.dll ;extension=php_ldap.dll ;extension=php_mbstring.dll ;extension=php_exif.dll ; Must be after mbstring as it depends on it ;extension=php_mysql.dll ;extension=php_mysqli.dll ;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client ;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client =php_pgsql.dll ;extension=php_pspell.dll ;extension=php_shmop.dll

and replace it with:

Extension=php_bz2.dll extension=php_curl.dll extension=php_fileinfo.dll extension=php_gd2.dll extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ;extension=php_imap.dll ;extension=php_interbase.dll ; extension=php_ldap.dll extension=php_mbstring.dll extension=php_exif.dll ; Must be after mbstring as it depends on it extension=php_mysql.dll extension=php_mysqli.dll ;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client ;extension=php_oci8_11g.dll ; Use with Oracle 11gR2 Instant Client extension=php_openssl.dll ;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll ;extension=php_pdo_odbc.dll ;extension=php_pdo_pgsql.dll extension=php_pdo_sqlite.dll ;extension=php_pgsql. dll ;extension=php_pspell.dll ;extension=php_shmop.dll

now uncomment the lines from this group:

;extension=php_soap.dll ;extension=php_sockets.dll ;extension=php_sqlite3.dll ;extension=php_sybase_ct.dll ;extension=php_tidy.dll ;extension=php_xmlrpc.dll ;extension=php_xsl.dll ;extension=php_zip.dll

should get:

extension=php_soap.dll extension=php_sockets.dll extension=php_sqlite3.dll ;extension=php_sybase_ct.dll ;extension=php_tidy.dll extension=php_xmlrpc.dll extension=php_xsl.dll ;extension=php_zip.dll

Restart the web server:

In catalog C:\Server\data\htdocs\ create a file with the name i.php

Copy to this file:

Unzip the downloaded file to C:\Server\data\htdocs\. Rename this folder (phpMyAdmin-3.5.8.2-all-languages) to phpmyadmin.

In catalog c:\Server\data\htdocs\phpmyadmin\ create a file config.inc.php and copy it there:

Now in a web browser open http://localhost/phpmyadmin/ :

For Username, enter root and leave the password blank.

Conclusion

As you can see, although we have selected suitable versions, it is possible to run a full-fledged web server on Windows XP, even if not with the latest software components.

By the way, you can download the finished assembly created according to this instruction. You will find her.

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 convenient editor, like 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 checkmark, 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 option extension_dir (line 721) and change the path to the ext folder according to the path PHP installations. 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 pops up) - look for errors in 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 are more a new version MySQL, check Skip... (skip) 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 properly. 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 MySQL setup For 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.

We indicate the version of our operating system (I indicated 64-bit Windows), and go to the download page (Go to Download Page https://dev.mysql.com/downloads/windows/installer/5.7.html).

I chose to download the full msi installer. At the time of this writing, there was current version MySQL 5.7.21 and downloaded a distribution called mysql-installer-community-5.7.21.0.msi.

Apache 2.4

At the time of preparation of the article, x64 version 2.4.33 was available, built on the basis of vc14:
httpd-2.4.29-o110g-x64-vc14.zip.
The size of the archive is about 10 MB.

PHP 7.2

At the time of writing this article, the x64 version of PHP 7.2 (7.2.2), Thread Safe built on VC15 was available: php-7.2.2-Win32-VC15-x64.zip.
Size Zip archive: 24 MB.
Now there are newer ones.

phpMyAdmin (PMA)

For database management MySQL data on local computer, install the free phpMyAdmin package.

We will download its distribution kit from the site http://www.phpmyadmin.net/
At the time of writing, version 4.7.7 was available:
phpMyAdmin-4.7.7-all-languages.zip
Size - about 11 MB.

We put the contents of the archive in a pre-prepared folder, for example:
D:\sites\localhost\www

Installation List

Distribution downloaded. Install in this order:

  • MySQL
  • Apache - setting up virtual servers, check for html
  • PHP - with additional configuration of Apache, check on php_test.php
  • phpMyAdmin (with additional php configuration)

Installing MySQL

Run the previously downloaded MySQL installer (mysql-installer-....msi).

In the License Agreement window, check the box:
I accept the license terms
- and click the Next button.

In the Choosing a Setup Type window, select the Custom item (to choose the parameters for installing the MySQL server yourself). Click the Next button.

In the Select Products and Features window, be sure to select the MySQL Server - X64 component. The rest of the components are optional. Having selected a component in the left part of the window, press the right arrow so that this component from those available for installation goes to the right part of the window - a list of what we will install.

Click Next after selecting components.

In the Installation window, click the Execute button to start the installation for execution.

You can monitor the progress of the installation by clicking the Show Details button.

When the installation is completed (Status becomes complete), click the Next button to proceed to configuring the MySQL server.

In the Product Configuration window, click the Next button.

In the Type and Networking window

leave the item Standalone MySQL Server enabled, click Next.

In the next window Type and Networking
set item Config Type = Development Machine

Leave the checkboxes next to TCP/IP and Open Firewall port for network access.
The MySQL communication port is also left with the default value (Port Number = 3306).

Check the box next to Show Advanced Options.

In the Accounts and Roles window, set the password for the main user (with the login root - administrator).

In the MySQL User Accounts field, you can add other users who will have access to MySQL databases. We will not create others yet: we will connect as root.

IN Windows window Service, check the Configure MySQL Server as a Windows Service item (so that the MySQL server starts as a system service).

Leave the system service name (MySQL57) as default.

We will start the MySQL server service manually (we only need it for the development and testing of local sites), so uncheck the Start the MySQL Server at System Startup item (so that the server does not start every time you start OC Windows).

We will start the service on behalf of the Standard System Account (we do not change this option).

In the Plugins and Extensions window, leave everything as it is. Click Next.

In the Advanced Options window, you can change the parameters of the logs (logs) where the server writes messages in the course of its work. Here you can leave everything as it is.

In the Apply Configuration window, click the Execute button to apply the server configuration.

When finished, click the Finish button.

In the Product Configuration window, click Next.

In the last window of the Installation Complete, checkboxes for items can be left unchecked. Click Finish.

The installation and configuration of the MySQL server is now complete.

You can start/stop the MySQL server manually by going to the list of Windows services.
Find MySQL57 in the list, right click on it and select "Start/Stop".

Installing Apache 2.4 for Windows

There are many articles on the internet that describe how to install Apache 2.4 for Windows. I may repeat something, but I will state my version step by step.

The archive downloaded from the developer's site (using the httpd-2.4.29-o110g-x64-vc14.zip option) contains the Apache24 folder. We place it, along with its contents, on drive C:

In addition to the package itself (the Apache24 folder), the archive contains the readme_first.html file, which is useful to read.

Particular attention should be paid to the presence of the Visual C++ 2015 x64 Redistributable Package in the installed Windows OS.
This package contains a set of libraries without which this build of Apache will not work.
You can download this package for free from the Microsoft website at the link (https://www.microsoft.com/en-us/download/details.aspx?id=49984) given in the readme_first.html file. Be sure to install it if it is not already in your OS.

If you have programs installed on your computer that listen on port 80, then it is better to discourage them from using this port, or assign them another one. The Apache server is configured on this port by default, see the Listen parameter in the C:\Apache24\conf\httpd.conf file

We are trying to start the server (later we will consider the option of starting the server as a system service (service)).
To do this, run the command line in the mode (on behalf of) the administrator.
Go to the C:\Apache24\bin folder and run the httpd.exe program

On first launch, you may see a Windows Security Alert that Windows Firewall has blocked some features of this application (see picture)

Check the box to enable Apache HTTP Server communication for Private networks.
Work in public networks can be prohibited.

Opening any browser, enter in the address bar the address http://localhost/
- the builder page for this Apache server package should appear.

(it is installed with the package in the C:\Apache24\htdocs folder - this is the value of the DocumentRoot variable in the httpd.conf file,
but we will change it later).

So the Apache server starts up and works fine.

If the server does not start, then you need to see what errors it gives. Errors can be seen at startup: on the command line and in the file C:\Apache24\logs\error.log

Let's make it so that the Apache server is started by the service (described in the readme_first.html attached to the distribution).
On a command prompt run as administrator, navigate to the C:\Apache24\bin folder and run the command
httpd -k install

It is convenient to monitor the status of the Apache server service and restart it (we will do it often during configuration) through the C:\Apache24\bin\ApacheMonitor.exe program. Make a shortcut for it and place it in a convenient place to launch it (on the taskbar or on the desktop).

It remains to configure the Apache server for our needs:
focus on the folders in which our sites will be located;
Prepare to work with MySQL and PHP.

Let's say we want to have 2 sites on the local computer with the names localhost and wp-test
http://localhost/
http://wp-test/

For this in system file C:\Windows\System32\drivers\etc\hosts should be lines like this

127.0.0.1 localhost
127.0.0.2 wp-test

The first line usually already exists by default.
We fill the second one ourselves.

These lines tell you to look for hosts named localhost and wp-test at IP addresses 127.0.0.1 and 127.0.0.2
- both addresses correspond to the local computer.

Restarting the OS is optional.

Let's create folders on the local computer to store site files, for example, in the folder:
D:\sites\localhost
D:\sites\wp-test

In each of these folders we will create 2 files with the names
access log
error log
and subfolder www
D:\sites\localhost\www
D:\sites\wp-test\www
- in these folders we will create index.html files with the following content:
this is localhost
this is wp-test

Now let's configure the Apache server to use the virtual hosts corresponding to our sites.

Let's edit the server configuration file (C:\Apache24\conf\httpd.conf).
To do this, you need to open it in a text editor.
I use NotePad++ (a very feature rich free editor) for this.

I usually add virtual hosts to the end of this file.

Let's add the following lines there:

#localhost ServerName localhost DocumentRoot "D:/sites/localhost/www" ErrorLog "D:/sites/localhost/error.log" CustomLog "D:/sites/localhost/access.log" common #wp test ServerName wp-test DocumentRoot "D:/sites/wp-test/www" ErrorLog "D:/sites/wp-test/error.log" CustomLog "D:/sites/wp-test/access.log" common AllowOverride All Options Includes FollowSymLinks Require all granted

Checking if browsers open pages at addresses
http://localhost/
http://wp-test/

When opened normally, the page should display the following lines:
this is localhost
And
this is wp-test

Similarly, you can create other virtual web servers on the local computer.

Additional settings for Apache that may come in handy.

Installing PHP 7

The content of the downloaded archive php-7.2.2-Win32-VC15-x64 is placed in the folder C:\php\

Carefully read the C:\php\install.txt file from the distribution.
This file briefly describes how to install PHP on the system and configure it to work with Apache.

The path C:\php is added to the PATH system variable

For testing PHP on our local site http://localhost/
create a php_test.php file in its folder (D:\sites\localhost\www) with the following content:

Then, when opening the address http://localhost/php_test.php, a page with data from the phpinfo command should open.

Prepare Apache for PHP

In httpd.conf file

In the place where the modules are loaded (look for the LoadModule group of commands), at the end of the group (if there is no such line yet), add:

LoadModule php_module "C:/php/php7apache2_4.dll"

Specify the path where php is installed with the directive:

PHPIniDir "C:/php"

In section add index.php:

DirectoryIndex index.html index.php

In section where commands like AddType application...

add a line

AddType application/x-httpd-php .php

Save httpd.conf and restart Apache.

After that, the test page http://localhost/php_test.php will open.

Let's edit the PHP settings file for phpMyAdmin and more.

Rename the php.ini-production file to php.ini (leave it in the same folder C:\php\)

Edit php.ini like this

Uncomment the line

Extension_dir = "ext"

Enable the parameter (default=Off)

Enable_dl = On

Specify a folder to download temporary files

Upload_tmp_dir="d:/sites/uploadtemp" upload_max_filesize = 500M

In chapter; Dynamic Extensions ;

uncomment the lines:

extension=gd2 extension=mbstring extension=mysqli

Let's enable another extension:

Extension=openssl

For example, to update wordpress plugins on the local site through the admin panel. Otherwise, an error occurs: No working transports found.

To execute long scripts, we will extend the maximum execution time, for example, like this:

Max_execution_time = 300

Installing phpMyAdmin

After downloading the distribution and placing its contents in the folder D:\sites\localhost\www
go to the documentation folder \www\doc\html and open the setup.html file

Following his instructions, we will create a config subfolder in the root directory of the site (www) (this is necessary for the time of configuring phpMyAdmin with a script that can be run by opening the setup page at http://localhost/setup/).
Rename the file located in the root directory \www\config.sample.inc.php
to the working file \www\config.inc.php
- open this file for editing and define the $cfg["blowfish_secret"] parameter in it - fill it with any characters, for example, the phrase ANY_WHAT_YOU_WANT:

$cfg["blowfish_secret"] = "ANY_WHAT_YOU_WANT"; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

and, having saved, we will close this file.

Let's check if the pages of the site open:
http://localhost/
http://localhost/index.php

In this article, we will look at installing and configuring a Web server Apache, PHP 5 And DBMS MySQL to use them on the local machine under the operating Windows system(2000 and XP). Using local servers can be useful for many reasons - you need to learn PHP or MySQL, and hosted testing your Web applications is either expensive or not possible at all. In this case, you will need the Apache+PHP+MySQL bundle on your local machine.

First you need to get the Apache and MySQL server distributions, as well as the PHP archive. We will be installing and configuring Apache 2, MySQL 4 and PHP 5.

You can also download the php.ini files from our site to configure PHP and httpd.conf for Apache. However, do this only as a last resort - if you did not succeed with the "native" files that appeared when installing applications. But in any case, they will need to be configured for a specific machine. Download php.ini and httpd.conf

You can download Apache from the mirrors provided on the official website http://www.apache.org/dyn/closer.cgi . When searching, keep in mind that Apache can also be called httpd, after its UNIX daemon. Mirrors usually have many different files, for example:
httpd-2.0.49-win32-src.zip is an archive with source codes(src) for Windows (win32) Apache Web Server (httpd) version 2.0.49.
httpd-2.0.49.tar.gz - the same, but for Linux, in which it is customary to distribute programs in source codes.
apache_2.0.50-win32-x86-no_ssl.exe - and here is the Apache server (apache) version 2.0.50 compiled for architecture (x86) for Windows (win32) without SSL(no_ssl) support - here it is needed.

Comment

Apache distribution binary codes are distributed in several versions, both with *.exe and *.msi extensions and have a name like httpd_version_win32_*_.msi.

So that you do not suffer, here is a resource where you can get it: http://apache.rinet.ru/dist/httpd/binaries/win32/
The second and third digits in the version may differ from those given here - you should choose the most latest version, as it fixes bugs found in previous versions.

PHP 5 can be downloaded from the section of our website.

The MySQL distribution can be downloaded from our website.

A complete reference manual in Russian can be found at .

After we have stocked up with all the necessary distributions, we can proceed with the installation. The order in which Apache, PHP and MySQL are installed does not matter. Let's start with the Apache web server.

Installing the Apache Web Server

Run the Apache web server installer. The result will be a window with a license agreement, after accepting which, you should go to the next window with brief information about innovations in the second version of Apache. The following window, shown in the figure, allows you to enter information about the server: Domain name servers, server name And address Email administrator. If the installation takes place on a local machine, then in the fields for the domain name and server name, enter localhost(See picture.). At the bottom of the window, you are prompted to select port number by which the server will accept requests (80 or 8080).


localhost is the name for using the server on the local machine, which is associated with the IP address 127.0.0.1, which is reserved for local use.

After that, the installation method will be offered: standard ( Typical) or selective ( Custom) that allows you to select server components manually. The next window allows you to select the server installation directory, by default it is C:Program FilesApache Group , but we recommend choosing another directory, for example, C:www. After that, the installation wizard will report that it is ready for the installation process and after pressing the button Install, the server files will be copied. If the installation was successful, Windows will automatically start Apache.

After successful installation, typing http://localhost/ or http://127.0.0.1/ in the browser window should load the server page.

Now you need to learn how to manage Apache, namely, learn how to start, stop and restart the server. There are many ways to carry out these operations: using the ApacheMonitor utility, using the management console Windows services, using the Start menu options, from command line... We will look at the Windows Services Management Console, which allows you to configure Apache to automatically start at system startup. To launch the management console, run the command
Start->Settings->Control Panel->Administrative Tools->Services.
In the console window that appears, in the figure below, select the Apache2 service. The right-click context menu allows you to start, stop and restart the service.


Windows Services allow you to run background applications at system startup. To do this, go to the Properties window by selecting context menu service point Properties and in the window that appears in the drop-down list " Launch type"select item" Auto".

Apache Configuration

Web server - complex software working on different platforms and in different operating systems Worldwide. Therefore, in order to work correctly on installed system it needs to be configured (configured).
By default, Apache settings are located in the httpd.conf file in the conf directory. The following will describe the main directives in the httpd.conf file and their commonly used meanings.

File paths

In Apache and PHP configuration files, you will often need to specify paths to various directories and folders. In operating rooms UNIX systems and Windows use different directory separators. On UNIX, a forward slash "/" is used, such as /usr/bin/perl, on Windows it is a backslash, such as c:Apachein. In general, in some Apache and PHP directives, both types of directory separators work: forward (/) and reverse () , but since both Apache and PHP were originally developed under UNIX, using their "native" format, you can avoid a number of problems . Therefore, it is recommended to write the paths in the configuration files (httpd.conf and php.ini) separated by a slash in the UNIX format - "/". For example:

ScriptAlias ​​"/php_dir/" "c:/php/"

httpd.conf file directives

port

Port 80

Sets the TCP port that Apache uses to establish a connection. The default is port 80.

Note

The only reason to use a non-standard port is if you don't have permission to use the standard port. When using a non-standard port, for example 8080, the port number must be specified in the address, for example: http://localhost:8080/.

ServerAdmin

ServerAdmin [email protected]

Contains the e-mail address of the web server administrator, which will be displayed in case of server operation errors.

ServerName

ServerName myserver

Contains the computer name for the server.

ServerRoot

ServerRoot "C:/Apache2"

Points to the directory containing the Apache web server files.

Note

Don't confuse the ServerRoot directive with the DocumentRoot directive, which specifies the directory for the Web site's files.

DocumentRoot

DocumentRoot "c:/apache2/htdocs"

Specifies the directory where the web site files are located.

Container

The scope of directives within this container is for all files and subdirectories within the DocumentRoot.


Options FollowSymLinks Includes Indexes
AllowOverride All

  • The AllowOverride directive set to All allows you to override the values ​​of the main httpd.conf configuration file in .htaccess files.
  • The Options FollowSymLinks directive allows Apache to follow symbolic links.
  • The Options Includes directive allows the implementation of SSI (Server Side Includes) directives in the code of the web site pages.
  • The Options Indexes directive specifies that the contents of a directory should be returned if there is no index file.

DirectoryIndex

DirectoryIndex index.html index.phtml index.php

Contains a list of index files that should be displayed when accessing a directory without specifying a file name (for example, http://localhost/test/).

AddDefaultCharset

AddDefaultCharset windows-1251

Sets the default encoding if no encoding is set in the header of the HTML document. You may also need to specify the KOI8-R encoding value.

Create virtual hosts

You can install multiple websites on one Apache web server. This server function is called virtual hosting. Below we will consider the creation of virtual nodes based on names. Virtual hosts are usually located at the end of the httpd.conf file.

First you need to specify which IP address is used for virtual hosts.



# Virtual host directives

httpd.conf file. Container


ServerAdmin [email protected] _domain.com
DocumentRoot c:/www/mysite
ServerName www.mysite.ru
ServerAlias ​​www.site.ru www.host2.ru
ErrorLog logs/mysite-error.log
CustomLog logs/mysite-access.log common

Consider the virtual host directives:

  • DocumentRoot indicates the directory where the files (pages) of this virtual node (WEB site) are located
  • ServerName specifies the name of the virtual host by which it can be accessed. In this case, at http://www.mysite.ru/.
  • ServerAlias ​​contains virtual host name aliases. In this case, the virtual host can also be accessed using the names: http://www.site.ru/ and http://www.host2.ru/.
  • ErrorLog and CustomLog specifies the server log names for this virtual host.

Containers are usually placed one after the other at the end of the httpd.conf file.

httpd.conf file. Setting up virtual hosts

NameVirtualHost 127.0.0.1:80

# Virtual host directives 1


# Virtual host directives 2


# Virtual host directives 3

Note

Apache needs to be reloaded for changes to the httpd.conf file to take effect.

In order to address virtual hosts by their names, they should be registered in the DNS server databases. If you are using Apache to test files on the local machine, then the names of your virtual hosts should be written in the hosts file. For Windows 2000 and XP, it is located in the C:WindowSystem32Driversets directory. The hosts file contains entries like:

Format of hosts file entries

127.0.0.1 www.mysite.ru
127.0.0.1 www.site.ru
127.0.0.1 www.host2.ru

Installing and configuring PHP

To install PHP, create a c:/php directory and place the files from the distribution zip archive in it. After that, you should rename the php.ini-dist configuration file to php.ini and copy it to the Windows directory.

Installing PHP as a module

Installing PHP as a module improves performance slightly because the PHP module is loaded once when the Web server is started.

Comment

When PHP is installed as a module, the settings from php.ini are read once when the Web server is started. Therefore, when making changes to php.ini, you must restart Apache in order to changes made entered into force.

To install PHP, open the main Apache configuration file httpd.conf for editing and remove the comment characters from the following lines, changing them if necessary:

httpd.conf file. Connecting PHP as an Apache module


LoadModule php5_module c:/php/php5apache2.dll

Note

Installing PHP as a CGI Application

When installing PHP as a CGI application, the PHP interpreter will be loaded every time the PHP script is called. As a result, there may be some degradation in performance. If PHP is installed as CGI, then Apache does not need to be reloaded when making changes to the php.ini file, as the settings are read each time the PHP script is executed. Installing PHP as a CGI speeds up making changes to the PHP configuration a bit because it doesn't require a restart of the WEB server.

Note

When installing PHP, some headers will stop working as CGI, for example, you will not be able to organize user authorization means of PHP. Authorizations can only be implemented by means of Apache itself using .htaccess files.

To install PHP, open the main configuration file httpd.conf for editing, find the commented PHP connection lines in it and change them as follows:

httpd.conf file. Connecting PHP as CGI

AddType application/x-httpd-php phtml php

Options ExecCGI

ScriptAlias ​​"/php_dir/" "c:/php/"
Action application/x-httpd-php "/php_dir/php-cgi.exe"

Note

Replace the c:/php directory with your PHP installation directory.

PHP configuration (php.ini file)

Since you will most likely be busy testing your Web applications on your local machine, you need to set up the php.ini configuration file properly. Find the error_reporting directive and set it to the following value:

This value will configure PHP in such a way that all errors will be displayed when running PHP scripts, and "remarks" will be ignored. You also need to make sure that the display_errors directive is enabled:

display_errors = On

If this directive is disabled (Off), then error messages will not be displayed in the browser window, and if an error occurs in the code, you will be guessing in front of a virgin white window - what would that mean.
It is also necessary to ensure that the variables_order directive has the following value:

Variables_order = "EGPCS"

The letters here mean the following:
E - environment variables
G - variables transmitted by GET method(G)
P - variables transferred via the POST method (P)
C - Cookies
S - sessions
The absence of any of the letters will not allow you to work with the corresponding variables.

The next directive that may need tweaking is register_globals. If this directive is enabled

Register_globals = On

then the variables passed by the GET, POST, cookies and sessions can be used in a PHP script, accessing them just like regular $someone variables.
If this directive is disabled

Register_globals = Off

then such variables can only be accessed using superglobal arrays ($_POST, $_GET, etc.).
Directive register_long_arrays allows using superglobal arrays in the old format ("long" - $HTTP_GET_VARS, $HTTP_POST_VARS, etc.)

Register_long_arrays = On

Now we need to set up the index file. If you type http://localhost/ instead of http://localhost/index.html in the browser window. The server will still provide index.html to the browser since this file is an index file and is looked up in the directory first unless a specific file is specified. Now we need to configure http.conf so that the Apache web server reacts to index.php files in the same way. To do this, find the DirectoryIndex directive in http.conf and change it as follows:

DirectoryIndex index.html index.html.var index.php

After that, you need to restart the Apache server, and in the root directory of the virtual host ("C: / www / scripts") create a trial PHP file(index.php):

phpinfo();
?>

If the configuration is successful, accessing http://localhost/index.php will display a purple table with the current PHP settings, which is returned by the phpinfo() function.
Thus, we have configured a bunch of Apache and PHP, and we can proceed to setting up MySQL. Unzip the MySQL distribution to a temporary directory and run the installer. You can control the operation of the MySQL server in the same way as Apache, using the Windows services management console.

MySQL connection

A detailed method for connecting the MySQL extension to PHP is described in the article at the link:.

If MySQL server is already installed on your machine, then the next step is to php setup to work with MySQL databases.

Open the php.ini file for editing from the Windows directory. To connect the MySQL extension library, you need to remove the comment character; (semicolon) from the line:

Extension=php_mysql.dll

Also check the value of the extension_dir directive

Extension_dir="c:/php-5.0/ext"

It should point to the directory where PHP extensions are stored. Directory separators are recommended to be written in UNIX format (/) - backslash. However, if all else fails, just roll back the value of the extension_dir directive, and copy the php_mysql.dll library to the root C:/php-5.0/ - in most cases this should help.

If PHP is included as a module, then you also need to copy the libmysql.dll library from the PHP installation directory to the C:/Windows/System32 system directory. For the changes to take effect, restart Apache.

To check if MySQL is working, restart the Apache server and create a test script with the following code:

$dblocation = "127.0.0.1" ;
$dbname = "test" ;
$dbuser = "root" ;
$dbpasswd = "" ;

$dbcnx = @ mysql_connect ($dblocation , $dbuser , $dbpasswd );
if (! $dbcnx )
{
echo "

Sorry, mySQL server is not available

" ;
exit();
}
if ( [email protected]
mysql_select_db ($dbname , $dbcnx ))
{
echo "

Unfortunately the database is not available.

"
;
exit();
}
$ver = mysql_query("SELECT VERSION()");
if(! $ver )
{
echo "

Request error

"
;
exit();
}
echo
mysql_result($ver , 0 );
?>

If MySQL is successfully integrated into the Apache and PHP bundle, accessing the check script will display the version of the MySQL server in the browser window.

New versions of MySQL (starting from 4.1.0) have changed the way they work with national encodings, so old code can cause question marks "??????????" to appear in the database table. instead of Russian text. To prevent this from happening at the beginning of the PHP script, after establishing a connection to the database, place the following lines:

mysql_query( "set character_set_client="cp1251"");
mysql_query( "set character_set_results="cp1251"");
mysql_query( "set collation_connection="cp1251_general_ci"");
?>

Installing PHP extensions

Lastly, you may need to configure some PHP extensions, they are configured in the same way as MySQL.

So, in order to connect the GDLib graphic library in php.ini, you need to uncomment the line:

Extension=php_gd2.dll

After that, check the presence of this library in the c: phpext folder. After making changes to php.ini, restart the server. To quickly check if the library is connected, run the phpinfo() function. If everything is in order, then in the table that is displayed by the phpinfo () functions, the section " gd

Using the deprecated php.exe name used in earlier versions instead of php-cgi.exe may also result in an error:

403 Forbidden You don't have permission to access /__php_dir__/php.exe/test.php on this server

HTML files run but PHP scripts don't

When PHP is not configured, when accessing files with the php extension, for example: http:/localohost/index.php, a window opens with a request to download such a file. This indicates that the processing of files with the php extension is not configured. Check the httpd.conf file for the existence of the following line:

AddType application/x-httpd-php phtml php

Notice: Undefined variable...

On a new, freshly installed PHP, you will often see messages like:

Notice: Undefined variable: msg in C:/Main/addrec.php on line 7

error_reporting = E_ALL & ~E_NOTICE

MySQL not connecting

Sometimes there are problems installing MySQL. It should be checked whether MySQL is started as a service each time the system is started. To do this, open the services console:

Start | Setting | Control panel | Administration | Services

find MySQL there - run it. In order for the server to start every time the system boots, right-click on the service and select "Properties" - in the drop-down list "Startup type" that opens, select "Auto".

If, when starting Apache and when accessing scripts, a message is displayed about the impossibility of loading the php_mysql.dll library.

PHP startup: Unable to load dynamic library c:/php/ext/php_mysql.dll
- the specified module was not found

Then again check the instructions from the section that describes how to connect to the PHP library for working with MySQL. Are you using the "correct" version of the php_mysql.dll file (for the version of PHP that is installed on the system)?
Versions of the php_mysql.dll file differ between PHP versions, although they have the same name.

  • Using Windows format directory separators (backslash): c:apache/bin. For reliable operation, UNIX delimiters (forward slashes) should be used, for example: c:/apache/bin.
  • The existence of several php.ini configuration files on the machine, or the absence of such a file. Desired file php.ini should be in Windows directories. Search your computer's disks, find any extra versions of files and delete them.
  • Any questions you may have about installing the Apache + PHP + MySQL bundle, you can ask on our forum dedicated to installing and configuring Apache, PHP and extension libraries.

    We select the latest version (at the time of this writing - 2.2.17) and go to the list of distributions. On your home computer, you are unlikely to need SSL, so download the version Win32 Binary without crypto (no mod_ssl) (MSI Installer).

    Now run the installer (the user must have administrator rights). At the beginning, nothing interesting - just a welcome screen:

    The second step is to agree to the terms of the license:

    The third stage is a few introductory words from the developers. Immediately click Next:

    Fourth stage. Here you need to enter data in 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. Below the text boxes, one of the most important settings is to install Apache as a service or as a normal program. Select "for All Users, on port 80, as a Service - Recommended" - install as a service:

    Type of instalation. Choose Custom (selective):

    Sixth stage. Choice of components and installation location. I left all the defaults:

    Seventh stage. Everything is ready for installation. Click Install:

    We complete the installation (Finish):

    Installation completed. An Apache icon will appear in the tray, with which you can quickly stop / start the service:

    We check the functionality. Open a browser and enter http://localhost/ in the address bar. If everything is correct, a page should open that says It works!

    In order for the server to be accessible not only on the local computer, but also from outside, it is necessary to open TCP port 80 in the Windows firewall for input.

    Opening a Port in Windows Firewall

    Open Start -> Control Panel -> System and Security -> Windows Firewall. In the left column, click on the "Advanced Options" link. In the window that opens, also in the left column, click on "Rules for incoming connections" and then in the right column "Create a rule ...":

    The New Rule Wizard opens. Select rule type "For port":

    protocols and ports. TCP protocol. Below, select the option "Defined local ports", and enter the port number - 80 in the text field on the right:

    Action. Select "Allow connection":

    Profile. We leave it by default (all three options are checked: domain, private, public):

    In the end, enter the name of the created rule. For example Apache Web Server:

    That's all. Click Done. Now you can try to connect from another computer.

    I remind you that for connections to the server, not only from local network, but also from the Internet, on the router (if any), you need to configure port forwarding on the 80th port (port forwarding or it is often called a virtual server).

    PHP installation (manual)

    Download the latest version of PHP (5.3.5 at the time of writing) from the site: http://windows.php.net/download/ . There are several versions available here:

    1. VC9 x86 Non Thread Safe - for installation on IIS in FastCGI mode.
    2. VC9 x86 Thread Safe - ???
    3. VC6 x86 Non Thread Safe - for installation on Apache in CGI/FastCGI mode.
    4. VC6 x86 Thread Safe- for installation on Apache in module mode - our choice.

    Because we started the installation in manual mode, download the zip-archive.

    Extract the contents of the archive into the installation directory. I chose C:\Program Files\PHP.

    Let's go to this directory. At the root of the installation you will 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 that in the settings for developers, displaying errors is allowed, while for production systems, displaying errors is disabled for security reasons.

    So, select the file you need (I chose php.ini-development), open it and save it in the same folder under the name php.ini. This operation can be done in a regular notepad, but it's still better to use a more comfortable editor, such as notepad2 .

    Now a few changes need to be made to php.ini:

    1. Find the extension_dir option (search for CTRL+F) and change the ext folder path to match the PHP installation path. For me it looks like this: extension_dir = "c:\program files\php\ext"
    2. Find the upload_tmp_dir option. Here you need to specify the path to the temporary folder. I chose c:\windows\temp. All together: upload_tmp_dir = "c:\windows\temp"
    3. Find the session.save_path option. Here you also need to specify the path to the temporary folder: session.save_path = "c:\windows\temp"
    4. Go to the Dynamic Extensions section. Here you need to uncomment the lines (remove the semicolon at the beginning) corresponding to the PHP modules that you need to work with. A basic set of modules might look something like this: ;extension=php_bz2.dll ;extension=php_curl.dll ;extension=php_fileinfo.dll extension=php_gd2.dll ;extension=php_gettext.dll ;extension=php_gmp.dll ;extension=php_intl.dll ; extension=php_imap.dll ;extension=php_interbase.dll ;extension=php_ldap.dll extension=php_mbstring.dll extension=php_exif.dll ; Must be after mbstring as it depends on it extension=php_mysql.dll extension=php_mysqli.dll ;extension=php_oci8.dll ; Use with Oracle 10gR2 Instant Client ;extension=php_oci8_11g.dll ; Use with Oracle 11g Instant Client =php_pdo_sqlite.dll ;extension=php_pgsql.dll ;extension=php_phar.dll ;extension=php_pspell.dll ;extension=php_shmop.dll ;extension=php_snmp.dll ;extension=php_soap.dll extension=php_sockets.dll ;extension=php_sqlite. dll extension=php_sqlite3.dll ;extension=php_sybase_ct.dll ;extension=php_tidy.dll ;extension=php_xmlrpc.dll extension=php_xsl.dll extension=php_zip.dll

    Now let's move on to the Apache settings.

    Open the Apache installation folder (by default C:\Program Files\Apache Software Foundation\Apache2.2\). Open the conf folder. Open the httpd.conf file.

    Go to the end of the file and add the following lines there:

    # Charset AddDefaultCharset windows-1251 # PHP LoadModule php5_module "c:\program files\php\php5apache2_2.dll" PHPIniDir "c:\program files\php" AddType application/x-httpd-php .php

    The path to the php folder is the one you chose during the installation process.

    In the same file we find the following lines:

    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. If the service restarts, that's a good sign. If not, look for errors in the configuration files. Check all paths carefully.

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

    Now open http://localhost/ in your browser. If everything is fine, you will see a similar page:

    If you see a page that says "It works!", try refreshing the page with CTRL+F5.

    Installing MySQL

    Moved to a separate article.

    Computer