Configure Apache server under Windows and support PHP

Source: Internet
Author: User
Tags php website

The configuration of the PHP environment is relatively cumbersome, most of the online tutorials are put together to say, the overall feeling is more chaotic, in fact, Apache is a general-purpose server software, can be used to configure support static pages, PHP, Python, Java and even ASP service-side language, To understand Apache as a separate server, and not necessarily with the PHP partner, but with PHP is a more popular combination, such as lamp is a more popular site architecture, so first we configure Apache, first let the server run up and can parse the static HTML file

First we go to the official website to download the latest version of Apache, first to home: http://www.apache.org/

  

This is the Apache Foundation's official website, in the end will see a lot of open source projects, such as spark, struts framework, the popular Hadoop Big data platform, Tomcat server, etc., the most famous is the first HTTP server is the HTTP server,

  

Now, click to go to the Apache Server page, the URL is: http://httpd.apache.org/

The official provides a lot of documents, etc., than the results found on the Internet to be systematic and accurate, and also the Chinese version

OK, we see now the latest version is 2.4.18, click "Download" hyperlink

  

You will see the type of download, the previous items are Linux version of the package file and source code, click on the last version of Windows

  

And now you see the download page:

  

We see that the Apache server is not dedicated to the version of Windows, you need to compile the source code to generate binary files, if not compiled, you can download the compiled program provided below

Behind the Wampserver and Xampp is the most popular integration environment of Windows platform, the first or second is the compiled version of the Apache server, we click the second entry, is the final download page, the link is:/http www.apachelounge.com/download/

Now we can download it directly based on the number of bits in the operating system.

  

After downloading, we for convenience, first set up a directory to specifically place the server and the subsequent PHP runtime environment, I was built under C:/www, and then the server just downloaded into the directory, and then C:/www/apache24 under this look

  

Also note that one place is the latest Apache operating environment must be based on vc++2014, and then vc++2015 more no problem, the same PHP run also need this environment, I mentioned earlier article, so install once VC14 or VC15 is no problem

Now start configuring the server, first open the httpd.conf configuration file under the Conf directory

Find the ServerRoot "C:/apache24" line,

Changes according to the actual directory, so instead: ServerRoot "C:/www/apache24"

Find #servername www.example.com:80 and remove the front #

And then find DocumentRoot "C:/apache24/htdocs" This means that our web resources are placed in the root directory, here I changed to: DocumentRoot "C:/www/apache24/htdocs"

And then the following line: <directory "C:/apache24/htdocs" > This is also a directory of Web resources, so instead: <directory "C:/www/apache24/htdocs" >

Then find:

<ifmodule dir_module>
DirectoryIndex index.html
</IfModule>

This means that our default home page program can be set to: DirectoryIndex index.html index.htm index.php This configuration is accessed in order of precedence

Then found: scriptalias/cgi-bin/"c:/apache24/cgi-bin/" here means to set the CGI directory, in the Apache directory has a cgi-bin directory, so this should be changed to: Scriptalias/ cgi-bin/"c:/www/apache24/cgi-bin/"

Then find:

<directory "C:/apache24/cgi-bin" >
AllowOverride None
Options None
Require all granted
</Directory>

This code, note and our previous Web root directory is not the same location, the place is also changed to Cgi-bin directory, and scriptalias like the line

Here, our Apache server configuration is complete, and now you can parse the HTML run app

Now, run cmd, enter the C:\www\Apache24\bin directory, the directory of Httpd.exe is the server execution program, according to the official website, we first put Apache as an application software service installed in the system services, run the command:

Httpd-k install-n "Apacheserver"

After executing this command, if there is no problem, the Apache service installed successfully, the service name is: Apacheserver This we can customize, if only to execute

Httpd-k Install

This defaults to installing the Apache service named: Apache2.4

If the installation prompt, OS 5 denial of service, AH00369 such errors, the reason is that we do not have permission to perform operations, then need to enter the C:\Windows\System32 directory, right-click Cmd.exe choose to run as an administrator, so that the installation is successful

Now run Services.msc can see the newly installed services, and the default is automatic, is automatically started with the system, not every time we start again,

If you want to manually start or shut down or restart the server there are two ways, one is in the system service right-click the corresponding operation, relatively simple

The other is to use the command line to operate:

Start: Httpd-k start-n "Apacheserver" or the default is Httpd-k start

Stop: Httpd-k stop-n "Apacheserver" or httpd-k shutdown-n "Apacheserver"

Restart: httpd-k restart-n "Apacheserver"

Execute if you need to uninstall the service: Httpd-k uninstall-n "Apacheserver"

Now, if we visit http://localhost or http://127.0.0.1, if we can see the Welcome page of the It works!, which is to access the Index.html program under the root directory, then the Apache environment is OK.

The following needs to be configured so that Apache can run PHP applications, now need to go to the PHP website to download the operating environment

The process is not elaborate, the Windows version of the URL is: http://windows.php.net/download

Here you can download the latest version of php7.0.1 can also download php5.6.16 these two versions, but it is not recommended to download the lower 5.5, or 5.4 version

  

Here according to the number of operating systems must download the thread-safe version, that is, the version of the thread security, after downloading to c:/www, I download here is PHP7 so the path is: C:\WWW\PHP7

  

Then we will see in this directory, Php7apache2_4.dll this is Apache running PHP necessary components, and now continue to open Apache configuration file httpd.conf

Position the cursor in the last, new line input: LoadModule php7_module "C:/www/php7/php7apache2_4.dll"

This line of code means that the Apache server is introduced into the PHP module to support Web Access for PHP applications

Be aware that PHP5 and PHP7 are not the same.

  

Then, continue adding a row

AddType application/x-httpd-php. php. html. htm. php5

This is to tell Apache to identify the suffix of php files, so that the application of these suffixes to parse, we can also add later. PHP7

Last add a line: Phpinidir "C:/WWW/PHP7" This line of code is to tell the Apache server php.ini directory, so that the server read the configuration of PHP

To now add up, if it is PHP7, it is possible to follow the boot is unsuccessful, if the start is unsuccessful, then put Phpinidir last line, put in front of LoadModule, is to read the php.ini settings, loading PHP module, so generally successful

There is also a configuration method for PHP7 on the Internet:

Phpinidir "C:/WWW/PHP7"
LoadFile "C:/www/php7/php7ts.dll"
LoadFile "C:/www/php7/ssleay32.dll"
LoadFile "C:/www/php7/libeay32.dll"
LoadModule php7_module "C:/www/php7/php7apache2_4.dll"

is more than three lines of code, the introduction of 3 files, if the above method still does not work, you can try this method, because PHP7 release not much time, the subsequent problems will definitely solve

Here Apache server is all configured, we save httpd.conf on the line

Now go to the PHP directory, copy php.ini-development a copy, then rename the copy to: PHP.ini, then open the php.ini start configuration

we find; On Windows: this line

  

Put the following; Extension_dir = "ext" in front of the note, and then the EXT to the EXT directory under PHP, changed to Extension_dir = "C:/www/php7/ext" directory, this is the specified PHP extension of the directory, if this is not set, So you can only use PHP core functionality, another Curl operation, mbstring string operations, XML operations, MySQL operations can not be done, so this must be set up well

Some tutorials on the web say put C:\WWW\PHP7; C:\www\php7\ext added to the environment variable, here only to remove the semicolon, and some tutorials that the Ext directory DLL files are copied to C:\Windows, the comment here regardless of him, the reason is very simple because Windows is in the environment variables, These methods are essentially the same, is to let PHP through the php.ini configuration file read ext extension directory, so I personally recommend the first method is to specify the directory directly here, simple and flexible

Once you've opened it, you need to have a choice to open the appropriate extension.

  

These extensions here, remove the front, is the representative of the Open, here is recommended to open:

Php_mbstring.dll (the Chinese title or abstract will be found to be too useful)

Php_mysqli.dll

Php_mysql.dll (new version abolished, replaced with mysqli)

Php_curl.dll

Php_gd2.dll

Php_pdo_mysql.dll

Php_sockets.dll

Php_xmlrpc.dll

These extensions are generally sufficient, followed by specific opening if needed

In addition, the time zone configuration can also be changed, the function and in the program with the Date_default_timezone_set () function set the same, the default is UTC GMT, and Beijing time difference of 8 hours

  

This can be changed to: Date.timezone = Asia/shanghai or Date.timezone = PRC

Here we save the php.ini, then restart the Apache server, Test phpinfo () on it.

To now Apache server and PHP environment are configured to complete, more detailed personalized configuration, and needs to be based on the specific configuration of the project, the follow-up continues to add, the current environment of general development testing is no problem

In addition, the MySQL database is basically independent, installed separately, as long as we install, you can use PHP or other programming language to establish a connection to access the data in the database, the specific configuration is relatively independent

Configure Apache server under Windows and support PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.