windows2012服务器中安装php7+mysql5.7+apache2.4环境

1.下载安装apache.2.4

https://home.apache.org/~steffenal/VC14/binaries/httpd-2.4.38-win64-VC14.zip

 

解压到d盘的apache24目录

配置apache

修改 httpd.conf文件

# 定义

Define SRVROOT "d:\apache24"

ServerRoot "${SRVROOT}"

 

Listen 80

# 开启模块

LoadModule access_compat_module modules/mod_access_compat.so

LoadModule actions_module modules/mod_actions.so

LoadModule alias_module modules/mod_alias.so

LoadModule allowmethods_module modules/mod_allowmethods.so

LoadModule asis_module modules/mod_asis.so

LoadModule auth_basic_module modules/mod_auth_basic.so

LoadModule authn_core_module modules/mod_authn_core.so

LoadModule authn_file_module modules/mod_authn_file.so

LoadModule authz_core_module modules/mod_authz_core.so

LoadModule authz_groupfile_module modules/mod_authz_groupfile.so

LoadModule authz_host_module modules/mod_authz_host.so

LoadModule authz_user_module modules/mod_authz_user.so

LoadModule autoindex_module modules/mod_autoindex.so

LoadModule cgi_module modules/mod_cgi.so

LoadModule dir_module modules/mod_dir.so

LoadModule env_module modules/mod_env.so

LoadModule include_module modules/mod_include.so

LoadModule isapi_module modules/mod_isapi.so

LoadModule log_config_module modules/mod_log_config.so

LoadModule mime_module modules/mod_mime.so

LoadModule negotiation_module modules/mod_negotiation.so

LoadModule rewrite_module modules/mod_rewrite.so

LoadModule setenvif_module modules/mod_setenvif.so

LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

LoadModule ssl_module modules/mod_ssl.so

# 链接php的库文件

LoadModule php7_module "D:/php-7.1.26/php7apache2_4.dll"

AddHandler application/x-httpd-php .php

PHPIniDir "D:/php-7.1.26"

<IfModule unixd_module>

User daemon

Group daemon

</IfModule>

ServerAdmin admin@example.com

<Directory />

    AllowOverride none

    Require all denied

</Directory>

DocumentRoot "${SRVROOT}/htdocs"

<Directory "${SRVROOT}/htdocs">

 

切换到d盘 apache24/bin 目录,将apache注册为系统服务

Httpd.exe –k install –n “apache24”

 

直接打开 http://localhost

显示是否是ok,说明正常工作

 

 

2.下载配置php

注意一定是 VC14 x64 Thread Safe  版本才有apache的链接dll文件

Php下载地址:

https://windows.php.net/download#php-7.1

x86_64位,并且有apache的链接dll库文件

VC14 x64 Thread Safe (2019-Jan-10 00:43:38)  版本

 

 

php.ini文件配置:

max_execution_time = 30

max_input_time = 60

memory_limit = 256M

error_reporting = E_ALL

display_errors = On

display_startup_errors = On

log_errors = On

log_errors_max_len = 1024

post_max_size = 105M

default_mimetype = "text/html"

default_charset = "UTF-8"

# 开启扩展

extension_dir = "D:\php-7.1.26\ext"

file_uploads = On

# 上传临时目录

upload_tmp_dir = D:\temp

upload_max_filesize = 105M

max_file_uploads = 20

default_socket_timeout = 60

extension=php_curl.dll

extension=php_mbstring.dll

extension=php_mysqli.dll

[mail function]

SMTP = localhost

smtp_port = 25

mail.add_x_header = On

 

[SQL]

sql.safe_mode = Off

 

在存放网站数据目录:D:\apache24\htdocs中建立打印Php信息的php文件验证php环境是否ok

<?php

Echo phpinfo();

?>

访问 http://localhost/info.php

 

3.安装mysql5.7

下载mysql msi安装包

里面包含x64和x32位版本

创建一个账号 dbadmin,dbapass

测试php7操作mysql数据库代码:

create database china charset=utf8;

create table users(id int,username varchar(255));

insert into users(id username) values(1,'tom');

<?php
$servername = "localhost";
$username = "dbadmin";
$password = "dbpass";
$dbname = "china";
 
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
 
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
 
if ($result->num_rows > 0) {
    // 输出数据
    while($row = $result->fetch_assoc()) {
        echo $row['id'].','.$row['username'].'</br>';
    }
} else {
    echo "0 结果";
}

//添加记录

$insertSql = "insert into users(id, username) values(18, 'hanmeimei')";
$result = $conn->query($insertSql);
echo $result . "\n";


$conn->close();
?>

 

 

posted @ 2019-01-31 13:57  reblue520  阅读(2024)  评论(0编辑  收藏  举报