Installing the Apache web server. Installation of Apache server, MySQL and PHP interpreter


Installing a web server on Linux:

  • If you have Ubuntu, then the article “How to install Apache web server with PHP 7, MariaDB/MySQL and phpMyAdmin (LAMP) on Ubuntu 16.10” is suitable for you.
  • If you have Arch Linux, then the article “Installing LAMP (Linux, Apache, MySQL/MariaDB, PHP7 and phpMyAdmin) in Arch Linux / BlackArch” is suitable for you.

Local server Very useful tool. It will definitely be useful for webmasters, PHP programmers, and penetration testers. All programs included in typical installation web servers are free, they all have open source. A local web server consumes minimal resources and is actually not difficult to install and configure.

This instruction will tell you how to install local web server without use ready-made assemblies. This method has its advantages. The most important of them are: full control on what you install; opportunity to use the most latest versions software.

If you follow the instructions exactly, then everything will definitely work for you! Except for those who have Windows XP - if you like this operating system, then special instructions have been made for you.

I will show an example of installation on Windows 10, but if you have a different Windows version, then don’t let this bother you - the procedure is identical everywhere. I will download the latest (most recent) versions of the programs at the time of writing. If by the time you read, new versions will be released, then download them.

Installation steps:

You may also find it useful:

1. Preparation (downloading programs included in the server, creating the server structure)

We need:

  • Apache(directly web server)
  • PHP- work environment PHP programs(required by almost all websites)
  • MySQL- database management system (required by most websites)
  • phpMyAdmin- Very handy tool for database management

The official website of the Apache developers is httpd.apache.org. You can download Apache from this site. But official version compiled using an old compiler, for this reason it does not work with new ones PHP versions. PHP authors recommend Apache from apachelounge.com/download. Therefore, for this instruction, we download Apache from the site apachelounge.com/download.

If you have a 64-bit version of Windows, then you can choose both 64-bit and 32-bit versions of components. The main rule is that all components must be of the same bit size. If you have a 32-bit version of Windows, then all components must be 32-bit. This does not apply to phpMyAdmin, which is written in PHP language. For PHP programs, the concept of bit depth is not applicable.

Free MySQL version called MySQL Community Server. It can be downloaded on the page. There is an executable installer on this same page, but I recommend downloading the ZIP archive. On the download page we are asked to register or log in to an existing one. account- but this is not necessary. Just click on the link " No thanks, just start my download" Pay attention to the bit depth.

We also need a C++ Redistributable file Visual Studio 2017, i.e. Visual C++ redistributable component for Visual Studio 2017 (or any other later), you can download it on the official Microsoft website using the link (direct link to download the 64-bit version; direct link to download the 32-bit version). This file is needed for the web server. And MySQL requires Visual C++ Redistributable Packages for Visual Studio 2015. It can be downloaded from .

So, I downloaded the following files:

  • httpd-2.4.29-Win64-VC15.zip
  • php-7.2.0-Win32-VC15-x64.zip
  • mysql-8.0.11-winx64.zip
  • phpMyAdmin-4.7.6-all-languages.zip
  • vc_redist.x64.exe
  • vcredist_x64.exe

Install files vc_redist.x64.exe And vcredist_x64.exe.

2. Create a web server structure

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

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 the directory data and create subfolders there D.B.(for databases) and htdocs(for websites).

Go to the directory C:\Server\data\DB\ and create an empty folder there data.

3. Installing Apache 2.4

The contents of the downloaded archive (more precisely, only the directory Apache24), unpack into C:\Server\bin\.

Go to the directory c:\Server\bin\Apache24\conf\ and open the file httpd.conf any text editor.

In it we need to replace a number of lines.

Define SRVROOT "c:/Apache24"

Define SRVROOT "c:/Server/bin/Apache24"

#ServerName www.example.com:80

ServerName localhost

DocumentRoot "$(SRVROOT)/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: # AllowOverride 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

Save and close the file. All, Apache setup completed! A description of each changed directive can be found on this page.

Open command line(this can be done by pressing the Win+X keys simultaneously). Select there Windows PowerShell(administrator) and copy there:

C:\Server\bin\Apache24\bin\httpd.exe -k install

If a request is received from the firewall for Apache, click Allow.

Now enter into the command line:

C:\Server\bin\Apache24\bin\httpd.exe -k start

And press Enter.

Enter root as the username. Leave the password field empty. If everything is done correctly, then everything should look like this:

7. Server use and data backup

In the catalog c:\Server\data\htdocs\ create folders and files, for example:

c:\Server\data\htdocs\test\ajax.php - this file, accordingly, will be available at http://localhost/test/ajax.php, etc.

To create a complete backup of all sites and databases, just copy the directory C:\Server\data\.

Before updating modules, make a backup of the folder bin- in case of problems, you can easily roll back to previous versions.

At reinstallation server or when updating it, you need to reconfigure configuration files. If you have copies of these files, the process can be significantly speeded up. It is advisable to backup the following files:

  • c:\Server\bin\Apache24\conf\httpd.conf
  • c:\Server\bin\mysql-8.0\my.ini
  • c:\Server\bin\PHP\php.ini
  • c:\Server\data\htdocs\phpMyAdmin\config.inc.php

All settings are stored in them.

8. Additional PHP setup

PHP is now a very powerful, flexible, user-friendly tool. On local computer it can be used to solve a variety of problems that are not necessarily related to the generation of Web pages. When solving extraordinary problems, you may run into restrictions set in the settings. These settings are contained in the php.ini file (c:\Server\bin\PHP\php.ini). Let's look at some of them:

Memory_limit = 128M

sets maximum amount memory that the script can use

Post_max_size = 8M

sets the maximum amount of data that will be accepted when sending POST method

;default_charset = "UTF-8"

sets the encoding (by default, the line is commented out)

Upload_max_filesize = 2M

the maximum size of a file uploaded to the server. Initially installed very small size- only two megabytes. For example, when loading a database into phpMyAdmin, you will not be able to upload a file larger than 2 megabytes until this setting item is changed.

Max_file_uploads = 20

maximum number of files to upload at one time

Max_execution_time = 30

maximum execution time for one script

Changing these settings is completely optional, but it is useful to know about them.

9. Additional settings for phpMyAdmin

We have already configured phpMyAdmin and for most people the basic functionality is enough. However, on home page phpMyAdmin there is an inscription: “Additional features of phpMyAdmin are not fully configured, some functions have been disabled.”

New features are:

  • showing relationships between (related) tables;
  • adding information about tables (starting from version 2.3.0 you can describe in a special table ‘table_info’ which column will be shown in the tooltip when moving the cursor over the associated key);
  • creating a PDF diagram (starting from version 2.3.0 you can create PDF pages, showing the relationships between your tables);
  • display column comments (since version 2.3.0 you can make a comment describing each column for each table. And they will be visible in " preview for print". Since version 2.5.0, comments are used on own pages tables and in view mode, appearing as tooltips above columns (property tables) or embedded in the table header in view mode. They can also be shown in the table dump);
  • create bookmarks (since version 2.2.0, phpMyAdmin allows users to bookmark queries. This can be useful for frequently used queries);
  • history of SQL queries (starting from version 2.5.0 you can save your history of all SQL queries, which were made through the phpMyAdmin interface);
  • designer (starting from version 2.10.0, the Designer tool is available; it allows you to visually manage relationships between tables);
  • information about recently used tables;
  • customizing the interface of frequently used tables;
  • tracking (starting from version 3.3.x, a tracking mechanism is available. It helps you track every SQL command that was executed by phpMyAdmin. Recording of data manipulation and command recording is supported. Once enabled, you will be able to version tables);
  • user settings (starting from version 3.4.x, phpMyAdmin allows users to set most settings and save them in the database);
  • custom menus (starting from version 4.1.0 you can create user groups that will only have access to assigned menu items. A user can be assigned to a group and will only see menu items available to their group);
  • hide/show navigation items (starting from version 4.1.0 you can hide/show items in the navigation tree).
  • and others

Now we will configure these additional features fully. Go to the link http://localhost/phpmyadmin/chk_rel.php and click "Create database". After this, all new features will be activated.

A few screenshots of the new features:

1) Designer

2) Tracking

10. Installation of a mail plug

In the C:\Server\bin\ directory, create a new directory called Sendmail. Now in this directory create a file sendmail.php with the following content:

#!/usr/bin/env php

Open the PHP configuration file, it is located here C:\Server\bin\PHP\php.ini. And add one line there:

Sendmail_path = "C:\Server\bin\PHP\php.exe C:\Server\bin\Sendmail\sendmail.php --dir C:\Server\bin\Sendmail\emails"

Save the file and restart the server. Great, now all sent emails will be saved in the directory C:\Server\bin\Sendmail\emails\

Letters will have the extension .eml and they can be opened, for example, by the program Thunderbird. Or a regular text editor.

11. Adding a PHP directory to PATH on Windows

If this is not done, there may be problems with some PHP modules, including php_curl.dll, php_intl.dll, php_ldap.dll, php_pdo_pgsql.dll and php_pgsql.dll. At least, every time the server starts, the following appears in the logs:

PHP Warning: PHP Startup: Unable to load dynamic library "C:\\Server\\bin\\PHP\\ext\\php_curl.dll" - \xef\xbf\xbd\xef\xbf\xbd \xef\xbf\ xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\ xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\ xbf\xbd\xef\xbf\xbd.\r\n in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library "C:\\Server\\bin\\PHP\\ext\\php_intl.dll " - \xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef \xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd.\r\n in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library " C:\\Server\\bin\\PHP\\ext\\php_ldap.dll" - \xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\ xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\ xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd.\r \n in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library "C:\\Server\\bin\\PHP\\ext\\php_pdo_pgsql.dll" - \xef\xbf\xbd\xef\xbf \xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef \xbf\xbd\xef\xbf\xbd\xef\xbf\xbd.\r\n in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library "C:\\Server\\bin\\PHP\ \ext\\php_pgsql.dll" - \xef\xbf\xbd\xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\ xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\ xef\xbf\xbd \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd.\r\n in Unknown on line 0

To avoid these warnings, you need to add the path to PHP to your system environment variables.

Click the Start button (or whatever it's called on Windows 10?), start typing " Changing system environment variables» and open the corresponding settings window.

There click " Environment Variables»:

In the window " System Variables» find and click on Path, then click " Change»:

Move the entry to the top:

Close all windows and save your changes.

Restart the server.

12. Freeze, slow traffic and/or server error Asynchronous AcceptEx failed

If your server “freezes” even without load - it does not show web pages until restarted, and in the server logs there are errors Asynchronous AcceptEx failed:

AH00455: Apache/2.4.9 (Win64) PHP/5.5.13 configured -- resuming normal operations AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:42:59 AH00094: Command line: "c:\\Server\\ bin\\Apache24\\bin\\httpd.exe -d C:/Server/bin/Apache24" AH00418: Parent: Created child process 4952 AH00354: Child: Starting 64 worker threads. (OS 64)The specified network name is no longer available. : AH00341: winnt_accept: Asynchronous AcceptEx failed. (OS 64)The specified network name is no longer available. : AH00341: winnt_accept: Asynchronous AcceptEx failed. (OS 64)The specified network name is no longer available. : AH00341: winnt_accept: Asynchronous AcceptEx failed. (OS 64)The specified network name is no longer available. : AH00341: winnt_accept: Asynchronous AcceptEx failed. (OS 64)The specified network name is no longer available. : AH00341: winnt_accept: Asynchronous AcceptEx failed. (OS 64)The specified network name is no longer available. : AH00341: winnt_accept: Asynchronous AcceptEx failed.

Then add to the Apache configuration file:

AcceptFilter http none AcceptFilter https none EnableSendfile off EnableMMAP off

13. Configuring cURL in the Apache web server on Windows

If you don't know what cURL is, then you don't need it. Those. Feel free to skip this step.

cURL is a console utility that allows you to exchange data with remote servers using a very large number of protocols. cURL can use cookies and supports authentication. If a web application requires cURL, then this must be specified in the dependencies. Many popular applications do not require cURL, for example phpMyAdmin and WordPress do not need to configure cURL.

If cURL is not configured correctly, you will receive errors:

Fatal error: Call to undefined function curl_multi_init() in ...

curl error: SSL certificate problem: unable to get local issuer certificate

To make cURL work in Apache on Windows you need:

1) Be sure to add the PHP directory to PATH (system environment variables). How to do this is stated just above:

2) In a file C:\Server\bin\PHP\php.ini line should be uncommented extension=curl

This is usually not required, but you can make a backup copy of the server binary (executable) files if you wish. All these files are located in the folder C:\Server\bin\. These are Apache, MySQL and PHP - i.e. programs that are responsible for the operation of the server, but which we can download from official websites and configure again at any time.

If you want to make a backup copy of them (for example, before upgrading the server), then stop the services:

C:\Server\bin\Apache24\bin\httpd.exe -k stop net stop mysql

And copy the folder to a safe place C:\Server\bin\.

By the way, you can copy the entire server, i.e. folder C:\Server\- in this case, you will simultaneously get a backup copy of both executable files and data (databases, websites).

When the copying is complete, start the services again:

C:\Server\bin\Apache24\bin\httpd.exe -k start net start mysql

15. Server update

All components that make up the web server are actively being developed and new versions are regularly released. When a new version is released, you can update one component (for example, PHP), or several at once.

Deleting a server

If you no longer need the server, or you want to install it again, stop the services and remove them from autostart by sequentially executing on the command line:

C:\Server\bin\Apache24\bin\httpd.exe -k stop c:\Server\bin\Apache24\bin\httpd.exe -k uninstall net stop mysql c:\Server\bin\mysql-8.0\bin\ mysqld --remove

Delete the server files; to do this, delete the folder C:\Server\. Warning, this will delete all databases and your sites.

How to protect your Apache web server from hacking on Windows

With PHP (with choice of versions), with MySQL and phpMyAdmin. This site is hosted exactly on it: responsive and qualified technical support, installation of WordPress and other web applications in one click, as a gift when paying for a year, free site transfer. When ordering hosting + 1 month free (promotional code b33e0e2f).

or install a bunch of servers yourself

Tested on Windows Vista SP1, Vista Ultimate, Windows 7

Your actions:

  1. Download the following distributions for free from official websites:

    Setting up the PHP interpreter

    1. Double-click the php.ini file from the C:\server\php\ folder.
    2. In the "Paths and Directories" section there should be a line extension_dir ="C:\server\php\ext" .
    3. In the "Dynamic Extensions" section, find; Be sure to appropriately set the extension_dir directive. , at the bottom of this line place:
      extension=php_gd2.dll
      extension=php_mbstring.dll
      extension=php_mysql.dll
      extension=php_mysqli.dll
      extension=php_pdo.dll
      extension=php_pdo_mysql.dll
      extension=php_sqlite.dll
    4. Somewhere at the end of the file, find the line; End: and delete everything that follows it.

    Save the modified file there.

    Once you've finished editing the files, create a www folder in the server folder and a cgi-bin folder in the www folder. Restart your computer. As a result, a green triangle appeared in the tray, in the server status instead of a red square; if not, and an error warning window is displayed, then the change in the httpd.conf file was inaccurate and you will have to carefully check everything, slash slopes, quotes, and so on.

    www is the root directory of the local server, this is where you should save all documents (folders, pages, images, scripts and other files) of your site.

    Testing the PHP interpreter

    Create a new file in an editor (Notepad2 or Notepad+) and write the code:

    echo phpinfo();
    ?>

    Save the file in the C:\server\www\ directory as index.php . In your browser, type http://127.0.0.1 or http://localhost/ ⇒ the table should be shown:


    I succeeded! If you have any questions or suggestions, please write to the blog.

    We have a local server in conjunction with an interpreter and now we can learn PHP.

    Testing the connection to the MySQL database server

    Small script:

    $dblocation = "127.0.0.1" ;
    $dbname = "test" ;
    $dbuser = "root" ;
    $dbpasswd = "" ; /* Enter the password you entered when
    MySQL installation */
    $dbcnx = @mysql_connect ($dblocation, $dbuser, $dbpasswd);
    if (! $dbcnx )
    {
    echo "MySQL server is not available";
    exit();
    }
    if (!@
    mysql_select_db ($dbname, $dbcnx))
    {
    echo "Database not available";
    exit();
    }
    $ver = mysql_query("SELECT VERSION()" );
    if(!$ver)
    {
    echo "Error in request";
    exit();
    }
    echo mysql_result ($ver, 0);
    ?>

    Save the script in the C:\server\www\ folder as mysql.php and type http://localhost/mysql.php in the browser ⇒ the serial number will be shown MySQL servers:

    5.5.12
    1. Download the database management manager distribution kit for free from the official website php-myadmin.ru, the latest stable version, file with the extension all-languages.zip.
    2. Unpack the archive into the phpmyadmin folder, and place it in the www folder.
    3. Download config.inc.php, extract from the archive and copy it to the phpmyadmin folder.
    4. Open config.inc.php , find the line $cfg["Servers"][$i]["password"] = "pass"; ⇒ instead of pass, specify the root password that you used when installing MySQL server⇒ save the file.
    5. In your browser, type http://localhost/phpmyadmin/ ⇒ the manager's title page will be shown:

    Having installed the above components, we received a complete local web server and everything necessary for organizing further work.

    Materials were used from the sites: dev.mysql.com | php.net | php-myadmin.ru

The web server is installed on a 64-bit Windows platform. Enterprise 1C server is also 64-bit, platform version 8.3.10.2561

  • The very first attempt to install Apache was using XAMPP. It didn't take off due to lack of skill.
  • The continuation was with IIS. Here, difficulties arose with launching 1C information databases, which were resolved by installing a 32-bit web extension of the enterprise 1C server, however, I wanted to get by with installing only a 64-bit platform. Discussion of error with IIS
  • According to the description from the article, I installed Apache 2.2, but the web server did not start by mistake

With Apache 2.4, everything finally worked out.

Description of installation step by step.

Step 1. Download the distribution

Step 4: Change the Windows path environment variable.

In the path environment variable you need to add the path to the Apache executable files C:\Apache24\bin

On Windows Server 2008 R2 and on Windows 7, on which I performed these steps, through the desktop icon Computer - System Properties - Advanced system settings - Environment Variables

Step 5. Install the C++ component

To do this, run the previously downloaded file VC_redist.x64.

I installed on Windows 7 Professional and on Windows Server 2008 R2.

I noticed that the vc libraries on 7 were installed in the C:\Windows\SysWOW64 folder, and on Server 2008 in the C:\Windows\System32 folder, although both systems are 64-bit.

As it turned out, it does not affect the operation of the web server.

On Windows 7 the operating system had to be restarted, on Windows Server 2008 - not.

Step 6. Installing Apache as services

Launch the command panel with administrator rights Start-Run-cmd, change the folder to C:\Apache24\bin , run

httpd.exe -k install

In the list of services - Start - Administration - Services - find the Apache 2.4 service - Launch it, set the startup type.

The web server installation is now complete..

Further steps are well described in the publication I linked to at the beginning

  • Checking that the web server is running - point your browser to http://localhost and see It works!
  • Set up a firewall for access from other computers
  • Publication of information base. I noticed here that after publication, when answering the question about restarting the web server, an automatic restart does not occur; the web server must be restarted manually.

An error was detected while using the web client

appears when opening an object from the list by double-clicking on the link. The workaround is to open the object from the context menu.

1.3) In the root of drive E: create two folders iSites (our sites will be located here) and iLogs (general server logs will live here).
1.4) In the G:\iSites folder we create two subdirectories localhost and testru and then each of them has its own www subdirectories, log and ssl

2) Now you need to download the Apache binaries. All! We've arrived! There are no more installers! Everything is like an adult :)

In order to download, go here http://httpd.apache.org/download.cgi and see something like this (depending on the date when you read this article of mine :)):

Currently the latest version of Apache is 2.4.18. After clicking on the specified link, we get here:

12.1) Unzip the contents of the archive into the D:\iServer\PHP directory

12.2) We will attach PHP to Apache as an Apache module. To do this, go to the catalog E:\iServer\Apache\conf, and add to the file httpd.conf at the end of a block of instructions LoadModule two lines:
LoadModule php7_module "D:/iServer/PHP/php7apache2_4.dll"
PHPIniDir "D:/iServer/PHP"

12.3) Find it in the file httpd.conf AddType instructions, at the end of this block we insert the instruction:
AddType application/x-httpd-php .php

12.4) Find in the file httpd.conf instruction block DirectoryIndex. And add it to the instructions DirectoryIndex file reference index.php. So that the final instructions look like this:
DirectoryIndex index.html index.php

12.5) In file httpd.conf to the section AddHandler add a line AddHandler application/x-httpd-php .php

12.6) Now it’s time to configure the php.ini file. To do this, rename or copy the file php.ini-production(in the catalog D:\iServer\PHP) to file php.ini.

12.7) In file php.ini uncomment the line extension_dir = "ext" and the extensions you need

12.8) Find the line in the php.ini file short_open_tag = Off. And we bring her to mind short_open_tag = On

12.9) Create in a directory E:\iSites\localhost\www phptest.php file and write the following code in it:
phpinfo();
?>

Save the file.

12.10) Stop and start Apache again through the Apache management console. After restarting Apache, you can open the Apache service management window by double-clicking on the tray icon. You should see the following window:

Please note that now with the Apache version, the PHP version is also indicated.

12.11) Testing the operation of PHP. Type in the browser http://localhost/phptest.php and we see the following picture and enjoy life. PHP worked:

12.12) Also for testing, let’s enable PHP functions for working with graphics. Edit the file D:\iServer\PHP\php.ini. Finding the line extension=php_gd2.dll and uncomment it. Restart Apache.

Create a file in the G:\iSites\localhost\www directory gdtest.php and enter the following code:

$pic=imagecreate(350,100);
$piccolor=imagecolorallocate($pic, 255,255,255);
$textcolor=imagecolorallocate($pic, 0,0,0);
$linecolor=imagecolorallocate($pic, 0,0,255);
$text="GD test successful - gdtest.php!";
imagerectangle($pic, 1.99, 349.0, $linecolor);
imagestring($pic,5,30,40, $text, $textcolor);
header("content-type: image/png");
imagepng($pic);
imagedestroy($pic);
?>

We enter the address http://localhost/gdtest.php in the browser and see:

If we don’t see it, then as usual we smoke the manual until we are completely clear :)

13) Now let's set it up rewrite_module, very useful thing :). In file httpd.con f uncomment the line

LoadModule rewrite_module modules/mod_rewrite.so


AllowOverride none
Require all denied

And replace the line in it AllowOverride None per line AllowOverride All
Then just below there will be just a line AllowOverride None it needs to be changed to AllowOverride All
This includes processing ALL ALL.htaccess settings in all directories.

Now we check the operation of the rewrite module. Restarting Apache

In the catalog E:\iSites\localhost\www create a file .htaccess and add one line to it

this line redirects from the file index.html to the site ya.ru

In the browser we simply type localhost and it should redirect us to the page ya.ru

If it works, then everything is configured correctly. Well, if not, then we look for where we messed up.

14) Install MySQL. Come here and download the installer mysql-installer-community-5.7.11.0.msi. It is worth noting that although the msi file is 32 bit, it installs both x32 or x64 versions depending on the platform . And so, click on it and the installation starts...

Then we see this and begin to select the components you need and remove the ones you don’t need...

I chose the following components:

Then click Advanced Options...

And select where MySQL server will be installed and where its databases will be located:

Click OK and Next and we see that the installer needs a redist for Workbench to work. But as he reports, he will try to install it himself

Click Execute and see:

Well, we set the redist... and now everything is fine with us

And click Execute...

It's time to configure MySQL...

Well, click Execute...

After clicking Finish, Workbench will start...

Let's connect to MySQL using it

If we see this, it means the server is installed and running. But Apache cannot work with it yet.

14.1) Let’s configure MySQL a little. By default, it stores temporary files on the system drive, which I think is not good. Therefore, we transfer temporary files to another location. To do this in the file E:\MySQLdb\my.ini in section add a line tmpdir=E:/MySQLtemp. Naturally, the E:\MySQLtemp directory must already be created. Restart the MySQL service and enjoy the view:

14.2) Checking the operation of MySQL (separately for now without connection to Apache and PHP). We give from the command line in the directory D:\iServer\MySQL\bin team

mysql.exe -h localhost -P 3306 -u root -p

enter the password and give the following command

show databases;

15) We attach MySQL to Apache, although it would be more accurate to say to PHP, but it is already attached to Apache. This is how the train turns out. So let's edit the file D:\iServer\PHP\php.ini . We find the lines in it
extension=php_mysqli.dll
extension=php_pdo_mysql.dll

and uncomment them. Then we find the line mysqli.default_port = and bring it to the form mysqli.default_port = 3306 . Next, we find the line mysqli.default_host = and bring it to the form mysqli.default_host = localhost

Restart Apache.

In the catalog E:\iSites\localhost\www create file mysqltest.php and enter the following code there:

try (
$DBH = new PDO("mysql:host=localhost", "root", "YOUR PASSWORD");

foreach($DBH->query("SELECT CURDATE()") as $row) (
echo "";
echo "";
}

}
catch(PDOException $e) (
echo $e->getMessage();
}
?>

Enter the address in the browser http://localhost/mysqltest.php and if everything was done correctly, then we see the current date. This means that PHP can work with MySQL.

Let's summarize. Currently we are running Windows Server 2008R2 x64 Apache 2.4 x64 + PHP 7.0.3 x64 + MySQL 5.7.11 x64. This whole thing took up enough space on drive D::

Compare with the free space on drive D: that was at the beginning.

Therefore, plan your disk space in advance.

Although service data (websites, logs and databases) still occupy almost nothing, over time they tend to grow. Therefore, it is better to keep them on a separate disk, just like services, so that neither one nor the other clogs the system disk.

16) Now all that remains is to make the Apache service work not under the system account, but under a regular user. By default, during installation, the Apache service is launched under the SYSTEM user, which has maximum rights in the system. This is not gud. Now we will correct this situation.

16.1) Create and configure an account under which we will run Apache.

  • create an iUser account and assign it a password that never expires
  • we check that it is included only in the users group
  • prohibit for the user iUser local login and set the right to work in operating system mode and login as a service through the gpedit.msc snap-in

  • We give the iUser account the right to write to the directories necessary for Apache to work:
    E:\iLogs– general Apache logs
    In the directories of site log files. In our case: E:\iSites\localhost\log And E:\iSites\testru\log
  • In the future, if you need write permissions to any folder or file on your site, then these permissions must be added. But most files on your site should not have write permission. And even more so for the .htacess file
  • Restarting the Apache2.2 service
  • Well, let’s check the work by going to http://localhost

If you did everything correctly, then everything should work.

17) And so everything works well for us locally. What if you try to connect to our web server over the network? And here’s a surprise :) No one will be able to connect, since on Windows Server 2003R2, by default, this port is closed by a firewall. Therefore, you need to create a rule that allows incoming connections to port 80.

18) We prohibit Apache from giving out its version and PHP version. This information can allow you to know for sure whether your version of Apache and PHP is vulnerable or not. It’s better to turn this off, since any, even the simplest scanner will show you this data:

By the way, here you can also see that our Location is http://ya.ru. This is exactly what our mod_rewrite did - another protection.

18.1) To prevent Apache from showing its version and the PHP version, do the following:

  • In the file, uncomment the line Include conf/extra/httpd-default.conf
  • In file D:\iServer\Apache\conf\extra\httpd-default.conf looking for a parameter ServerTokens and change its value from Full on Prod and restart Apache.

And now Apache only shows this:

Do you agree that this is already more pleasant :)?

For complete happiness, all that remains is to tell you how to attach Apache SSL certificates for virtual sites. But more on that in another article. Although I already wrote about this. But times change and now everything is a little different, but the essence has not changed.

Last update: 10/20/2017

Let's download the Apache web server package from http://www.apachelounge.com/. Let's select the latest version of the server. On the downloads page we can find two versions of the Apache package - for 64-bit systems and for 32-bit.

Before installing Apache, it should be noted that if our OS is Windows, then the package for C++ must be installed on the system, which can be found at the address for 64-bit and 32-bit.

After downloading the package from Apache, unpack the downloaded archive. In it we will find the folder directly with the web server files - the Apache24 directory. Let's move this directory to drive C so that the full path to the directory is C:/Apache24.

Now we need to install Apache as a Windows service. To do this, launch the Windows command line as an administrator and go to the web server directory using the command

httpd.exe -k install

If the installation is successful, the command line will display the message "The Apache2.4 service is successfully installed". The server will also be tested:

In my case, as shown in the picture above, Apache was unable to connect to port 80, which is the default in the configuration, since I have port 80 listening on another web server - IIS. This is one of the common problems when running Apache. To solve this, we need to either disable the IIS service or specify a new port for Apache. I will choose the second path.

After installation, we will configure the server to connect it with the previously installed PHP interpreter. To do this in the folder C:\Apache24\conf Let's find the httpd.conf file and open it in a text editor.

The httpd.conf file configures the behavior of the web server. We will not touch upon its descriptions, but will only make small changes that we will need to work with PHP.

First, let's find the line

Listen 80

This line indicates the listening port. The default is port 80. If there are no conflicts with ports, you can leave it as it is. I'll change the port to 8080.

#ServerName www.example.com:80

and change to

ServerName localhost:8080

Now let's connect PHP. To do this, find the end of the module loading block in the httpd.conf file LoadModule

//...................... #LoadModule watchdog_module modules/mod_watchdog.so #LoadModule xml2enc_module modules/mod_xml2enc.so

And at the end of this block we will add the lines

LoadModule php7_module "C:/php/php7apache2_4.dll" PHPIniDir "C:/php"

DocumentRoot "c:/Apache24/htdocs"

By default, the directory "c:/Apache24/htdocs" is used as the document storage. Let's replace this line with the following:

DocumentRoot "c:/localhost"

Let's change the paths of the files in which information about errors or site visits will be recorded. To do this, find the line

ErrorLog "logs/error.log"

And let's replace it with

ErrorLog "c:/localhost/error.log"

CustomLog "logs/access.log" common

And let's replace it with

CustomLog "c:/localhost/access.log" common

And we will also find the block and add two lines to it:

AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps

And at the end we will find the block :

DirectoryIndex index.html

And replace it with the following:

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

This is the minimum required configuration needed to work with PHP. To manage the server (start, stop, restart), we can use the utility that comes with the kit - . This utility can be found in the directory C:\Apache24\bin

Let's launch the utility. The ApacheMonitor icon will appear in the tray. Click on it and select Start in the context menu that appears.

If everything is configured correctly, the web server should start.

Now our task is to make sure that php is connected and working correctly. To do this, let's go to the c:/localhost folder, which we created to store documents, and add a regular text file to it. Let's rename it index.php and add the following content to it:

In this case, we have created a simple script that displays general information about PHP. Now let's access this script by typing the address in the browser bar http://localhost:8080/index.php

What happened here? When accessing a site on a local machine, http://localhost is specified as the address. Since we specified 8080 as the port, the port is also indicated in the address via a colon. If we used port 80, which is the default, then it would not need to be specified.

Then the name of the resource being accessed is indicated. In this case, the file index.php is used as a resource. And since the httpd.conf file specifies the directory as the web server document storage C:\localhost, then it is in this directory that the web server will search for the necessary files.

And since we indicated above during configuration that the file can be used as the main page index.php, then we can also access this resource simply http://localhost:8080/

This completes the installation and configuration of the Apache web server, and we can create our websites.







2024 gtavrl.ru.