Home > Article > Backend Development > Configure apache method instance that supports PHP (win7)
This article mainly shares with you examples of how to configure apache to support PHP (win7). Wamp and lamp are environments often used by PHP engineers. Today we will configure apache so that it can work together with php.
1. Enter the conf directory of apache and open the apache configuration file httpd.conf. (It is recommended to back up before modification)
Modify the directory where the apache software is located:
ServerRoot "D:/wamp/Apache24"
Modify the host name and port number:
ServerName localhost:80
Modify the www directory (this directory is the directory where the project is located, the browser Can be accessed):
DocumentRoot "D:/wamp/www" <Directory "D:/wamp/www">
Modify the default index to support PHP:
<IfModule dir_module> DirectoryIndex index.php index.html index.htm </IfModule>
Enable rewrite function:
LoadModule rewrite_module modules/mod_rewrite.so
Customize 404 page (optional):
ErrorDocument 404 /missing.html
Load the PHP module, pay attention to the absolute path:
php5.6
LoadModule php5_module D:/wamp/php/php-5.6.22-Win32-VC11-x86/php5apache2_4.dll <IfModule php5_module> PHPIniDir "D:/wamp/php/php-5.6.22-Win32-VC11-x86/" AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule>
If it is php7, change it accordingly:
php7
LoadModule php7_module D:/wamp/php/php-7.0.13-Win32-VC14-x64/php7apache2_4.dll<IfModule php7_module> PHPIniDir "D:/wamp/php/php-7.0.13-Win32-VC14-x64/" AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps</IfModule>
Note : If it is PHP5.4 version, there is only php5apache2_2.dll in the php directory, which needs to be matched with Apache2.2.
So, when installing php5.6, you must confirm whether there is a php5apache2_4.dll file in the PHP installation package.
You can open the virtual host configuration file:
#Virtual hosts Include conf/extra/httpd-vhosts.conf
The default httpd-vhosts.conf file is for reference. Once the file is enabled, please configure it correctly, otherwise the apache service cannot be enabled. .
Virtual host example:
<VirtualHost *:80> DocumentRoot "D:/www/app/laravel-5-blog/public/" ServerName laravel-5-blog.fhy.com DirectoryIndex index.php <Directory "D:/www/app/laravel-5-blog/"> AllowOverride All </Directory > ErrorLog "logs/laravel-5-blog.fhy.com-error.log" CustomLog "logs/laravel-5-blog.fhy.com-access.log" common</VirtualHost>
DocumentRoot sets the path of the project, ServerName sets the host name, DirectoryIndex sets the entry file; AllowOverride setting in Directory turns on the .htaccess function.
You can enable the host alias configuration file:
Include conf/extra/httpd-alias.conf
If you install the x64-bit version of PHP, Apache also needs to be the x64-bit version. Then also libeay32.dll
, ssleay32.dll
, libssh2.dll
in the php directory and php_curl.dll## in the ext directory #Copy all four files and place them in the System32 directory. Otherwise the curl extension cannot be used.
<?php echo phpinfo();?>Enter localhost/phpinfo.php in the browser address bar. If PHP related information is displayed, it indicates success. wamp and lamp are environments often used by PHP engineers. Today we will configure apache so that it can work together with php. 1. Enter the conf directory of apache and open the apache configuration file httpd.conf. (It is recommended to back up before modification)
Modify the directory where the apache software is located:
ServerRoot "D:/wamp/Apache24"Modify the host name and port number:
ServerName localhost:80Modify the www directory (this directory is the directory where the project is located, the browser Can be accessed):
DocumentRoot "D:/wamp/www" <Directory "D:/wamp/www">Modify the default index to support PHP:
<IfModule dir_module> DirectoryIndex index.php index.html index.htm </IfModule>Enable rewrite function:
LoadModule rewrite_module modules/mod_rewrite.soCustomize 404 page (optional):
ErrorDocument 404 /missing.htmlLoad the PHP module, pay attention to the absolute path: php5.6
LoadModule php5_module D:/wamp/php/php-5.6.22-Win32-VC11-x86/php5apache2_4.dll <IfModule php5_module> PHPIniDir "D:/wamp/php/php-5.6.22-Win32-VC11-x86/" AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule>If it is php7, change it accordingly: php7
LoadModule php7_module D:/wamp/php/php-7.0.13-Win32-VC14-x64/php7apache2_4.dll<IfModule php7_module> PHPIniDir "D:/wamp/php/php-7.0.13-Win32-VC14-x64/" AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps</IfModule>Note : If it is PHP5.4 version, there is only php5apache2_2.dll in the php directory, which needs to be matched with Apache2.2.
So, when installing php5.6, you must confirm whether there is a php5apache2_4.dll file in the PHP installation package.
#Virtual hosts Include conf/extra/httpd-vhosts.confThe default httpd-vhosts.conf file is for reference. Once the file is enabled, please configure it correctly, otherwise the apache service cannot be enabled. . Virtual host example:
<VirtualHost *:80> DocumentRoot "D:/www/app/laravel-5-blog/public/" ServerName laravel-5-blog.fhy.com DirectoryIndex index.php <Directory "D:/www/app/laravel-5-blog/"> AllowOverride All </Directory > ErrorLog "logs/laravel-5-blog.fhy.com-error.log" CustomLog "logs/laravel-5-blog.fhy.com-access.log" common</VirtualHost>DocumentRoot sets the path of the project, ServerName sets the host name, DirectoryIndex sets the entry file; AllowOverride setting in Directory turns on the .htaccess function. You can enable the host alias configuration file:
Include conf/extra/httpd-alias.confIf you install the x64-bit version of PHP, Apache also needs to be the x64-bit version. Then also
libeay32.dll,
ssleay32.dll,
libssh2.dll in the php directory and
php_curl.dll## in the ext directory #Copy all four files and place them in the System32 directory. Otherwise the curl extension cannot be used. After successfully starting Apache, write phpinfo.php in the www directory:
<?php echo phpinfo();?>
Enter localhost/phpinfo.php in the browser address bar. If PHP related information is displayed, it indicates success.
Related recommendations:
After compiling php7, how to make apache support php7Configure Apache to support PHP5 apache php suite apache add php module apache deployment php itemNginx supports PHP configurationThe above is the detailed content of Configure apache method instance that supports PHP (win7). For more information, please follow other related articles on the PHP Chinese website!