Build apache php mysql process sharing under Windows

  • 2020-05-13 04:06:00
  • OfStack

Under windows, both apache and mysql have automatic installation procedures. This paper focuses on the process of setting up apache+php+mysql under windows from the aspects of apache and php version selection, php thread safety, apache and mysql installation startup services, and work environment configuration.

Apache download address: http: / / httpd apache. org/download cgi

php download address: http: / / windows php. net/download /

mysql download address: http: / / dev mysql. com/downloads mysql /

1. Version selection

According to the php website, different versions of php have different compilers to choose from and different packages to install apache.

Currently, the compilers vc11, php5.4, and php5.3 are vc9, php5.2 are vc6, but php5.2 is no longer updated.

There is one problem to note in particular: apache.org only provides a compiled version of vc6 under windows. In other words, if you choose the release version of apache.org, you can only choose php5.2, otherwise you may have a problem.

In addition, to run vc9 or vc11 compiled programs under windows, Visual C++ runtime needs to be installed. Visual C++ 2008(x86), Visual C++ 2008(x64), Visual C++ 2012(x86 or x64) can be downloaded from windows's official website.

If you are using php5.3 or above, it is recommended to download apache from ApacheLounge.com.

2. Thread safety

php thread safety is to ensure that php will not have non-1 data in multi-threaded environment, but non-thread safety may occur. Therefore, thread safety requires resource control, which adds extra overhead and is less efficient than non-thread safety in a single-threaded environment.

So, how do you choose to use either a thread-safe (Thread safe) or a non-thread-safe (Non Thread Safe) version?

1. DSO(mod_php, ISAPI, etc.)

In the form of DLL dynamic library, it can be executed after being requested by the user. After processing a user request, it will not disappear immediately. Therefore, thread safety check is needed to improve the execution efficiency of the program.
2. CGI(CGI, FastCGI)

With a single thread to perform operations, so there is no need to carry out thread safety checks, remove the protection of thread safety checks can improve the execution efficiency, here select a non-thread safe version.

3. Start the service

The installation package fool install is ignored here. If you manually install the apache and mysql services, refer to the following command


# The installation apache2.2 service
D:\apache2.2\bin\httpd.exe -k install
# Start the apache2.2 service
D:\apache2.2\bin\httpd.exe -k start # The installation mysql service
D:\mysql\bin\mysqld.exe -install
# Start the mysql service
sc start mysql

4. Configure the environment

1. Configure apache to support php


PHPIniDir "D:\php\php.ini"
LoadModule php5_module "D:\php\php5apache2_2.dll"
AddType application/x-httpd-php .php

2. Configure php to support mysql


extension_dir = "D:/php/ext"
extension = php_mysql.dll

3. php connects mysql


<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

If Apache cannot be started after setup, it will be helpful to refer to the article "solving the problem that Apache/PHP cannot be started".


Related articles: