SmugWimp at smugwimp dot com ¶
17 years ago
If you make changes to your PHP.ini file, consider the following.
(I'm running IIS5 on W2K server. I don't know about 2K3)
PHP will not "take" the changes until the webserver is restarted, and that doesn't mean through the MMC. Usually folks just reboot. But you can also use the following commands, for a much faster "turnaround". At a command line prompt, type:
iisreset /stop
and that will stop the webserver service. Then type:
net start w3svc
and that will start the webserver service again. MUCH faster than a reboot, and you can check your changes faster as a result with the old:
<?php>
phpinfo();
?>
in your page somewhere.
I wish I could remember where I read this tip; it isn't anything I came up with...
lukasz at szostak dot biz ¶
17 years ago
You can have multiple versions of PHP running on the same Apache server. I have seen many different solutions pointing at achieving this, but most of them required installing additional instances of Apache, redirecting ports/hosts, etc., which was not satisfying for me.
Finally, I have come up with the simplest solution I've seen so far, limited to reconfiguring Apache's httpd.conf.
My goal is to have PHP5 as the default scripting language for .php files in my DocumentRoot (which is in my case d:/htdocs), and PHP4 for specified DocumentRoot subdirectories.
Here it is (Apache's httpd.conf contents):
---------------------------
# replace with your PHP4 directory
ScriptAlias /php4/ "c:/usr/php4/"
# replace with your PHP5 directory
ScriptAlias /php5/ "c:/usr/php5/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php5/php-cgi.exe"
# populate this for every directory with PHP4 code
<Directory "d:/htdocs/some_subdir">
Action application/x-httpd-php "/php4/php.exe"
# directory where your PHP4 php.ini file is located at
SetEnv PHPRC "c:/usr/php4"
</Directory>
# remember to put this section below the above
<Directory "d:/htdocs">
# directory where your PHP5 php.ini file is located at
SetEnv PHPRC "c:/usr/php5"
</Directory>
---------------------------
This solution is not limited to having only two parallel versions of PHP. You can play with httpd.conf contents to have as many PHP versions configured as you want.
You can also use multiple php.ini configuration files for the same PHP version (but for different DocumentRoot subfolders), which might be useful in some cases.
Remember to put your php.ini files in directories specified in lines "SetEnv PHPRC...", and make sure that there's no php.ini files in other directories (such as c:\windows in Windows).
And finally, as you can see, I run PHP in CGI mode. This has its advantages and limitations. If you have to run PHP as Apache module, then... sorry - you have to use other solution (the best advice as always is: Google it!).
Hope this helps someone.
jp at iticonsulting dot nl ¶
18 years ago
If you get 404 page not found on Windows/IIS5, have a look at C:\SYSTEM32\INETSRV\URLSCAN
There is a .ini file there that prevents some files from being served by IIS, even if they exist, instead IIS will give a 404. The urlscan logfile (same place) should give you some insight into what parameter is preventing a page from loading, if any.
Jack Hardie ¶
16 years ago
If you are installing PHP on Vista just go to David Wang's blog. http://blogs.msdn.com/david.wang/
archive/2006/06/21/HOWTO-Install-and-Run-PHP-on-IIS7-Part-2.aspx
Magic!
smileclick at hotmail dot com ¶
15 years ago
Still Can't Run PHP Code?
After installing php-5.2.5-win32-installer.msi on my Windows XP2. with IIS5.1 it still didn't run PHP files.
I eventually found the fix*:
1. Goto Control Panel>System>Advanced>Environmental Variables
2. Add a New System Variable "PHRC" and set its path as "C:\Program Files\PHP"
3. Restart
*source:
http://us2.php.net/manual/en/faq.installation.php
#faq.installation.addtopath
webmaster at nachelfamily dot com ¶
16 years ago
I made the mistake of setting a 'wildcard application map' for PHP on a Windows 2003 / IIS 6.0 / PHP ISAPI installation.
This resulted in "No input file specified" errors whenever I tried to load the default page in my site's directories. I don't know why this broke things, but it did.
If anyone has the same problem, this may be the cause.
bufoni at hotmail dot com ¶
14 years ago
Oh Man!
I installed by Microsoft Installer, manually, whatever I always received de same error from IIS7.
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
The IIS7 interface is quite diferent and are not all together like IIS6
The 5.3 version have not any of those files: php5stdll, php5isapi.dll. etc.
The installer puts others files in handlers and I decided to use them as substitutes. Nothing done!
After that, I discovered that installer do not install these files within the sites, but in the root default site configuration of IIS7.
So, I copied the root configuration to my site and them it worked (all others procedures were done e.g. copy php.ini to windows folder)
Feroz Zahid ¶
18 years ago
In order to run php scripts with php.exe CGI instead of php4isapi.dll under IIS, following steps can be followed.
i) Add a web service extension for PHP using IIS manager. Choose a web service extension name like 'PHP' and add your php.exe path in the 'file location' while adding the required file e.g. 'C:\php\php.exe' in the Add extension dialog box. Don't forget to 'Allow' the extension file.
ii) Open php.ini file located at %systemroot%. Set the following variables to the shown values.
cgi.force_redirect = 0
cgi.redirect_status_env = ENV_VAR_NAME
iii) In your websites, add Application Mapping for '.php' and set the executable path to your php.exe file path.
You can test whether PHP is running or not and other PHP settings using the following simple PHP script.
<?php>
phpinfo();
?>
Feroz Zahid
ferozzahid [_at_] usa [_dot_] [_com_]
jneill at gamedaytv dot com ¶
16 years ago
Here's how to run dual PHP instances with PHP 5.2 and any previous PHP on Windows 2003:
1. Right-click My Computer, go to Advanced tab, and click on Environment Variables.
Add the two installations and their EXT directories to the Path variable. For example, add:
c:\php;c:\php\ext;c:\TMAS\php;c:\tmas\php\ext;
Then, add the newer PHP version's directory as a variable called PHPRC. For example:
Variable:PHPRC
Value: C:\PHP
Click OK to close the Environment Variables window, and click OK to close System Properties.
2. In registry, under HKEY_LOCAL_MACHINE>SOFTWARE>PHP, add a REG_SZ key called iniFilePath and give it a value
of the directory where the older PHP is installed. For example:
C:\TMAS\PHP
3. In IIS, go to the Web Service Extensions. Add both versions' ISAPI module separately to the extensions
list, and allow both.
4. In IIS, go to each website utilizing the PHP versions. Set an ISAPI filter if needed. On the Home Directory
tab, click Configuration, and add .php, .php3, .phtml, and any other extensions needed (perhaps .html?) to
be filtered through PHP, and specify the ISAPI module version needed for each website.
You can now run two versions of PHP. This is because the order of where to look for the .ini file changed
between previous PHP versions and PHP 5.2, as documented at http://us2.php.net/ini:
---------------------------------------------------
php.ini is searched in these locations (in order):
* SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI, php_ini parameter in NSAPI, PHP_INI_PATH environment variable in THTTPD)
* The PHPRC environment variable. Before PHP 5.2.0 this was checked after the registry key mentioned below.
* HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath (Windows Registry location)
* Current working directory (for CLI)
* The web server's directory (for SAPI modules), or directory of PHP (otherwise in Windows)
* Windows directory (C:\windows or C:\winnt) (for Windows), or --with-config-file-path compile time option
----------------------------------------------------
robert dot johnson at icap dot com ¶
15 years ago
IIS setup: 403 forbidden error.
We had installed two separate different PHP versions - PHP 5.1.4 followed by 5.2.5.
We configured 5.2.5 php5isapi.dll to be loaded as the .php file type extension.
Despite this, php version 5.1.4 was being loaded. We renamed 5.1.4's folder and then PHP was not loading at all.
There were no visible references to 5.1.4 in the IIS configuration, but in the file \webConfig.xml, there was a reference to 5.1.4's isapi under IISFilters.
To fix this problem, we added version 5.2.5's php5isapi.dll to the ISAPI Filter category for the web site, in the IIS control panel.
dpharshman at dslextreme dot com ¶
14 years ago
PHP 5.2.9.2 Install on XP Pro IIS 5.1 - phpinfo( ) results incorrect
Testing Date: 05.15.09
Background:
For several days now I, as a newbie, have been unsure if I had installed PHP correctly, or not. No matter what I did phpinfo( ) reported "Configuratin File Path" as: “C:\WINDOWS”. I was left to wonder what was wrong.
To help resolve the phpinfo() “issue”, I conducted a series of tests using two scripts:
The first is “test-php-ini-loaded.php”; it is stored in c:\inetpub\wwwroot, and has the following code:
<?php
$inipath = php_ini_loaded_file();
if (
$inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
The second script is simply calls phpinfo( ). It is named test.php, is stored in “c:\inetpub\wwroot”, and has the following code:
<?php phpinfo( ); ?>
My Dev Environment:
1. Windows XP Pro SP3
2. IIS 5.1 / MMC 3.0
3. PHP 5.2.9.2 – phpMyAdmin not yet installed
4. (plus MySQL 5.1, etc.)
5. Install location is on my local E: drive
The Tests:
Test 1:
a. PHPRC environment variable and IniFilePath Registry left in place and active
b. Verified no other copies of php.ini exist on the system other than in my E:\PHP folder
c. Renamed php.ini to hold-php.ini
d. Stopped and started IIS (“net stop iisadmin” and “net start w3svc”)
e. Ran “test-php-ini-loaded.php” to check whether my php.ini is loaded. It is not.
f. Ran "test.php". “Loaded Configuration File” was empty, while “Configuration File (php.ini) Path” showed: C:\WINDOWS.
Test 2:
a. Moved php.ini from E:\PHP to C:\WINDOWS
b. Stopped and started IIS
c. Ran "test-php-ini-loaded.php" to check if my php.ini is loaded. It is not, which surprised me.
d. Ran "test.php". My php.ini is apparently not loaded, or found, by phpinfo( ), even though “Configuration File (php.ini) Path” reports it as being in C:\WINDOWS.
e. Note: Per PHP’s “The configuration file” note, PHP's search order includes: “Windows directory (C:\windows or C:\winnt) (for Windows), ...”; but it apparently doesn’t or php.ini would have been found and displayed at “Loaded Configuration File”.
Test 3:
a. Left the solo copy of my php.ini in C:\WINDOWS
b. Disabled PHPRC environment variable by renaming it to “Ex-PHPRC and saving the settings (note: for this test I left the Registry entry for PHP IniFilePath intact)
c. Stopped and started IIS
d. Ran "test-php-ini-loaded.php" to check whether my php.ini is loaded. Predictably it is not found.
e. Ran the "test.php". Again, my php.ini file is reported as not found in C:\WINDOWS though “Configuration File (php.ini) Path” reports it as being there.
Test 4:
a. To be thorough and eliminate all possible sources of “mis-direction” I deleted the PHP IniFilePath Registry entry (after backing up the Registry). The PHPRC environment variable was left disabled.
b. Stopped and started IIS
c. Ran "test-php-ini-loaded.php" to check whether my php.ini is loaded. Predictably it is not.
d. Ran "test.php". Again, no change. My php.ini file is not found “Configuration File (php.ini) Path” reports it as being there.
Conclusions:
The first conclusion I came to is that, in the default download version of phpinfo( ), “Configuration File (php.ini) Path” is hard-wired to report C:\WINDOWS whether php.ini is there or not. Further, that C:\WINDOWS is not a default search location (at least not on XP).
However, given an otherwise “proper” setup, phpinfo() reporting C:\WINDOWS as the value for “Configuration File (php.ini) Path” is merely misleading and is not actually harmful or indicative of a failed installation.
Thanks go to Peter Guy of www.peterguy.com who suggested the testing, and to Daniel Brown of www.php.net for some initial guidance.
P.S. This note is not meant to take anything away from PHP. It is a fine tool. The sole purpose of the testing was to confirm that my installation of PHP was correct.
ratkinson at tbs-ltd dot co dot uk ¶
17 years ago
When installing onto the Windows IIS platform, ensure you add the PHPRC Server Variable to point to your PHP.INI file.
Also, add '.INI' to the FILEEXT Server Variable. Failure to add these could stop the PHP engine being able to find your PHP.INI file, and none of your modifications will be read.
Rob.
Как установить php на windows 10
В данной статье мы рассмотрим процесс установки PHP на операционную систему Windows 10.
Шаг 1: Скачивание PHP
Перейдите на официальный сайт PHP по ссылке https://www.php.net/downloads.php и скачайте архив с последней версией PHP для Windows.
Шаг 2: Распаковка архива
Распакуйте архив с PHP в удобную для вас директорию, например, C:\php
.
Шаг 3: Добавление PHP в переменные среды
Добавьте путь к папке с PHP в переменную среды Path
, чтобы иметь возможность вызывать PHP из командной строки:
- Откройте «Системные свойства» (нажмите клавиши
Win + X
и выберите «Система») - В левой панели выберите «Дополнительные параметры системы»
- Во вкладке «Дополнительно» выберите «Переменные среды»
- В разделе «Системные переменные» найдите переменную
Path
и нажмите «Изменить» - Добавьте новую строку со значением пути к PHP, например,
C:\php
- Нажмите «ОК» для сохранения изменений
Шаг 4: Создание файла php.ini
Создайте файл конфигурации PHP, называемый php.ini
, в директории с PHP. Можно скопировать и переименовать один из имеющихся примеров, например, php.ini-development
.
Шаг 5: Проверка установки PHP
Откройте командную строку (Win + R
, введите cmd
и нажмите Enter) и выполните следующую команду:
php -v
Если установка прошла успешно, вы увидите информацию о версии PHP.
Заключение/
Теперь у вас установлен PHP на вашем компьютере с операционной системой Windows 10. Вы можете начать разрабатывать веб-приложения, используя PHP, и экспериментировать с различными возможностями языка.
Не забудьте также установить и настроить веб-сервер, такой как Apache или Nginx, чтобы работать с PHP и отображать ваши веб-приложения.
PHP is a general-purpose scripting language geared towards web development. PHP is open-source software ( OSS ). PHP is free to use and download. PHP stands for PHP Hypertext Preprocessor. PHP file have extension called .php. PHP supports many databases MySQL, Oracle, etc. PHP is free to download and use. It was created by a Danish Canadian and designed by Rasmus Lerdorf in 1994. The common websites that are used are eCommerce, Social Platforms, Email Hosting, etc.
Installing PHP on Windows:
Follow the below steps to install PHP on Windows:
Step 1: Visit https://www.php.net/ website using any web browser and click on Downloads.
Step 2: Click on the Windows “Downloads” button.
Step 3: The new webpage has different options, choose the Thread safe version, and click on the zip button and Download it.
Step 4: Now check for the executable file in downloads in your system and extract it.
Step 5: After extracting, you get the extracted folder.
Step 6: Now copy the extracted folder.
Step 7: Now paste the copy folder in your windows drive in the Program files folder.
Step 8: Now the Permission Windows appears to paste the folder in program files then click on “Continue”.
Step 9: Now after pasting the folder then copy the address of the folder in program files.
Step 10: Now click on Start Menu and search “Edit the system environment variables” and open it.
Step 11: After opening System, Variable New window appears, and click on “Environment Variables…”
Step 12: Now go to the “System variables” Path option and double click on Path.
Step 13: Next screen will open and click on the “New” button.
Step 14: After New Paste the address we copy from program files to new and click on Enter button.
Step 15: Now Click on the OK button.
Step 16: Click on the OK button.
Step 17: Click on OK for saving changes.
Step 18: Now your PHP is installed on your computer. You may check by going to the “Start” menu typing Command Prompt. Open it.
Step 19: When the Command Prompt opens, type php -v
Step 20: Now enter the command prompt to show the version of PHP installed on your computer.
You have successfully installed PHP on your Windows 10 system.
Last Updated :
08 Jun, 2023
Like Article
Save Article
Найти дистрибутив PHP можно по адресу https://windows.php.net/download#php-8.2 Выберите версию Thread Safe.
В папке c:\WebServer\WAMP\ создайте новую папку PHP и скопируйте туда содержимое архива php-8.2.5 — VS16 x64 Thread Safe (2023-Apr-12 09:19:44) .
Смотрите Дерево каталогов .
Настройка конфигурационного файла php.ini
С помощью Notepad++ открываем php.ini-development в папке c:\WebServer\WAMP\PHP\ и сохраняем его как php.ini , и вносим в него следующие изменения .
Для этого находим строку – 768 :
И заменяем ее на :
extension_dir = "C:\WebServer\WAMP\PHP\ext\"
Теперь найдите строки: Начинается со строки 920 .
;extension=bz2
;extension=curl
;extension=fileinfo
;extension=gd2
;extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;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=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop
И заменим их на :
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
extension=gmp
extension=intl
extension=imap
;extension=interbase
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=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
extension=pgsql
extension=shmop
Заменим строки: – начинаются со строки 950.
;extension=soap
;extension=sockets
;extension=sqlite3
;extension=tidy
;extension=xmlrpc
;extension=xsl
На:
extension=soap
extension=sockets
extension=sqlite3
extension=tidy
extension=xmlrpc
extension=xsl
Указываем кодировку по умолчанию . Для этого находим строку – 720 :
;default_charset = "UTF-8"
И меняем ее на :
default_charset = "UTF-8"
Находим строку – 746:
;include_path = ".;c:\php\includes"
И меняем ее на :
include_path = ".;C:\WebServer\home\includes"
Предварительно создадим папку includes в C:\WebServer\home\
Здесь будут хранится подключаемые файлы PHP .
Заменим строку – 970:
На:
date.timezone = "Europe/Moscow"
Сохраняем и закрываем файл php.ini .
Теперь необходимо вписать поддержку PHP в файл конфигурации сервера Apache . Открываем файл httpd.conf и в конец файла добавим строки :
PHPIniDir "C:/WebServer/WAMP/PHP"
AddHandler application/x-httpd-php .php
LoadModule php_module "C:/WebServer/WAMP/PHP/php8apache2_4.dll"
Сохраняем и закрываем файл httpd.conf .
Настройка переменной среды
Далее необходимо добавить каталог с установленным интерпретатором PHP в переменную PATH операционной системы Windows 10 . Для этого нажмите кнопку Пуск на Windows 10, начните набирать «Изменение системных переменных среды» и откройте соответствующее окно настроек.
В открывшемся окне выбираем в самом низу пункт переменные среды .
В следующем открывшемся окне :
Выберем пункт path и нажимаем изменить .
В следующем открывшемся окне :
Выбираем пункт создать и в открывшейся строке напишите C:\WebServer\WAMP\PHP\ и выбираем пункт вверх и подымаем нашу строку к вверху , и нажимаем кнопку Ok , как на рисунке ниже .
Во всех открытых окнах нажимаем Ok , все окна переменной среды path закрываем . После данных изменений следует перезагрузить компьютер .
После перезагрузки компьютера , открываем Notepad++ и набираем следующий код :
<?php
phpinfo();
?>
Сохраняем файл в каталоге c:\WEbServer\home\www\ с названием i.php
В адресной строке Web – браузера набираем : http://localhost/i.php , если вы увидите данные о интерпретаторе PHP , как на рисунке , то значит все настройки сделали правильно и PHP работает .
Установка PHP завершена , если при выполнении примеров появляются ошибки ошибки , то проверяйте все в конфигурационные файлы , перезагружаем сервер и снова пробуем достичь желаемого результата.
И помните после каждого изменения конфигурационных файлов и исправлении ошибок , нужно чистить историю Web – браузера , может так получится вы нашли исправили ошибку , перезагрузили сервер , а Web – браузер выдает вам файлы из истории , и вы видите при загрузке опять ошибку .
— by: C. Smith
PHP 8 is on the way. In this tutorial, I will show you how to install PHP 8 on your Windows 10 machine using Apache as a webserver.
Download the necessary files
You can download PHP binaries from the URL: https://windows.php.net/download/.
Currently, the final version of PHP 8 has not been released, therefore, it cannot be found on the main page. Select the «QA Releases» from the top menu or navigate directly to https://windows.php.net/qa/.
Download the thread-safe, 32, or 64-bit version depending on your Windows type. As all versions have been compiled with VisualStudio 16 (2019), so later, you need a suitable Apache binary and a «Microsoft Visual C++ 2019 Redistributable» package installed on your PC.
Prepare PHP location
I like the programs to be in the Program Files folder. Besides this, over time, you will install several different versions of PHP. Therefore, I create the following directory structure:
For the sake of ease of use, I make some sacrifices in the security of my development machine. I give local users full permission to the PHP directory on my machine.
Once you have created the directory, copy the contents of the downloaded zip file.
Check if PHP works
As I mentioned earlier, PHP 8 was compiled with Visual Studio 2019. Thus, if the appropriate Redistributable is not installed on your machine, you will get the following error:
… VCRUNTIME140.dll was not found. ..
You can download the file from Microsoft Redistributable download
If all went well, you can use PHP from the command line. You can check the installation with the command: php -v
and the result should be something similar:
To make working with PHP more convenient, you can put the PHP directory on the path. Click on start and just type env
. From the list click on «Edit the system environment variables» and the System Properties dialog will appear. Click the «Environment Variables…» and select «Path» from the System variables block. Add the new PHP folder to the list.
Configure PHP
Now PHP is running but not yet configured properly. Configuring PHP 8 at the base level is no different from older versions.
The PHP folder contains 2 example configuration files:
- php.ini-production
- php.ini-development
Copy the development version to the same directory as php.ini
and open this for editing. What you need to set is the location of the extensions and session data.
You have to set the extension_dir
parameter to the valid location: extension_dir = "c:\Program Files\PHP\php-8.0.0RC2\ext"
extension_dir = "c:\Program Files\PHP\php-8.0.0RC2\ext"
You also have to uncomment the required extensions from the list. Usually, the curl, gd, mbstring, mysqli, pdo_mysql extensions are required for complex php apps.
extension=curl
extension=gd
extension=mbstring
extension=mysqli
extension=openssl
extension=pdo_mysql
Finally, you need to set the location where to save the session data: session.save_path = "w:/tmp"
session.save_path = "w:/tmp"
Installing Apache
Even if PHP has a built-in web server, production systems use Apache, Ngnix, Lightspeed, and so on. For a Windows development environment, Apache is the easiest choice.
You can download the latest Apache webserver from the ApacheLounge website. Download the 32 or 64-bit version depending on your OS type.
As I mentioned before, I don’t like everything in the C: root, so I also create a directory for Apache in the Program Files folder. Don’t forget to allow permissions for the users.
Now you can copy the content of the Apache24 folder of the zip file to the new location. Pay attention to the exact directory structure.
As with PHP, you can add Apache to the path, but in this case, you need to add the bin
folder.
Basic Apache configuration
Apache configuration files are located in the conf
directory. The main config file is the httpd.conf
. To start the webserver you need to set the server root (SRVROOT
) parameter in the config file to the correct location as follows:
Define SRVROOT "c:/Program Files/Apache/httpd-2.4.46"
ServerRoot "$ {SRVROOT}"
It is a good idea to set the ServerName
explicitly to prevent problems during startup. As we will use virtual hosts later, you can simply set it to localhost:80
ServerName localhost:80
An optional step — but usually required by most PHP applications — to enable Apache modules. For example, the mod_rewrite module is disabled by default but almost always required. Just uncomment the line and you are done.
LoadModule rewrite_module modules/mod_rewrite.so
Install Apache as a service
To install Apache as a windows service, you have to open a command prompt as an administrator. Navigate to the Apache bin directory and execute the command: httpd -k install
Then you can start the webserver using httpd -k start
Allow access:
If everything is correct, then you get the prompt back without any message.
Open a browser and type http://localhost
as the URL. You should get a welcome page similar to this:
Setup virtual hosts
The default document location is the htdocs
folder in the installation directory. However, this is not optimal. If you are a developer, you probably work on multiple web projects. So it would be nice to have a dedicated folder and URL for each project. For example, if site1.com
and site2.com
are the production sites, then you probably want a site1.local
and site2.local
URLs with a dedicated target folder for your development.
Virtual hosts are the solution to this problem.
Again, it is a good idea to store your code separated from drive C.
For example, you can create a directory structure like this:
Now you have to configure virtual hosts and enable it. First, open the httpd.conf
file and uncomment the line that includes the httpd-vhosts.conf
file.
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then, open the httpd-vhosts.conf
file that is in the extra
folder. Add one entry for each project you want. The ServerName
, DocumentRoot
, and ErrorLog
are the important parameters, you can skip the others.
<VirtualHost *:80>
ServerName site1.local
DocumentRoot "w:/Websites/site1.local"
ErrorLog "w:/Websites/site1.local/error.log"
</VirtualHost>
Besides this, you have to allow access to these folders so add a common Directory
block with the following content before the VirtualHosts entries.
Your final virtual host config file should look like this:
<Directory "w:/Websites" >
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
ServerName site1.local
DocumentRoot "w:/Websites/site1.local"
ErrorLog "w:/Websites/site1.local/error.log"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.local
DocumentRoot "w:/Websites/site2.local"
ErrorLog "w:/Websites/site2.local/error.log"
</VirtualHost>
You also need to extend the Windows hosts file that is located in c:\Windows\System32\drivers\etc\hosts
. Open the file for editing with administration privileges and add the server names used before to the file pointing to the local 127.0.0.1 IP address.
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 site1.local
127.0.0.1 site2.local
Put a simple index.html file in the site roots with different content for testing purposes.
Now you can restart Apache using httpd -k restart
. If everything is correct, then no error message is displayed. Navigate to site1.local and site2.local, and your browser should display the corresponding Html content.
Setup Apache to use PHP 8
The setup is almost done, but we haven’t configured PHP and Apache to work together.
First, we have to add the php extension to the known mime types. To do this, add the following line at the end of the mime.types
config file: application/x-httpd-php php
application/x-httpd-php php
To execute the index.php
automatically if a directory is requested, extend the DirectoryIndex
property with index.php
in httpd.conf
.
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
After that, the most important step is to load the php module. To do this, specify the PHP install directory and the appropriate module in the httpd.conf
file. Just insert the lines at the end of the httpd.conf
:
# PHP 8.0
PHPIniDir "c:/Program Files/PHP/php-8.0.0RC2"
LoadModule php_module "c:/Program Files/PHP/php-8.0.0RC2/php8apache2_4.dll"
Now you can restart apache and check for any error. If everything is fine then create a small inf.php file in the server document root with a simple phpinfo like this:
<?php
phpinfo();
Visiting site1.local/info.php should result in a PHP information page in your browser.
Troubleshooting
The «Can’t locate API module structure ‘php8_module’ in file …» error message is a common problem. Verify that exactly php_module
is in the LoadModule line. Neither the old php7_module
nor the expected php8_module
is good.