Web Server on Windows 11 (Apache, MySQL, PHP and phpMyAdmin): step-by-step installation guide

Table of contents

1. What is a web server for Windows

2. Download web server (Apache, MySQL, PHP and phpMyAdmin) for Windows 11

3. Create the structure of the web server

4. Installing Apache 2.4

5. Installing and configuring MySQL 8.0

6. Installing and configuring PHP 8

7. Installing and configuring phpMyAdmin

8. Server usage and data backup

9. PHP tweaking

10. Additional configuration of phpMyAdmin

11. Setting up the mail plug

12. Adding PHP Directory to PATH on Windows

13. Setting up cURL in Apache Web Server on Windows

14. How to back up Apache data (websites and databases) on Windows

15. How to update the web server on Windows

16. How to protect the Apache web server from hacking in Windows

How to uninstall the web server


1. What is a web server for Windows

The web server itself is Apache – it can process requests from the user and send him the requested files, such as static HTML pages, pictures, files with CSS and JavaScript. Since this functionality is usually not enough and most users need support for dynamically created pages, PHP is connected to Apache as a web server module for these purposes. To store data, one or another database management system (DBMS) is used, usually MySQL or MariaDB. The DBMS is not an Apache or PHP module, it is a separate network service to which various programs can connect, it is important for us that PHP can work with MySQL.

These three components are the most typical of what is commonly referred to as a “web server”, although, again, the actual web server is just Apache. Quite often, phpMyAdmin is added to these three components. At its core, phpMyAdmin is a set of PHP scripts designed to make working with databases easier. phpMyAdmin is a web interface for working with databases.

In fact, you can add/enable other scripting languages to the web server, for example, Python, Perl, Ruby and others – the corresponding links will be given at the end of the article.

This is a step by step guide for installing a web server on Windows. Here it will be shown in detail how to install, configure and run Apache, MySQL, PHP and phpMyAdmin without using extraneous assemblies. This approach will allow you to have the latest versions of components and not worry about the security of running programs. After understanding how Apache modules work and connect, you can add any components you need, as well as customize it exactly to your needs.

2. Download web server (Apache, MySQL, PHP and phpMyAdmin) for Windows 11

On the download page, we are prompted to register or log into an existing account – this is optional. Just click on the link “No thanks, just start my download”.

We also need Visual C++ Redistributable for Visual Studio 2015-2022 (or any other later one), you can download it on the official Microsoft website at the link (direct download link for the 64-bit version; direct download link for the 32-bit version).

So, I have downloaded the following files:

  • httpd-2.4.52-win64-VS16.zip
  • php-8.1.2-Win32-vs16-x64.zip
  • mysql-8.0.28-winx64.zip
  • phpMyAdmin-5.1.2-all-languages.zip
  • VC_redist.x64.exe

Install the VC_redist.x64.exe file.

An important note when working with file extensions. If you use Windows Explorer to create and rename config files, remember that it doesn't show the file extension by default, so you may see my.ini, but it's actually my.ini.txt. Therefore, the server does not see this file and does not apply the settings from it, which leads to errors.

So when creating files:

3. Create the structure of the web server

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 C:\ drive, create the “Server” directory. In this directory, create 2 subdirectories: “bin” (for executable files) and “data”.

Go to the “data” directory and create subfolders “DB” (for databases) and “htdocs” (for websites) there.

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

Map of important folders that are mentioned in this manual:

C:.
└── Server
    ├── bin
    │   ├── Apache24
    │   │   └─── conf
    │   ├── mysql-8.0
    │   ├── PHP
    │   └── Sendmail
    ├── certs
    ├── data
    │   ├── DB
    │   │   └─── data
    │   └── htdocs
    │       └─── phpmyadmin
    └── manage

4. Installing Apache 2.4

Unzip the contents of the downloaded archive (to be more precise, only the Apache24 directory) to C:\Server\bin\.

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

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

Replace

Define SRVROOT "c:/Apache24"

with

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

replace

#LoadModule rewrite_module modules/mod_rewrite.so

replace

LoadModule rewrite_module modules/mod_rewrite.so

replace

#ServerName www.example.com:80

with

ServerName localhost

replace

    # 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

with

    # 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

replace

DocumentRoot "${SRVROOT}/htdocs"

with

DocumentRoot "c:/Server/data/htdocs"

replace

<Directory "${SRVROOT}/htdocs">

with

<Directory "c:/Server/data/htdocs">

and replace

DirectoryIndex index.html

with

DirectoryIndex index.php index.html index.htm

Save and close the file. That's it, Apache setup is complete!

Open a command prompt (this can be done by pressing the Win+x keys at the same time). Select there “Windows Terminal (Admin)”.

and copy there:

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

If you receive a request from the firewall, then click “Allow access”.

Now type in the command line:

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

and press Enter.

Now in the browser we type http://localhost/ and we see the following:

This means two things:

  • Apache running
  • There are no files in the c:\Server\data\htdocs\ directory.

You can play with it – add any html files to the directory – a full-fledged web server works.

5. Installing and configuring MySQL 8.0

Unpack the MySQL files into the bin​ directory (from the mysql-8.0.28-winx64.zip archive). Rename the mysql-8.0.28-winx64 folder to mysql-8.0​ (for brevity). By the way, the unpacked mysql-8.0 folder takes up about 800 megabytes!

We go into this folder and create the my.ini file there. Now open this file with any text editor.

Add the following lines there:

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
datadir="c:/Server/data/DB/data/"
default_authentication_plugin=mysql_native_password

Save and close it.

The setup is completed, but you still need to perform initialization and installation, for this we open the command line as an administrator and sequentially enter there:

C:\Server\bin\mysql-8.0\bin\mysqld --initialize-insecure --user=root
C:\Server\bin\mysql-8.0\bin\mysqld --install
net start mysql

At the end of this process, automatically generated files should appear in the C:\Server\data\DB\data\ directory:

The MySQL service will now start every time you turn on Windows.

6. Installing and configuring PHP 8

In the c:\Server\bin\ folder, create a PHP directory and copy the contents of the php-8.1.2-Win32-vs16-x64.zip archive into it.

In the c:\Server\bin\Apache24\conf\httpd.conf file, add the lines at the very end

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

Then restart Apache

c:\Server\bin\Apache24\bin\httpd.exe -k restart

In the directory c:\Server\data\htdocs\ create a file called i.php

Copy to this file:

<?php
phpinfo ();

In a browser, open the link http://localhost/i.php. If you see the same thing as in the picture, then PHP is working:

PHP 8 setup

PHP configuration takes place in the php.ini file. There is no php.ini in the zip archives intended for manual installation and for updates (this is done on purpose so as not to accidentally overwrite your file with your unique settings). But there are two others, which are called php.ini-development and php.ini-production. Any of them, when manually installed, can be renamed to php.ini and configured further. On localhost we will use php.ini-development.

Open the php.ini file with 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=bz2
;extension=curl
;extension=ffi
;extension=ftp
;extension=fileinfo
;extension=gd
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=ldap
;extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
;extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=oci8_19  ; Use with Oracle Database 19 Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop    

and replace it with:

extension=bz2
extension=curl
extension=ffi
extension=ftp
extension=fileinfo
extension=gd
extension=gettext
extension=gmp
extension=intl
extension=imap
extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=oci8_19  ; Use with Oracle Database 19 Instant Client
extension=odbc
extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=shmop  

now uncomment this group of lines:

;extension=soap
;extension=sockets
;extension=sodium
;extension=sqlite3
;extension=tidy
;extension=xsl

you should get:

extension=soap
extension=sockets
extension=sodium
extension=sqlite3
extension=tidy
extension=xsl

With these actions, we have enabled extensions. They may be needed in different situations for different scripts. Save the file and restart Apache.

7. Installing and configuring phpMyAdmin

Copy the contents of the phpMyAdmin-5.1.2-all-languages.zip archive to the c:\Server\data\htdocs\ directory. Rename phpMyAdmin-5.1.2-all-languages to phpmyadmin (for brevity)

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

<?php

/* Servers configuration */
$i = 0;

/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = '';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['nopassword'] = true;
$cfg['Servers'][$i]['AllowNoPassword'] = true;

/* End of servers configuration */

$cfg['blowfish_secret'] = 'HACKWARE.RU ==== WRITE DOWN WHAT YOU WANT HERE';
$cfg['DefaultLang'] = 'en';
$cfg['ServerDefault'] = 1;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

?>

In the browser we type http://localhost/phpmyadmin/

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

8. Server usage and data backup

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

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

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

Before updating modules, make a backup of the bin folder – in case of problems, it will be easy to roll back to previous versions.

When you reinstall the server or upgrade it, you must reconfigure the configuration files. If you have copies of these files, then the process can be greatly accelerated. It is recommended to back up 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.

9. PHP tweaking

PHP is currently a very powerful, flexible, user-friendly programming language and tool. On a local computer, it can be used to perform a variety of tasks that are not necessarily related to the generation of Web pages. When solving extraordinary tasks, you can run into the 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 the maximum amount of memory the script can use

post_max_size = 8M

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

;default_charset = "UTF-8"

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

upload_max_filesize = 2M

the maximum size of the file uploaded to the server. Initially set to a very small size – only two megabytes. For example, when uploading a database to 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

It is not necessary to change these settings, but it is useful to know about them.

10. Additional configuration of phpMyAdmin

We have already set up phpMyAdmin and for most of us the basic functionality is enough. However, the phpMyAdmin start page says ‘The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. Find out why.’.

New features are:

  • showing relationships between (related) tables;
  • adding information about tables (since 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 schema (starting from version 2.3.0 you can create PDF pages in phpMyAdmin 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 the "print preview". Since version 2.5.0, comments are used on native table pages and in view, showing as tooltips over columns (property tables) or embedded in the table header in view mode (they can also be shown in a 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 that were made through the phpMyAdmin interface);
  • designer (starting from version 2.10.0, the Designer tool is available; it allows you to visually manage the relationships between tables);
  • information about recently used tables;
  • customizing the interface of frequently used tables;
  • tracking (since version 3.3.x a tracking mechanism is available. It helps you trace every SQL command that was executed by phpMyAdmin. Recording of work with data and recording of commands is supported. After enabling, you can make versions of tables);
  • user settings (since version 3.4.x, phpMyAdmin allows users to set most of the 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 see only menu items available for his group);
  • hide/show navigation items (since version 4.1.0 you can hide/show items in the navigation tree).
  • other

Now we will configure these additional features in full. Go to http://localhost/phpmyadmin/index.php?route=/check-relations and click “Create a database named 'phpmyadmin' and setup the phpMyAdmin configuration storage there”.

After that, all new features will be activated.

Some screenshots of new features:

1) Designer

2) Tracking

11. Setting up the mail plug

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

#!/usr/bin/env php
 
<?php
/*  PHP.INI
 *  [mail function]
 *  ;SMTP = localhost
 *  ;smtp_port = 25
 *  ;sendmail_from = me@example.com
 *  sendmail_path = php.exe sendmail.php --dir C:\mail --open
 */
 
$is_windows = stristr(PHP_OS, 'WIN');
$options = getopt("", ['open', 'prepend', 'file:', 'dir:']);
$is_open = isset($options['open']);
$is_prepend = isset($options['prepend']);
$is_onefile = isset($options['file']);
$mail_dir = isset($options['dir']) ? $options['dir'] : sys_get_temp_dir() . '/mail';
$file_name = isset($options['file']) ? $options['file'] : mkname();
$file_path = $mail_dir . '/' . $file_name;
 
if (!is_dir($mail_dir)) {
    mkdir($mail_dir, 0777, TRUE);
    if (!is_dir($mail_dir)) {
        die('Mail folder [' . $mail_dir . '] not created');
    }
}
 
$stream = $is_onefile ? PHP_EOL . str_repeat("-=", 10) . date('Y-m-d H:i:s') . str_repeat("-=", 10) . PHP_EOL : '';
while (false !== ($line = fgets(STDIN))) {
    //$stream .= ($is_windows ? str_replace("\n", PHP_EOL, $line) : $line);
    $stream .= $line;
}
 
if ($is_prepend && file_exists($file_path)) {
    $file_contents = file_get_contents($file_path);
    $stream .= $file_contents;
}
 
file_put_contents($file_path, $stream, $is_prepend ? 0 : FILE_APPEND);
 
if ($is_open && $is_windows) {
    pclose(popen("start /B notepad " . $file_path, "r"));
}
 
function mkname($i = 0) {
    global $mail_dir;
    $fn = 'mail_' . date('Y-m-d_H-i-s_') . $i . '.eml';
    return file_exists($mail_dir . '/' . $fn) ? mkname( ++$i) : $fn;
}

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 stored in C:\Server\bin\Sendmail\emails\

Emails will have the .eml extension and they can be opened, for example, with the Thunderbird program or a text editor.

12. Adding PHP Directory to PATH on Windows

If this is not done, then 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 when the server is started, the following appears in the logs every time:

PHP Warning:  PHP Startup: Unable to load dynamic library 'curl' (tried: C:\\Server\\bin\\PHP\\ext\\curl (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_curl.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'intl' (tried: C:\\Server\\bin\\PHP\\ext\\intl (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_intl.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'ldap' (tried: C:\\Server\\bin\\PHP\\ext\\ldap (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_ldap.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: C:\\Server\\bin\\PHP\\ext\\pdo_pgsql (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_pdo_pgsql.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: C:\\Server\\bin\\PHP\\ext\\pdo_sqlite (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_pdo_sqlite.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: C:\\Server\\bin\\PHP\\ext\\pgsql (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_pgsql.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'sodium' (tried: C:\\Server\\bin\\PHP\\ext\\sodium (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_sodium.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlite3' (tried: C:\\Server\\bin\\PHP\\ext\\sqlite3 (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c), C:\\Server\\bin\\PHP\\ext\\php_sqlite3.dll (\xd0\x9d\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd \xd1\x83\xd0\xba\xd0\xb0\xd0\xb7\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xbc\xd0\xbe\xd0\xb4\xd1\x83\xd0\xbb\xd1\x8c)) in Unknown on line 0

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

Click the Start button, start typing “Edit the system environment variables” and open the corresponding settings window.

There, click “Environment Variables”.

In the “System Variables” window, find and click “Path”, then click “Edit” button:

If the following window opens,

then at the very beginning of the line, add

C:\Server\bin\PHP\;

Click “OK”.

If a multi-line window opens, then click “Create” and enter “C:\Server\bin\PHP\” there, move the entry to the very top:

Close all windows and save your changes.

Restart the server.

13. Setting up cURL in Apache Web Server on Windows

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

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

If cURL is configured incorrectly, then you will get errors:

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

Or:

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

For cURL to work in Apache on Windows you need:

1) Be sure to add PHP directory to PATH (system environment variables). How to do this is said a little higher: https://miloserdov.org/?p=7703#12

2) In the C:\Server\bin\PHP\php.ini file, the “extension=curl” line must be uncommented

3) You need to download the file https://curl.haxx.se/ca/cacert.pem, then in the C:\Server\ folder create a new folder called certs and move it to this new folder (C:\Server\certs\) downloaded file.

4) In the file C:\Server\bin\PHP\php.ini find the line

;curl.cainfo =

And replace it with

curl.cainfo = C:\Server\certs\cacert.pem

5) Restart the server.

14. How to back up Apache data (websites and databases) on Windows

All relevant information, i.e. site files and their databases are stored in the C:\Server\data\ folder. A backup copy in case the original data would become corrupted can be done in two ways.

The first way is that we simply make a copy of all files (websites + databases) to a safe place. This is a simple method and for most of us it will be the most convenient.

You need to start by stopping MySQL, because until it is stopped, some database files are open and cannot be copied correctly:

net stop mysql

Now just copy the folder C:\Server\data\ to any safe place. It already contains both databases (subfolder C:\Server\data\DB\) and all sites (subfolder C:\Server\data\htdocs\). When the copy is complete, start the MySQL service again:

net start mysql

If you need to restore all sites, or individual sites, or only individual site files, then this can be done without stopping the web server.

If you need to restore the databases, then again you will need to stop MySQL and return the original files C:\Server\data\DB\.

Please note that if you completely return the original folder C:\Server\data\, then all data is completely rolled back, i.e. all changes made after the backup was created will be gone!

The second backup method is to export the databases (this is done with the MySQL service running) and back up only the sites folder C:\Server\data\htdocs\. This method is a bit more complicated, but you can control which databases you want to export. Also in this form (databases in the form of .SQL files and site files) it is convenient to transfer sites to another web server or hosting.

We need the mysqldump.exe utility, it comes with MySQL and is located in the C:\Server\bin\mysql-8.0\bin\ directory.

To use it, open the command line and go to the folder with the program:

cd C:\Server\bin\mysql-8.0\bin\

The program can be used with a variety of options.

If you want to backup all databases to one file, then run:

.\mysqldump.exe -u root -p --all-databases > all-databases.sql

By the way, you need to look for the file in the folder that you see in the command line prompt.

To backup only one database (eg hackware):

.\mysqldump.exe -u root -p hackware > hackware.sql

To back up multiple databases, use the --databases option, followed by a space-separated list of the databases you want to back up:

.\mysqldump.exe -u root -p --databases hackware miloserdov > hackware_miloserdov.sql

To backup just one table (wp_posts) from a database (wordpress):

.\mysqldump.exe -u root -p wordpress wp_posts > wordpress_posts.sql

To back up multiple tables, list them with a space after the database name:

.\mysqldump.exe -u root -p wordpress wp_posts wp_comments > wordpress_posts_comments.sql

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

If you want to backup them (for example, before updating the server), then stop the services:

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

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

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

When the copy is complete, restart the services:

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

Database import

Import all databases:

mysql -u username -p < all-databases.sql

Single database import: To import an existing database file into MySQL or MariaDB, you need to create a new database into which the contents of the dump file will be imported. Start by logging into the database as root or another user with sufficient privileges to create a new database.

cd C:\Server\bin\mysql-8.0\bin\
.\mysql -u root -p

This will give you a MySQL shell prompt. Next, create a new database named new_database.

CREATE DATABASE new_database;

Creation will be confirmed.

Output
Query OK, 1 row affected (0.00 sec)

Now exit the MySQL shell by pressing CTRL+d. On a normal command line, you can import a file with the following command:

.\mysql -u username -p new_database < data-dump.sql

In this command:

  • username is the username with which you can login to the database
  • newdatabase is the name of the newly created database
  • data-dump.sql is a dump file with data for import, located in the current directory

Successful execution of the command will not display any messages. If errors occur during this process, mysql will print them to the terminal. You can verify that the database has been imported by logging into the MySQL shell again and parsing the data. This can be done by selecting a new database with the command

USE new_database;

and then execute a SQL query:

SHOW TABLES;

or a similar command to view data.

15. How to update the web server on Windows

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

Apache update

Download the archive with the new version of Apache.

Copy the c:\Server\bin\Apache24\conf\httpd.conf file to a safe location.

Stop and remove the Apache service:

c:\Server\bin\Apache24\bin\httpd.exe -k stop
c:\Server\bin\Apache24\bin\httpd.exe -k uninstall

Delete the C:\Server\bin\Apache24\ folder (this will not affect your sites and databases).

Unzip the new archive to C:\Server\bin\. Copy the httpd.conf file you saved earlier to c:\Server\bin\Apache24\conf\httpd.conf.

Start the Apache service:

c:\Server\bin\Apache24\bin\httpd.exe -k install
c:\Server\bin\Apache24\bin\httpd.exe -k start

PHP update

Download the archive with the new PHP version.

Copy the c:\Server\bin\PHP\php.ini file to a safe place.

Delete the C:\Server\bin\PHP\ folder.

Unzip the new archive to C:\Server\bin\PHP.

Copy the php.ini file you saved earlier to c:\Server\bin\PHP\php.ini.

Restart the Apache service:

c:\Server\bin\Apache24\bin\httpd.exe -k restart

MySQL update

Download the archive with the new version of MySQL.

Copy the c:\Server\bin\mysql-8.0\my.ini file to a safe location.

Stop and remove the MySQL service:

net stop mysql
c:\Server\bin\mysql-8.0\bin\mysqld --remove

Delete the C:\Server\bin\mysql-8.0\ folder (this will not affect your sites and databases).

Unzip the new archive to C:\Server\bin\. Rename the folder to mysql-8.0.

Copy the my.ini file you saved earlier to c:\Server\bin\mysql-8.0\my.ini.

Start the MySQL service:

C:\Server\bin\mysql-8.0\bin\mysqld --install
net start mysql

phpMyAdmin update

Download the archive with the new version of phpMyAdmin.

Copy the c:\Server\data\htdocs\phpMyAdmin\config.inc.php file to a safe location.

Delete the C:\Server\bin\phpMyAdmin\ folder (this will not affect your sites and databases).

Unzip the new archive to C:\Server\data\htdocs\. Rename the folder in phpMyAdmin.

Copy the config.inc.php file you saved earlier to c:\Server\data\htdocs\phpMyAdmin\config.inc.php.

16. How to protect the Apache web server from hacking in Windows

Recommended for you: How to protect the Apache web server from hacking in Windows.

How to uninstall the web server

If you no longer need a web-server installed with this guide or you want to install it again, follow the steps below to uninstall it.Stop the services and remove them from autostart by executing in the Windows Terminal:

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

Attention: all the web-sites and their databases created on your local web-server will be deleted!

Delete the server files by deleting the C:\Server\ folder. Attention: this will remove all databases and your sites.

Recommended for you:

13 Comments to Web Server on Windows 11 (Apache, MySQL, PHP and phpMyAdmin): step-by-step installation guide

  1. Paul Göttgens says:

    Hi Alex,

    Excellent tutorial, however. It does not work if you want to install on a different drive. I tried to install on the D drive. Apache works fine, but it crashes on MySQL, because it tries to install on the C drive when you use the command line.

    Do I have to edit a script to get this working and install the server on a different drive?

    Best regards,

     

    Paul

    • Alex says:

      Hello! Please pay attention to the setting of the my.ini file, as it contains the absolute path to the folder where the database is stored.

      [mysqld]
      sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
      datadir="d:/Server/data/DB/data/"
      default_authentication_plugin=mysql_native_password
      
      • Paul Gottgens says:

        Hi Alex,

         

        Thank you very much. That will do it.

         

        Best regards,

         

        Paul

  2. Flavius Popa says:

    One of the best tutorial I ever seen! Thank you so much! 

  3. Robert says:

    Hi Alex I made a big mistake, I had an outdated version of mysql so I grabbed this folder and cut it by placing it on an external drive and installed the latest version of mysql, but I did not take into account the databases that I had created, so I went to the folder called data of the old version of mysql and copied and pasted them in the new folder of the latest version, but those databases do not appear, do you know if I can recover that information with the files .ibd, they are practice projects but I do not want to lose that information, if you know any trick you could help me please.

     

  4. Dang says:

    Hi Alex,
    I have done the right steps but cant login to Mysql Server.
    Error: mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it

  5. Faisal Ali says:

    Hi Alex,

    I followed the same instructions, but now http://localhost/phpmyadmin is showing an empty white screen.

    • Alex says:

      Hello! I completely uninstalled my web server, rebooted my computer, opened this manual, downloaded the latest versions of each program, and reinstalled everything.

      Everything just works. phpMyAdmin just works too:

      You somewhere made an inaccuracy in the instructions. Try looking for errors also in the C:\Server\bin\Apache24\logs\access.log file.

  6. Waleed Ahmed says:

    Thanks a lot 

    This is the best and most comprehensive I found

  7. Lafatra says:

    Thanks a lot, 

    Can you show us how to create vhosts with https in ssl mod

    • Alex says:

      Hello! I wrote about how to create and use Apache virtual hosts on Windows in this article: Creating Apache Virtual Hosts on Windows

      I also wrote about how to use HTTPS in Apache on Windows, though only in Russian without translation into English: Apache SSL: переход Apache на HTTPS

      You can use Google Translator or find an equivalent of this article in English.

      But it is necessary to highlight an important point of working with SSL and HTTPS, which some users do not understand. You can create an SSL certificate locally for any virtual host (for example, “localhost” or “mysite.local”), but this certificate will never be valid for web browsers. To be more precise, you can add your certificate to be trusted by your web browser, but it will never be valid for web browsers on another computer.

      This reason makes no sense to use HTTPS on the local computer: the certificate is initially invalid, and if a hacker replaces it with another invalid certificate (Man-in-the-middle attack), then you will not even notice it.

      On Windows with Apache, you can use a valid certificate for a real host (for example, miloserdov.org). But you can only get a valid certificate from a trusted source (for example, a test certificate for 3 months from Let's Encrypt or buy a certificate from any other authorized person). But your web server must be accessible from outside your local network, and you must buy the domain name for which you want to get a certificate. These are all solvable tasks, and for a system administrator, these are trivial, simple tasks. But all this, as you understand, goes beyond the topic “local web server on a home computer”.

  8. DrLightman says:

    I'm almost crying with emotion at how well this tutorial is done. Maybe is the best one I've ever read.

    I've bought a new laptop recently and today I had to setup a dev environment as I have on the pc desktop and this updated guide helped me a lot, I followed it word by word, except some paths.

    PS: there is a small error in the first picture where you show the tree of the suggested folders, "Server" is missing.

    If you want add the part to setup https with locally trusted certs, I followed this guide years ago and it should still work:

    https://gist.github.com/cecilemuller/9492b848eb8fe46d462abeb26656c4f8

Leave a Reply

Your email address will not be published. Required fields are marked *