Windows Server 2012 + PHPStudy 环境优化方案

低配置云服务器的性能优化


Windows Server 2012[内存2G] + PHPStudy 8.1.1.3环境(PHP 8.2.4 NTS + Apache 2.4.39 + MySQL 8.0),以下是详细的优化配置和示例代码:

一、PHP配置优化 (php.ini)

[PHP]
; 内存限制
memory_limit = 128M

; OPcache配置
zend_extension=php_opcache.dll
opcache.enable=1
opcache.memory_consumption=64
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

; 进程管理
max_execution_time = 30
max_input_time = 60
max_input_vars = 1000

; 禁用危险函数
disable_functions = exec,passthru,shell_exec,system,proc_open,popen

; 会话处理
session.gc_maxlifetime = 1440
session.save_handler = files
session.save_path = "C:/phpstudy_pro/tmp/session"

二、Apache配置优化 (httpd.conf)

# 在httpd.conf末尾添加:

# 基本优化
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

# 模块优化(禁用不需要的模块)
#LoadModule access_compat_module modules/mod_access_compat.so
#LoadModule authn_anon_module modules/mod_authn_anon.so

# 进程优化
<IfModule mpm_prefork_module>
    StartServers          2
    MinSpareServers       2
    MaxSpareServers       5
    MaxRequestWorkers     50
    MaxConnectionsPerChild 3000
</IfModule>

# 压缩配置
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript text/xml
</IfModule>

# 静态文件缓存
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
</IfModule>

三、MySQL 8.0配置优化 (my.ini)

[mysqld]
# 基础配置
table_open_cache=400
table_definition_cache=400

# 内存优化
innodb_buffer_pool_size=512M
key_buffer_size=32M
tmp_table_size=32M
max_heap_table_size=32M

# 连接控制
max_connections=30
thread_cache_size=10
wait_timeout=60
interactive_timeout=60

# InnoDB优化
innodb_flush_log_at_trx_commit=2
innodb_log_file_size=64M
innodb_log_buffer_size=8M
innodb_io_capacity=200

四、WordPress专用优化

1. wp-config.php 关键设置

// 内存设置
define('WP_MEMORY_LIMIT', '96M');
define('WP_MAX_MEMORY_LIMIT', '128M');

// 禁用修订版本
define('WP_POST_REVISIONS', 3);

// 禁用自动保存
define('AUTOSAVE_INTERVAL', 300);

// 禁用文件编辑
define('DISALLOW_FILE_EDIT', true);

// 启用缓存
define('WP_CACHE', true);

五、PHPStudy特定优化

  1. 组件选择

    • 只启用必要的组件(Apache+PHP+MySQL)
    • 禁用FTP、Nginx等其他服务
  2. 端口优化

    • 修改默认端口(避免冲突)
    • 在PHPStudy面板中关闭不必要的端口
  3. 日志管理

    • 设置日志文件大小限制(不超过50MB)
    • 启用日志轮转


转载请注明出处:  https://www.cntworld.cn
智能工控 » Windows Server 2012 + PHPStudy 环境优化方案

发表回复

提供最优质的资源集合

立即查看 了解详情
文章加载时间:0.0043 秒