IIS installation

  • Install Windows features
    Control Panel -> All Control Panel Items -> Programs and Features -> Enable or Disable Windows Features
    Select Internet Information Services
    Add CGI feature
  • Testing IIS
    Call up localhost in the browser.
  • IIS Log Files
    C:\inetpub\logs\LogFiles\W3SVC[ID OF THE PAGE]\u_extend1.log

Web Platform Installer - Other useful tools

Popular apps can be easily installed with the Web Platform Installer. If there are errors, however, these are usually very difficult to solve because the messages do not say much. Personally, I don't use the tool to install applications, except to take a quick look at what's new. The Web Platform Installer can either be found under Actions in the IIS Manager 'Get new web platform components', this link leads you to the correct download or you can search directly using a search engine. After the installation, the Web Platform Installer appears in the IIS Manager.

IIS settings

  • Configuration editor
    Section -> system.web/sessionState -> increase timeout

Fix IIS problems

  • Restart IIS
    Open the Windows command prompt (cmd.exe = CMD) as administrator.
    iisreset (Is the same as 'Restart' in the IIS Manager under Actions.)
  • Start IIS
    Open CMD as administrator.
    iisreset /start (Is the same as 'Start' in the IIS Manager under Actions.)
  • Stop IIS
    Open CMD as administrator.
    iisreset /stop (Is the same as 'Stop' in the IIS Manager under Actions.)
  • No access rights
    Give the user 'IIS_IUSRS' or the current user full access to the folder 'inetpub'.
  • Reset handler assignment so that the higher-level PHP versions appear
    Open node sites -> select page -> open handler assignment -> under Actions, click on 'Reset to parent' on the right.
  • Remove PHP versions
    Remove PHP versions in the IIS manager (handler assignment and FastCGI settings).
    Delete the removed PHP versions in the file 'C:\Windows\System32\inetsrv\config\applicationHost.config', if available.
    Delete the removed PHP versions in the same file in the 'inetpub' folder, if available.

Let IIS interpret Apache .htaccess files

  • Install Windows features
    Control Panel -> All Control Panel Items -> Programs and Features -> Enable or Disable Windows Features
    Add ISAPI extensions feature (for Helicon ISAPI_Rewrite 3 Fullversion, Version 3.1.0078; fulfills the tasks of 'Apache Web Server Rewrites')
    Add ISAPI filter feature (this is a .htaccess reader; since the .htaccess is a Linux file)
  • Install Helicon ISAPI_Rewrite
    Select the required version at https://www.helicontech.com/isapi_rewrite/. Then download and install.
    At the end, add the registration information to the 'httpd.conf' file, if available.

PHP for IIS

When using PHP as FastCGI with IIS, take the Non-Thread Safe (NTS) versions of PHP. Since the FastCGI module takes care of the management of incoming requests in parallel.

  • Install PHP Manager for IIS
    Look for 'PHP Manager for IIS [IIS VERSION]' in a search engine.
  • Set up PHP versions
    Download the required PHP version from https://windows.php.net/download/.
    Extract into a directory you created yourself, e.g. 'C:\PHP'.
    Open IIS Manager -> select first node -> PHP Manager -> Register new PHP Version -> select file -> OK
  • Install the 'Microsoft Visual C ++ Redistributable' required for PHP
    Microsoft Visual C++ 2012 Redistributable (x86 or x64) for VC11.
    Microsoft Visual C++ 2015-2019 Redistributable (x86 or x64) for VC14, VC15 or VS16.
  • Testing
    In the folder 'C:\inetpub\wwwroot' create the file 'info.php' and insert the following line.
    ‹?php phpinfo(); ?›
    Call up localhost/info.php in the browser.
  • PHP configuration
    Open the 'php.ini' file.
    Activate the necessary extensions
    extension=php_mysql.dll (Extension for MySQL database; this extension is obsolete and was removed as of PHP 7)
    extension=php_mysqli.dll (Extension for MySQL database)
    extension=php_mbstring.dll (Extension for multibyte string functions; e.g. mb_strlen)
    extension=php_mcrypt.dll (Extension for decryption and encryption; e.g. mcrypt_encrypt)
    extension=php_curl.dll (Extension for cURL sessions; e.g. curl_close)
    Necessary settings
    date.timezone = "Europe/Berlin"
    If the MySQL port is different, keyword Multiple MySQL Server
    [MySQL] (obsolete, removed from PHP 7)
    mysql.default_port = 3307
    or
    [MySQLi]
    mysqli.default_port = 3307
    Restart IIS after changes and check 'info.php'.
  • Supported PHP versions
    https://www.php.net/supported-versions.php
  • Official PHP installation requirements
    https://www.php.net/manual/de/install.windows.requirements.php
  • Error file
    C:\Windows\Temp\php-[PHP VERSION]_errors.log

ImageMagick for PHP on IIS

  • Check important information
    Create the 'info.php' file and insert the line '‹?php phpinfo(); ?›'. Call up the file in the browser and check the following.
    PHP Version = 7.4.12
    Compiler = MSVC15 (Visual C++ 2017)
    Architecture = x86
    Thread Safety = disabled
  • Download the 'php_imagick.dll' file for PHP https://pecl.php.net/package/imagick
    Extract the file 'php_imagick.dll' into the folder 'C:\PHP\php-[PHP VERSION]-nts-Win32-[COMPILER]-[ARCHITECTURE]\ext'.
  • Add PHP extension
    Open the 'php.ini' file and insert the following lines at the very end.
    [PHP_IMAGICK]
    extension=php_imagick.dll
  • Download the package 'ImageMagick-[IMAGEMAGICK VERSION]-[COMPILER]-[ARCHITECTURE]' from https://windows.php.net/downloads/pecl/deps/
    Add environment variable
    Extract the folder from the downloaded package into a directory you created yourself, e.g. 'C:\PHPext'.
    Environment Variables -> System Variables -> Edit Path -> Add Path 'C:\PHPext\ImageMagick-[IMAGEMAGICK VERSION]-[COMPILER]-[ARCHITECTURE]\bin;'
    ATTENTION: Only one environment variable is possible for ImageMagick, if there are several entries for different versions there will be problems loading the individual modules (e.g. png is not supported).
    Alternative to the environment variable
    I do not prefer this method and have not yet tested this method because I liked to separate the packages. I change the environment variable depending on which ImageMagick version I need.
    Extract the DLL files from the 'bin' folder beginning with CORE_RL or IM_MOD_RL into the folder 'C:\PHP\php-[PHP VERSION]-nts-Win32-[COMPILER]-[ARCHITECTURE]'.
  • Check supported formats
    Call up 'info.php' and check 'ImageMagick number of supported formats'.
  • Testing
    Create the 'imagick-test.php' file and add the following lines. Then call up the file in the browser.
    ‹?php
    $image = new Imagick();
    $image->newImage(1, 1, new ImagickPixel('#ffffff'));
    $image->setImageFormat('png');
    $pngData = $image->getImagesBlob();
    echo strpos($pngData, '\x89PNG\r\n\x1a\n') === 0 ? 'Ok' : 'Failed';

MySQL

MySQL Installer

With the MySQL Installer 'mysql-installer-web-community-[MYSQL VERSION].msi' you can install, upgrade and change MySQL.

Multiple MySQL versions

Start several MySQL instances as Windows services.

  1. Install MySQL
    Select the required version from https://dev.mysql.com/downloads/mysql/ and download it.
    Unzip the file 'mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE].zip' and create an additional folder 'mysql-[MYSQL FULL VERSION]-data'.
  2. Install the 'Microsoft Visual C ++ Redistributable Package' required for MySQL
    Install required Microsoft packages, if not available.
    Install Microsoft Visual C++ 2008 Redistributable (x86 or x64) for MySQL 5.5.
    Install Microsoft Visual C++ 2010 Redistributable (x86 or x64) for MySQL 5.6.
    Install Microsoft Visual C++ 2013 Redistributable (x86 or x64) for MySQL 5.7.
    Install Microsoft Visual C++ 2015-2019 Redistributable (x86 or x64) for MySQL 8.0.
  3. Create file for MySQL settings
    Create the file 'my-mysqld[MYSQL SHORT VERSION].ini', e.g. my-mysqld57.ini and insert the following lines.
    [client]
    port = 3307 (The default port for MySQL is 3306, so let's start with port 3307)

    [mysql]
    default-character-set=UTF8

    [mysqld]
    basedir = "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\"
    datadir = "C:\MySQL\mysql-[MYSQL FULL VERSION]-data\"
    port = 3307
    enable-named-pipe
    socket = MySQLpipe[MYSQL SHORT VERSION]
    character-set-server=UTF8
    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
  4. Remove environment variables
    In the case of multiple MySQL instances, do not add any environment variables, if environment variables are present, remove them as follows.
    Environment Variables -> System Variables -> Edit Path -> Remove Environment Variables
    ATTENTION: Commands are not possible without an environment variable, e.g. mysql -u root -p.
  5. Initialize the folder 'mysql-[MYSQL FULL VERSION]-data'
    MySQL version 5.6 and earlier
    Insert the content of the 'data' folder of the *.zip file.
    MySQL version 5.7 and later
    ATTENTION: The *.zip file no longer has a 'data' folder.
    Re-initialize the folder 'mysql-[MYSQL FULL VERSION]-data'.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysqld" --defaults-file="C:\MySQL\my-mysqld[MYSQL SHORT VERSION].ini" --initialize --console (--initialize-insecure = No password is set; Log in = mysql -u root --skip-password)
    A password is generated, don't forget to write it down.
    e.g. "C:\MySQL\mysql-8.0.22-winx64\bin\mysqld" --defaults-file="C:\MySQL\my-mysqld80.ini" --initialize --console
  6. Install Service
    Run CMD as administrator.
    ATTENTION: The code '--defaults-file' must follow the service name.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysqld" --install MySQL[MYSQL SHORT VERSION] --defaults-file="C:\MySQL\my-mysqld[MYSQL SHORT VERSION].ini"
    e.g. "C:\MySQL\mysql-8.0.22-winx64\bin\mysqld" --install MySQL80 --defaults-file="C:\MySQL\my-mysqld80.ini"
    Alternative possibility
    To use a certain MySQL version, change to the folder of the desired MySQL version and then execute the desired command 'mysql [COMMAND]'.
    cd "C:\MySQL\mysql-[MYSQL VERSION]-win[ARCHITECTURE]\bin\"
    e.g. cd "C:\MySQL\mysql-8.0.22-winx64\bin\"
  7. Start service
    Run CMD as administrator.
    net start MySQL[MYSQL SHORT VERSION]
    If the service MySQL[MYSQL SHORT VERSION] does not start, check the '* .err' file in the 'C:\MySQL\mysql-[MYSQL FULL VERSION]-data' folder.
    Alternative possibility
    Start temporary mysqld service.
    ATTENTION: An installed MySQL service must not be running, otherwise the new temporary mysqld service cannot be started.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysqld" --port=[PORT] --user=[USER] --datadir="C:\MySQL\mysql-[MYSQL FULL VERSION]-data\" --console (--console lists errors)
    e.g. "C:\MySQL\mysql-5.5.59-win32\bin\mysqld" --port=3307 --user=root --datadir="C:\MySQL\mysql-5.5.59-data\" --console
    Shut down temporary mysqld service.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysqld" --host=127.0.0.1 --port=[PORT] --user=[USER] --password shutdown
  8. Log in
    Run CMD as administrator.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysql" --host=localhost --port=[PORT] --user=[USER] --password=[PASSWORD] (Full version)
    mysql -h localhost -P [PORT] -u [USER] -p (Short version, password is requested after executing the command)
    e.g. "C:\MySQL\mysql-5.7.21-win32\bin\mysql" -h localhost -P 3309 -u root -p
  9. Testing
    Execute the following command after logging in.
    show variables where Variable_name in('hostname','port');

MySQL settings

  • Permissions
    The MySQL server user must be able to read the file 'my-mysqld[MYSQL SHORT VERSION].ini'.
  • All functions of mysqld
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysqld" --help
  • Show open ports
    netstat -an
  • Check specific port
    netstat -an | find '[PORT]'

Change root password

  • Log in
    mysql -h localhost -P [PORT] -u [USER] -p
  • MySQL 5.7.5 and earlier
    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('[PASSWORD]');
  • MySQL 5.7.6 and later
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '[PASSWORD]';

Remove MySQL Windows Service

  • Stop Service
    Run CMD as administrator.
    net stop MySQL[MYSQL SHORT VERSION]
  • Delete Service
    sc delete MySQL[MYSQL SHORT VERSION]

MySQL upgrade on Windows

  1. Create MySQL backup
    Save the directory 'mysql-[MYSQL FULL VERSION]-data'.
  2. Stop current service
    net stop MySQL[MYSQL SHORT VERSION]
  3. Delete current service
    sc delete MySQL[MYSQL SHORT VERSION]
  4. Delete current MySQL and extract new MySQL
    ATTENTION: Do not delete the current directory 'mysql-[MYSQL FULL VERSION]-data'.
  5. Install new service
    ATTENTION: The code '--defaults-file' must follow the service name.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysqld" --install MySQL[MYSQL SHORT VERSION] --defaults-file="C:\MySQL\my-mysqld[MYSQL SHORT VERSION].ini"
    e.g. "C:\MySQL\mysql-5.7.21-win32\bin\mysqld" --install MySQL57 --defaults-file="C:\MySQL\my-mysqld57.ini"
  6. Start Service
    net start MySQL[MYSQL SHORT VERSION]
  7. Perform upgrade
    DO NOT delete the 'ibdata1' file. All tables, passwords, etc. are contained in the 'ibdata1' file.
    If NECESSARY delete 'ib_logfile()' and 'ib_logfile1'.
    Delete the files '*.err' and '*.pid' if available.
    "C:\MySQL\mysql-[MYSQL FULL VERSION]-win[ARCHITECTURE]\bin\mysql_upgrade" -h localhost -P [PORT] -u root -p
    e.g. "C:\MySQL\mysql-5.7.21-win32\bin\mysql_upgrade" -h localhost -P 3309 -u root -p
  8. Stop and restart the server
    net stop MySQL[MYSQL SHORT VERSION]
    net start MySQL[MYSQL SHORT VERSION]

phpMyAdmin

  • Install phpMyAdmin
    Download the package from https://www.phpmyadmin.net/downloads/.
    Unzip all files to 'C:\inetpub\wwwroot\phpmyadmin'.
    Grant the user 'IUSR' full access to the folder 'C:\inetpub' to avoid possible problems.
  • Convert phpMyAdmin in IIS into an application
    Right click on 'phpmyadmin' -> Convert to Application -> OK
  • Testing
    Call localhost/phpmyadmin in the browser.
  • Configure the 'config.inc.php' file
    Create the folder 'config' under 'C:\inetpub\wwwroot\phpmyadmin'.
    Call localhost/phpmyadmin/setup in the browser.
    Make the required settings.
    Store the generated 'config.inc.php' in the directory 'C:\inetpub\wwwroot\phpmyadmin'.
    Delete the 'config' folder.
    Call localhost/phpmyadmin in the browser. Finished.

phpMyAdmin export settings

I select the following options for export in addition to the standard options.

  • Combine the export in one transaction
  • Disable foreign key checking
  • Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER command
  • IF NOT EXISTS (less efficient, because indexes are created during table creation)
  • Maximum length of the created query 999999

Sending emails via PHP

Fake sendmail for Windows

  • Download 'Fake sendmail for Windows' and extract it
    https://www.glob.com.au/sendmail/sendmail.zip
    Extract the archive 'sendmail.zip' into the directory 'C:\PHPext\sendmail\'.
  • Add the following in the 'php.ini'
    sendmail_path = 'C:\PHPext\sendmail\sendmail.exe -t'
  • Make settings in the 'sendmail.ini'
    smtp_server=[SMTP-SERVER]
    smtp_port=[SMTP-PORT]
    smtp_ssl=auto
    error_logfile=C:\PHPext\sendmail\error.log
    debug_logfile=C:\PHPext\sendmail\debug.log
    auth_username=[E-MAIL]
    auth_password=[PASSWORD]
    ;pop3_server=
    ;pop3_username=
    ;pop3_password=
    ;force_sender=[E-MAIL] (Force sender; did NOT work for me)
    ;force_recipient=[E-MAIL] (Force recipient; worked for me)
    hostname=localhost
  • Testing
    Create the 'sendmail.php' file and insert the following line.
    ‹?php
    mail('[E-MAIL]','Subject: Test','E-mail message','From: [E-MAIL]');
    Call up the file in the browser and see whether the mail has arrived.
    ATTENTION: The sender must be an email address of the associated account. It is possible to only add sender email addresses to accounts, e.g. at Google, Yahoo.