11 Февраля 2020 | 11 Vasario 2020 | 11 February 2020

1) Установка „Denwer“ (или отдельно „Apache+PHP+MySQL“) и дальнейшее его использование

В условиях платных хостингов лучше выбрать установку „Denwer“, что будет бесплатно. Установочная программа „Denwer“ это есть локальная связка „Apache+PHP+MySQL+phpMyAdmin“ для „Windows“. Сайт „Denwer“ находится здесь [1]. Вам надо решить, надо ли вам „Denver“, с „PHP 5.3“ (или надо ли вам отдельной инсталяции „Apache+PHP+MySQL“, с „PHP 7“). Далее запустите „Denwer“:

-каталог для установки выберите „C:\WebServers“
-имя виртуального диска „Z:“
-запускать и останавливать систему по нажатию на ярлык (выбор „2“)

После окончания установки, создать в каталоге „C:\home“ каталог с именем сайта (например, „new-site.edu“), затем в этом каталоге создать каталог для субдомена „www“, потом перезапустить „Denwer“. Дальше вся работа с сайтом будет в каталоге „С:\home\new-site.edu\www“.

Для работы с национальными символами надо будет перенастроить „Denwer“, добавив поддержку кодировки „UTF-8“, как здесь [2] (Для этого можно в „/usr/local/apache/conf/httpd.conf“ заменить „AddDefaultCharset windows-1251“ на „AddDefaultCharset utf-8“).

Если по каким-то причинам, вы не хотите использовать „Denwer“, то можно попробовать отдельно установить „Apache+PHP+MySQL“ (с „PHP 7“).

Установка „Apache“

Загрузите экземпляр „Apache“ с „Apache Lounge“ [3]. Можно выбрать 64-бит редакцию (httpd-2.4.41-win64-VS16.zip). Как только архив .zip будет загружен, разархивируйте содержимое архива (например, сюда „C:\Apache24“). Так же надо будет установить файл „Visual Studio 2017 C++ Redistributables“ [4]. Далее выполните такие команды из командной строки администратора: „cd..“ > „cd..“ > „cd Apache24“ > „cd bin“ > „httpd.exe -k install“ > „httpd.exe -k start“ и попробуйте набрать в браузере в строке адрес „localhost“. Если в браузере появился текст „It works!“ - значит вы настроили „Apache“ успешно. Файлы сайтов хранятся по умолчанию в „C:\Apache24\htdocs“. Чтобы остановить сервис „Apache“, введите из командной строки администратора: „httpd.exe -k stop“. Если вам нужно внести изменения в „Apache“, вам нужно ввести „httpd.exe -k restart“.

Сайты в „Apache“

В каталоге „C:\Apache24\htdocs“ создаем каталог „new-site.edu“ и копируем туда „index.html“ из „C:\Apache24\htdocs“  

В файл „C:\Windows\System32\drivers\etc\hosts“ от имени администратора в „Notepad++“ добавляем: 

127.0.0.1       localhost
127.0.0.1       new-site.edu

В файл „C:\Apache24\conf\extra\httpd-vhosts.conf“ добавляем:

<VirtualHost *:80>
    DocumentRoot C:/Apache24/htdocs/new-site.edu
    ServerName new-site.edu
</VirtualHost>

В „C:\Apache24\conf\httpd.conf“ раскоментируем (удалить #):

#Include conf/extra/httpd-vhosts.conf

Перезагружаем „Apache“ и пробуем зайти в http://new-site.edu, если появился текст „It works!“, значит все правильно.

Установка „PHP“

Скачиваем „PHP“ системные файлы „php-7.4.2-Win32-vc15-x64.zip“ [5]. Разархивируем в „C:\PHP7“. В файле „C:\Apache24\conf\httpd.conf“ добавить в конец:

# ----- PHP Configuration -----
# LoadModule php7_module "С:/PHP7/php7apache2_4.dll"
LoadModule php7_module "С:/PHP7/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
# Configure the path to php.ini
# PHPIniDir "С:/PHP7"
PHPIniDir "С:/PHP7"

Перезагружаем „Apache“. Создаем файл „C:\Apache24\htdocs\new-site.edu\ver.php“ и пишем туда: 

<?php phpinfo()?>

В браузере открываем http://new-site.edu/ver.php, если видим настройки „PHP“, значит мы успешно установили „PHP“.

Установка „MySQL“

Загружаем „mysql-installer-community-8.0.18.0.msi“ [6], запускаем. Выбираем такие опции:

- Setup Type - Custom
- Select Products and Features - можно выбрать только MySQL Server 8.0.18 X64

Далее устанавливаем и конфигурируем БД:

- High Availability - Standalone MySQL Server / Classic MySQL Replication
- Type and Networking - Config Type - Development Computer
- Authentication Method - Use Legacy Authantication Method(Retain MySQL 5.x Compatibility)
- Accounts and Roles - Current Root Password - Вводим пароль админа БД

Дальше переименовываем „C:\PHP7\php.ini-development“ в „C:\PHP7\php.ini“. В „php.ini“ раскоментируем (удаляем ;) „;extension=mysqli“ и меняем „;extension_dir = "ext"“ на „extension_dir = "C:\PHP7\ext"“.

Дальше можно создать БД из консоли Администратора БД(меню „Пуск > Программы > MySQL“) с помощью команды:

CREATE DATABASE db;

Далее создаем „C:\Apache24\htdocs\new-site.edu\db.php“ с содержанием:

<?php  
  $dbcnx = mysqli_connect("127.0.0.1", "root_login", "root_password", "db");
  if (!$dbcnx)  
  {  
    echo "Not Ok!";  
  }
  else
  {
    echo "Ok!";
  }
?>

Заходим в http://new-site.edu/db.php, если видим текст „Ok!“, значит „MySQL“ работает.
----------
1) „Denwer“ instaliavimas (arba atskirai „Apache+PHP+MySQL“) ir jo tolesnis naudojimas

Mokamo hostingo sąlygomis geriau pasirinkti vietinį „Denwer“ instaliavimą, kuris bus nemokamas. Denwer diegimo programa yra „Apache+PHP+MySQL+phpMyAdmin“ paketas „Windows'ui“. „Denwer“ svetainė yra čia [1]. Turite nuspręsti, ar jums reikia „Denver“, su „PHP 5.3“ (arba ar jums reikia atskiros „Apache+PHP+MySQL“ instaliacijos su „PHP 7“). Toliau paleiskite „Denwer“ ir pasirinkite (rusų kalba):

-каталог для установки выберите „C:\WebServers“
-имя виртуального диска „Z:“
-запускать и останавливать систему по нажатию на ярлык (pasirinkimas „2“)

Baigę diegti, sukurkite katalogą „C:\home“ kataloge su svetainės pavadinimu (pvz, new-site.edu), tada sukurkite katalogą „www“ subdomenui šiame kataloge, tada paleiskite „Denwer“. Tada visas darbas su svetaine bus kataloge „C:\home\new-site.edu\www“.

Norint dirbti su nacionaliniais simboliais, reikės iš naujo konfigūruoti „Denwer“, pridedant palaikymą „UTF-8“ kodavimui, kaip čia [2] (Norėdami tai padaryti, faile „/usr/local/apache/conf/httpd.conf“, pakeiskite „AddDefaultCharset windows-1251“ į „AddDefaultCharset utf-8“).

Jei dėl kokių nors priežasčių nenorite naudoti „Denwer“, galite pabandyti atskirai įdiegti „Apache+PHP+MySQL“ (su „PHP 7“).

„Apache“ įdiegimas

Atsisiųskite „Apache“ kopiją iš „Apache Lounge“ [3]. Galite pasirinkti 64 bitų leidimą (httpd-2.4.41-win64-VS16.zip). Kai atsisiųsite .zip archyvą, išpakuokite archyvo turinį (pavyzdžiui, čia „C:\Apache24“). Taip pat turėsite įdiegti failą „Visual Studio 2017 C++ Redistributables“ [4]. Tada paleiskite šias komandas iš administratoriaus komandų eilutės: „cd..“ > „cd..“ > „cd Apache24“ > „cd bin“ > „httpd.exe -k install“ > „httpd.exe -k start“ ir pabandykite naršyklėje įvesti adresą „localhost“. Jei naršyklėje pasirodo tekstas „It works!“ - taigi sėkmingai sukonfigūravote „Apache“. Pagal numatytuosius nustatymus svetainės failai saugomi „C:\Apache24\htdocs“. Norėdami sustabdyti „Apache“ servisą, administratoriaus komandų eilutėje įveskite: „httpd.exe -k stop“. Jei jums reikia atlikti „Apache“ pakeitimus, tada turite įvesti „httpd.exe -k restart“.

„Apache“ svetainės

Kataloge „C:\Apache24\htdocs“ sukurkite katalogą „new-site.edu“ ir nukopijuokite „index.html“ iš „C:\Apache24\htdocs“ ten.

Į failą „C:\Windows\System32\drivers\etc\hosts“ „Notepad++“ Administratorius režime pridėkite:

127.0.0.1       localhost
127.0.0.1       new-site.edu

Į failą „C:\Apache24\conf\extra\httpd-vhosts.conf“ pridėkite:

<VirtualHost *:80>
    DocumentRoot C:/Apache24/htdocs/new-site.edu
    ServerName new-site.edu
</VirtualHost>

Faile „C:\Apache24\conf\httpd.conf“ atšaukite eilutę (ištrinti #):

#Include conf/extra/httpd-vhosts.conf

Perkrauname „Apache“ ir bandome apsilankyti http://new-site.edu, jei pasirodo tekstas „It works!“, tada viskas yra teisinga.

„PHP“ įdiegimas 

Atsisiųskite „PHP“ sistemos failus „php-7.4.2-Win32-vc15-x64.zip“ [5]. Išpakuokite į „C:\PHP7“. Faile „C:\Apache24\conf\httpd.conf“ pridėti prie pabaigos: 

# ----- PHP Configuration -----
# LoadModule php7_module "С:/PHP7/php7apache2_4.dll"
LoadModule php7_module "С:/PHP7/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
# Configure the path to php.ini
# PHPIniDir "С:/PHP7"
PHPIniDir "С:/PHP7"

Perkraukite „Apache“. Sukurkite failą „C:\Apache24\htdocs\new-site.edu\ver.php“ ir parašykite ten:

<?php phpinfo()?>

Naršyklėje atidarykite http://new-site.edu/ver.php, jei matome „PHP“ nustatymus, tada sėkmingai įdiegėme „PHP“.

„MySQL“ diegimas

Atsisiųskite „mysql-installer-community-8.0.18.0.msi“ [6], paleiskite jį. Nurodykite šiuos variantus:

- Setup Type - Custom
- Select Products and Features - galima pasirinkti tik MySQL Server 8.0.18 X64

Tada įdiekite ir sukonfigūruokite duomenų bazę:

- High Availability - Standalone MySQL Server / Classic MySQL Replication
- Type and Networking - Config Type - Development Computer
- Authentication Method - Use Legacy Authantication Method(Retain MySQL 5.x Compatibility)
- Accounts and Roles - Current Root Password - Įveskite DB administratoriaus slaptažodį

Tada pervardykite „C:\PHP7\php.ini-development“ į „C:\PHP7\php.ini“. Faile „php.ini“ komentuoti (ištrinti ;) „;extension = mysqli“ ir pakeisti „;extension_dir = "ext"“ į „extension_dir = "C:\PHP7\ext"“.

Tada galite sukurti duomenų bazę iš Duomenų bazės administratorius konsolės(meniu „Start > Programs > MySQL“) su komanda:

CREATE DATABASE db;

Tada sukurkite „C:\Apache24\htdocs\new-site.edu\db.php“ su turiniu:

<?php  
  $dbcnx = mysqli_connect("127.0.0.1", "root_login", "root_password", "db");  
  if (!$dbcnx)  
  {  
    echo "Not Ok!";  
  }
  else
  {
    echo "Ok!";
  }
?>

Einame į http://new-site.edu/db.php, jei matome tekstą „Ok!“, tada veikia „MySQL“.
----------
1) Installing „Denwer“ (or separately „Apache+PHP+MySQL“) and its subsequent use

With paid hosting, it is better to use a local „Denwer“ installation, which will be free. The „Denwer“ installer is an „Apache+PHP+MySQL+phpMyAdmin“ package for „Windows“. The „Denwer“ website is here [1]. You need to decide whether you need „Denver“ with „PHP 5.3“ (or whether you need a separate „Apache+PHP+MySQL“ installation with „PHP 7“). Run „Denwer“ below and select (in Russian):

-каталог для установки выберите „C:\WebServers“
-имя виртуального диска „Z:“
-запускать и останавливать систему по нажатию на ярлык (choice „2“)

When the installation is complete, create a directory in the „C:\home“ directory with the site name (for example new-site.edu), then create a directory for the www subdomain in that directory, then run „Denwer“. Then all work on the site will be in the directory „C:\home\new-site.edu\www“.

To work with national characters, you will need to reconfigure „Denwer“ by adding support for „UTF-8“ encoding, as here [2] (To do this, modify „AddDefaultCharset windows-1251“ to „AddDefaultCharset utf-8“).

If for some reason you don't want to use „Denwer“, you can try installing „Apache+PHP+MySQL“ separately (with „PHP 7“).

Installing „Apache“

Download a copy of „Apache“ from the „Apache Lounge“ [3]. You can select the 64-bit edition (httpd-2.4.41-win64-VS16.zip). When you download the .zip archive, unzip the contents of the archive (for example, here: „C:\Apache24“). You will also need to install the „Visual Studio 2017 C ++ Redistributables“ file [4]. Then run the following commands from the admin command prompt: „cd ..“ > „cd ..“ > „cd Apache24“ > „cd bin“ > „httpd.exe -k install“ > „httpd.exe -k start“ and try enter „localhost“ in your browser. If the text „It works!“ Appears in your browser - so you've successfully configured „Apache“. By default, site files are stored in „C:\Apache24\htdocs“. To stop „Apache“ service, enter: „httpd.exe -k stop“ at the administrator command prompt. If you need to make changes to „Apache“ then you need to type „httpd.exe -k restart“.

„Apache“ Sites

In the „C:\Apache24\htdocs“ directory, create the „new-site.edu“ directory and copy the „index.html“ from „C:\Apache24\htdocs“ there.

Add to „Notepad++“ in the „C:\Windows\System32\drivers\etc\hosts“ file in Admin mode:

127.0.0.1       localhost
127.0.0.1       new-site.edu

Add the following to your „C:\Apache24\conf\extra\httpd-vhosts.conf“ file:

<VirtualHost *:80>
    DocumentRoot C:/Apache24/htdocs/new-site.edu
    ServerName new-site.edu
</VirtualHost>

In „C:\Apache24\conf\httpd.conf“, undo the line (delete #):

#Include conf/extra/httpd-vhosts.conf

We reload „Apache“ and try to visit http://new-site.edu, if it says „It works!“ Then everything is correct.

Installing „PHP“

Download „PHP“ system files „php-7.4.2-Win32-vc15-x64.zip“ [5]. Unzip to „C:\PHP7“. In „C:\Apache24\conf\httpd.conf“, add to end:

# ----- PHP Configuration -----
# LoadModule php7_module "С:/PHP7/php7apache2_4.dll"
LoadModule php7_module "С:/PHP7/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
# Configure the path to php.ini
# PHPIniDir "С:/PHP7"
PHPIniDir "С:/PHP7"

Restart „Apache“. Create the file „C:\Apache24\htdocs\new-site.edu\ver.php“ and write there:

<?php phpinfo()?>

Open http://new-site.edu/ver.php in your browser if we see „PHP“ settings then we have successfully installed „PHP“.

Installing „MySQL“

Download „mysql-installer-community-8.0.18.0.msi“ [6] and run it. Please specify the following options:

- Setup Type - Custom
- Select Products and Features - Only MySQL Server 8.0.18 X64 can be selected

Then install and configure the database:

- High Availability - Standalone MySQL Server / Classic MySQL Replication
- Type and Networking - Config Type - Development Computer
- Authentication Method - Use Legacy Authantication Method (Retain MySQL 5.x Compatibility)
- Accounts and Roles - Current Root Password - Enter the DB administrator password

Then rename „C:\PHP7\php.ini-development“ to „C:\PHP7\php.ini“. In „php.ini“ comment (delete ;) „;extension = mysqli“ and change „;extension_dir = "ext"“ to „extension_dir = "C:\PHP7\ext"“.

You can then create a database from the Database Admin console („Start menu > Programs > MySQL“) with the command:

CREATE DATABASE db;

Then create „C:\Apache24\htdocs\new-site.edu\db.php“ with the content:

<?php  
  $dbcnx = mysqli_connect("127.0.0.1", "root_login", "root_password", "db");  
  if (!$dbcnx)  
  {  
    echo "Not Ok!";  
  }
  else
  {
    echo "Ok!";
  }
?>

We go to http://new-site.edu/db.php, if we see the text „Ok!“ Then „MySQL“ is running.
----------
[1]http://www.denwer.ru
[2]https://ru.stackoverflow.com/questions/235786/Кодировка-страниц-на-сервере-denwer
[3]https://www.apachelounge.com/download/VS16/binaries/httpd-2.4.41-win64-VS16.zip
[4]https://aka.ms/vs/16/release/VC_redist.x64.exe
[5]https://windows.php.net/downloads/releases/php-7.4.2-Win32-vc15-x64.zip
[6]https://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-8.0.18.0.msi