우분투 php 재시작 - ubuntu php jaesijag

우분투에서 apt-get으로 설치한 PHP를 기준으로 설정합니다.

우분투 php 재시작 - ubuntu php jaesijag

php.ini 위치 : /etc/php5/apache2/php.ini

기본값으로 제공되는 php.ini 파일은 실서비스를 위한 환경설정(php.ini-production) 내용을 담고 있으며, 개발을 위한 환경설정(php.ini-development)도 샘플파일로 제공을 한다.

샘플파일 위치 : /usr/share/php5/

.htaccess를 이용한 php.ini 수정

호스팅을 받는 경우나 특정한 사이트에만 설정내용을 반영하고 싶을 경우는 해당 사이트의 루트에 .htaccess 파일을 생성하여 설정할 수 있다.

php_value upload_max_filesize 50M
php_value post_max_size 50M
php_flag register_globals off
php_flag magic_quotes_gpc on

업로드 설정

sudo vi /etc/php5/apache2/php.ini

  ; 파일업로드 허용여부
  file_uploads = On  

  ; 최대 업로드 파일 사이즈 
  upload_max_filesize = 10M 

  ; Post 방식으로 넘겨질 최대 데이터 사이즈
  post_max_size = 10M    
 
  ; 최대 실행시간. 파일 사이즈가 클수록 시간을 늘려주어야함. 0은 무한대
  max_execution_time = 30    

  ; 스크립트 페이지로 넘어가기 전에 php엔진이 데이터를 업로더 받는 시간
  max_input_time = 3600    

  ; 메모리 사용량 제한
  memory_limit = 128M 

Apache 재시작

sudo service apache2 restart

upload_max_filesize와 post_max_size

폼을 이용해 전송되는 업로드 파일은 'multipart/form-data'라는 포맷으로 전송된다. 이때 전송량에 상한선을 설정할 수 있는데 이 값은 post_max_size이며 이 값은 upload_max_filesize보다 크게 잡는 것을 추천한다.

post_max_size > upload_max_filesize

upload_max_file_size는 업로드하는 모든 파일의 크기의 합이라는 것을 인지하는게 중요하다. post_max_size는 upload_max_filesize와 인코더(encoder)를 포함한 mine 헤더 양식을 더한 모든 다른 필드 길이 합계이다. 이 필드들의 값은 일반적으로 작은 사이즈의 크기이기 때문에 종종 post_max_size의 값을 upload_max_size의 값으로 설정하곤 한다. 이 값들은 2048M 미만으로 적용가능하다.(2Gb)

기본값 post_max_size = 8M / upload_max_filesize = 2M

memory_limit

php엔진이 POST로 전달되는 데이터를 처리하는 경우에는 전달되는 데이터의 일부를 유지하기 위해 메모리가 사용된다. php를 설치시에 --enable-memory-limit 옵션이 설정되었을때만 영향을 끼친다(우분투에서 php설치시 활성화됨). memory_limit 값을 너무 높은 값을 설정하는 것은 매우 위험할 수 있는데, 이는 여러개의 업로드들이 동시에 처리되는 경우 사용가능한 모든 메모리를 사용해버려 다른 관련없는 스크립트뿐만 아니라 서버 전체에 영향을 미치게 된다. 이 값을 0으로 설정하는 경우 메모리의 제한이 없어진다.

기본값 memory_limit = 128M

max_execution_time과 max_input_time

max_execution_time은 스크립트의 최대 실행 시간이고 이 값이 0이면 무제한, max_input_time은 스크립트가 입력을 받아들일때 소비할 수 있는 시간이며 -1이면 무제한, 잘못된 스크립트 사용시 서버가 무한루프에 빠지는것을 방지하기 위한 부분이다.

만일 여러 메가 바이트의 데이터를 전송해야 하는 경우 max_input_time은 높아야 한다. 또한, 스크립트에서 set_time_limit() 함수를 호출해서 max_input_time의 ini파일의 설정을 재정의 할 수 있다. php에서 set_time_limit(0)으로 설정하면 두가지 시간을 모두 제어할수 있어 업로드페이지에 이 코드를 삽입하는 것을 추천한다.

기본값 max_execution_time = 30 / max_input_time = 60

Apache 설정

아파치 웹서버에서는 LimitRequestBody라는 지시어를 사용해 POST 데이터에 제한을 할 수 있는데 이 값이 설정되어 있다면 다른것 보다 우선시 되니 유의해야 한다. 몇몇의 배포판 설치시에 이 값이 512kb로 설정되어 있기도 하다.

여러개의 웹사이트를 사용할 경우 기본값을 설정해 두고 대용량의 업로드 설정이 필요한 경우 아래와 같이 .htaccess 를 이용해 필요한 사이트에만 적용하도록 하자.

최대 파일 업로드 사이즈를 2000 메가바이트로
php_value upload_max_filesize 2000M
최대 POST 데이터 사이즈를 2000 메가바이트로

POST 데이터 = 업로드 파일 데이터 + 헤더 등 요청데이터 이므로 upload_max_filesize보다 크게 잡는게 산술적으로 옳다.

php_value post_max_size 2000M
실행시간 무한대

php 스크립트에 set_time_limit(0) 설정 추천, 그게 불가능할경우 아래 설정사용

php_value max_execution_time 0
최대 메모리 무한대
php_value memory_limit 0
업로드 설정시 유의사항

업로드 디렉토리 안의 php 파일 실행 불가

<Directory "/var/www/wordpress/wp-content/uploads/">
  php_admin_value engine off
</Directory>

에러 출력

기본적으로 실서비스를 위해 에러출력이 Off 되어 있다. 개발환경을 위해서는 이를 On 시키도록 하자.

display_errors = On

시간대 설정

date.timezone = Asia/Seoul

date.timezone이 주석처리 되어 있을 경우에, 오류 발생시 항상 다음과 같은 에러가 따라온다.

Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.

위와 같은 date.timezone = Asia/Seoul 로 설정해주면 해결됨.

I need to reload my php.ini and there's nothing in the help dialog about restarting it.

asked Oct 12, 2010 at 1:58

Note: prepend sudo if not root

  • Using SysV Init scripts directly:

    /etc/init.d/php-fpm restart    # typical
    /etc/init.d/php5-fpm restart   # debian-style
    /etc/init.d/php7.0-fpm restart # debian-style PHP 7
    
  • Using service wrapper script

    service php-fpm restart    # typical
    service php5-fpm restart   # debian-style
    service php7.0-fpm restart # debian-style PHP 7
    
  • Using Upstart (e.g. ubuntu):

    restart php7.0-fpm         # typical (ubuntu is debian-based) PHP 7
    restart php5-fpm           # typical (ubuntu is debian-based)
    restart php-fpm            # uncommon
    
  • Using systemd (newer servers):

    systemctl restart php-fpm.service    # typical
    systemctl restart php5-fpm.service   # uncommon
    systemctl restart php7.0-fpm.service # uncommon PHP 7
    

Or whatever the equivalent is on your system.

answered Oct 12, 2010 at 3:37

tylerltylerl

14.9k7 gold badges49 silver badges71 bronze badges

5

For Mac OS X, this is what I do:

Make a script /usr/local/etc/php/fpm-restart:

#!/bin/sh

echo "Stopping php-fpm..."
launchctl unload -w ~/Library/LaunchAgents/homebrew-php*.plist

echo "Starting php-fpm..."
launchctl load -w ~/Library/LaunchAgents/homebrew-php*.plist

echo "php-fpm restarted"
exit 0

Then:

chmod ug+x /usr/local/etc/php/fpm-restart
cd /usr/local/sbin
ln -s /usr/local/etc/php/fpm-restart

make sure /usr/local/sbin is in your $PATH

then just call it from the terminal fpm-restart and BOOM!!

Falcon Momot

25k13 gold badges61 silver badges92 bronze badges

answered Sep 23, 2013 at 4:55

3

Usually, service php5-fpm restart will do fine, on an up-to-date distribution.

But somtimes, it fails, telling you restart: Unknown instance: (or such).

Now, if you do not like to reboot your server, just kill the processes and have a fresh start (edited as of here):

$ sudo pkill php5-fpm; sudo service php5-fpm start

answered Aug 8, 2014 at 11:55

BurninLeoBurninLeo

8602 gold badges11 silver badges28 bronze badges

1

This should work:

pkill -o -USR2 php-fpm
pkill -o -USR2 php5-fpm

answered Feb 1, 2011 at 20:08

dialt0nedialt0ne

3,02718 silver badges27 bronze badges

5

For Mac OSX brew services restart php56 worked for me.

answered Dec 30, 2015 at 21:25

우분투 php 재시작 - ubuntu php jaesijag

1

I had a problem restarting php7-fpm, because I didn't knew how exactly the service was named. This function gave me the answer:

service --status-all

php7-fpm service in my Ubuntu was called php7.0-fpm, so I did:

service php7.0-fpm restart

answered Mar 26, 2017 at 8:57

GediminasGediminas

2172 silver badges8 bronze badges

1

php-fpm will restart if you send a USR2 signal to the main process:

sudo kill -USR2 php-fpm_main_process_id

So we just need to instruct php-fpm to record its pid somewhere. In this example, I'll assume you want to save it at /etc/private/php-fpm.pid, and that php-fpm runs as user _php. First, add this line to the configuration file:

pid = /etc/php-fpm.pid

Then create the file /etc/php-fpm.pid, and make sure php-fpm has permission to modify it:

$ cd /etc
$ sudo touch php-fpm.pid
$ sudo chown _php php-fpm.pid
$ sudo chmod 644 php-fpm.pid

Now, next time php-fpm starts, you'll be able to get its pid and restart it like this:

$ cat /etc/php-fpm.pid
815
$ sudo kill -USR2 815

Or you can combine these into a single command:

$ sudo kill -USR2 `cat /etc/private/php-fpm.pid`

answered Mar 12, 2014 at 7:01

PitarouPitarou

1611 silver badge3 bronze badges

2

For me I had just upgraded via apt and the service restart wasn't working. I ended up needing to kill the existing processes before it worked using: killall php5-fpm

answered Sep 25, 2013 at 19:24

PoochPooch

1612 bronze badges

To allow the PHP-FPM restart script to work, you must use specify a PID file in your php-fpm.conf file. i.e.

pid = /var/run/php-fpm/php-fpm.pid

The default value for pid in php-fpm.conf is nothing, which means to not create a PID file, which means that the restart script can't tell which process to end during the restart.

answered May 11, 2013 at 15:03

우분투 php 재시작 - ubuntu php jaesijag

DanackDanack

1,1861 gold badge14 silver badges27 bronze badges

On CentOS 7

sudo systemctl enable php-fpm // Just incase is disabled. Also ensures it starts automatically with the server

sudo systemctl start php-fpm  // Start the service

sudo systemctl stop php-fpm   // Stop the service

sudo systemctl status php-fpm  // View status

answered Jun 28, 2016 at 10:44

우분투 php 재시작 - ubuntu php jaesijag

On Ubuntu 16 with php 5.6 fpm.

 /etc/init.d/php5.6-fpm restart

answered Oct 11, 2016 at 9:20

우분투 php 재시작 - ubuntu php jaesijag

MrPHPMrPHP

1416 bronze badges

On RedHat / CentOS 7 using PHP 7 from softwarecollections.org

service rh-php70-php-fpm start
service rh-php70-php-fpm stop
service rh-php70-php-fpm reload
service rh-php70-php-fpm restart
service rh-php70-php-fpm status

or if you're using systemctl:

systemctl start rh-php70-php-fpm
systemctl stop rh-php70-php-fpm
systemctl reload rh-php70-php-fpm
systemctl restart rh-php70-php-fpm
systemctl status rh-php70-php-fpm

answered Jun 3, 2017 at 16:17

우분투 php 재시작 - ubuntu php jaesijag

The simplest way to find the name of php-fpm service is to search for it:

systemctl -l --type service --all | grep fpm

answered Mar 17, 2019 at 16:33

우분투 php 재시작 - ubuntu php jaesijag

1

On Windows:

  1. Open Services in the Management Console:

    Start -> Run -> "services.msc" -> OK
    
  2. Select php-fpm from the list

  3. Rightclick and select restart

answered Sep 9, 2015 at 6:46

Gerald SchneiderGerald Schneider

20.1k8 gold badges52 silver badges79 bronze badges

For old versions of debian & ubuntu - php 5.6 it will be

 /etc/init.d/php-fpm56 restart
 service php-fpm56 restart

우분투 php 재시작 - ubuntu php jaesijag

answered Sep 9, 2015 at 6:01

On Alpine with nginx this is working here:

To kill all php-fpm7 processes:

kill $(ps -o pid,comm | grep php-fpm7 | awk '{print $1}')

To start php-fpm7:

php-fpm7

answered May 16, 2017 at 20:08

To list systemd services on CentOS/RHEL 7.x+ use

systemctl

To list all services:

systemctl list-unit-files

Where you can find service named * php-fpm * copy service name and run the following command

systemctl restart ea-php72-php-fpm.service

NOTE : ea-php72-php-fpm.service user your service name

answered Nov 26, 2018 at 8:55

우분투 php 재시작 - ubuntu php jaesijag

Another method for MaxOS

Open ActivityMonitor, search php-fpm, find the pid.

Open terminal, use kill [pid] to stop php-fpm

Then php-fpm on terminal to start it.

If there is error information that 127.0.0.1:9000 Already in use, just ignore that.

Refresh Nginx page, should see php.ini changes take effects.

answered Sep 23, 2019 at 8:31

1