Home > Backend Development > PHP Tutorial > Configure apache method instance that supports PHP (win7)

Configure apache method instance that supports PHP (win7)

小云云
Release: 2023-03-20 15:02:02
Original
1546 people have browsed it

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"
Copy after login
Copy after login

Modify the host name and port number:

    ServerName localhost:80
Copy after login
Copy after login

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">
Copy after login
Copy after login

Modify the default index to support PHP:

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm 
</IfModule>
Copy after login
Copy after login

Enable rewrite function:

    LoadModule rewrite_module modules/mod_rewrite.so
Copy after login
Copy after login

Customize 404 page (optional):

    ErrorDocument 404 /missing.html
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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
Copy after login
Copy after login

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>
Copy after login
Copy after login

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
Copy after login
Copy after login

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.

After successfully starting Apache, write phpinfo.php in the www directory:

<?php
    echo phpinfo();?>
Copy after login
Copy after login

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"
Copy after login
Copy after login

Modify the host name and port number:

    ServerName localhost:80
Copy after login
Copy after login

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">
Copy after login
Copy after login

Modify the default index to support PHP:

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm 
</IfModule>
Copy after login
Copy after login

Enable rewrite function:

    LoadModule rewrite_module modules/mod_rewrite.so
Copy after login
Copy after login

Customize 404 page (optional):

    ErrorDocument 404 /missing.html
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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
Copy after login
Copy after login

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>
Copy after login
Copy after login

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
Copy after login
Copy after login

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. After successfully starting Apache, write phpinfo.php in the www directory:

<?php
    echo phpinfo();?>
Copy after login
Copy after login

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 php7

Configure Apache to support PHP5 apache php suite apache add php module apache deployment php item

Nginx supports PHP configuration

The 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template