갈루아의 반서재

워드프레스의 경우 기본적으로 최대 업로드 파일 크기가 2MB로 설정되어 있어 불편한 점이 많다. 최대 사이즈 설정을 변경해보자.


여기서는 php.ini 파일의 수정값을 통해 진행해보기로 한다.

php.ini 파일은 우분투의 경우 통상 아래의 2군데에 위치해있는데 2개의 파일 모두를 수정해야 한다.


/etc/php/7.2/fpm/php.ini

/etc/php/7.2/cli/php.ini


수정해야할 내용은 두 파일 모두 동일하다. 먼저 fpm 디렉토리의 설정파일부터 수정해보자.

1
root@hilbert:/etc/php/7.2/fpm# nano php.ini
cs

파일을 열어 먼저 upload_max_filesize 를 기존 2M 에서 원하는 크기로 수정해준다. Ctrl + W 를 이용하면 손쉽게 해당 항목을 찾을 수 있다. 그리고 post 당 업로드 파일의 갯수도 수정할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
 
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
 
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
 
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 64M
 
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
 
cs

포스트당 사이즈도 수정해준다.

1
2
3
4
5
6
 
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 64M
cs

각각의 스크립트의 실행시간을 늘린다.

1
2
3
4
5
 
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 1000
cs

스크립트가 소진하는 메모리의 크기도 수정하자.

1
2
3
4
 
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 256M
cs

어떤 경우에는 -1 로 되어 있는 경우도 있는데, -1 의 의미는 메모리의 최대 사이즈를 쓴다는 의미이다.

1
2
3
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = -1;
cs


위와 마찬가지로 cli 디렉토리의 설정파일도 수정해준다.

1
root@hilbert:/etc/php/7.2/cli# nano php.ini
cs


다음으로 nginx 환경설정을 수정해야한다.

1
root@hilbert:/etc/nginx# nano nginx.conf
cs

설정파일을 열고 아래 client_max_body_size 64m; 을 기본 셋팅에 추가한다. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
 
events {
    worker_connections 768;
    # multi_accept on;
}
 
http {
 
    ##
    # Basic Settings
    ## 
    client_max_body_size 64m;
 
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;
cs


파일을 저장한 후 php-fpm 과 nginx 를 모두 재시작해줍니다.

1
2
root@hilbert:/etc/nginx# sudo systemctl restart php7.2-fpm
root@hilbert:/etc/nginx# sudo systemctl reload nginx
cs


업로드 사이즈가 기존 2MB 에서 64MB 로 늘어났음을 확인할 수 있다.