# Ubuntu 24.04效能調校

### Opcache

/etc/php/8.3/fpm/conf.d/10-opcache.ini

```bash
; configuration for php opcache module
; priority=10
zend_extension=opcache.so
opcache.jit=off

; 強化穩定性（可選）
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=192
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.save_comments=1
opcache.enable_file_override=0
opcache.file_update_protection=2  ;可選
```

/etc/php/7.4/fpm/conf.d/10-opcache.ini

```
; configuration for php opcache module
; priority=10
zend_extension=opcache.so

; 其他建議參數
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.save_comments=1
opcache.enable_file_override=0
```

網站內容穩定、不常更新 PHP 程式碼 opcache.validate\_timestamps=0

### APcu

<span class="s1">/etc/php/8.3/cli/conf.d/20-apcu.ini </span>

```
extension=apcu.so
# chatgpt add
apc.enabled=1
apc.shm_size=64M
apc.ttl=3600
apc.user_ttl=7200
apc.gc_ttl=3600
apc.entries_hint=4096
apc.smart=1
apc.enable_cli=0
```

<span class="s1">/etc/php/7.4/cli/conf.d/20-apcu.ini </span>

```
extension=apcu.so
# chatgpt add
apc.enabled=1
apc.shm_size=64M
apc.ttl=3600
apc.user_ttl=7200
apc.gc_ttl=3600
apc.entries_hint=4096
apc.smart=1
apc.enable_cli=0
```

### Nginx

<span class="s1">/etc/nginx/nginx.conf</span>

```
user www-data;
worker_processes auto;
worker_rlimit_nofile 100000;

events {
    worker_connections 10240;
    multi_accept on;
    use epoll;
}

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
```