使用nohup在背景中執行程式

通常使用putty進行ssh連線時,常常遇到要長時間的執行一個指令
而半徒若將putty關閉的話,這個程式也將會被終止.
因此必須將程式放置到背景中執行

方法1: 執行結果輸出至nohup.out

nohup command &

方法2: 指定輸出logfile

nohup command > logfile &

方法3: 不要輸出任何資訊

nohup command >/dev/null 2>&1 &

若要搭配sudo的話,其用法如下

sudo sh -c 'nohup command &'

php.ini 常見設定

php.ini檔案位置/etc/php5/apache2/php.ini
php-fpm檔案位置/etc/php5/fpm/php.ini
而php cli位置應該是在 /etc/php5/cli/php.ini

sudo vim /etc/php5/apache2/php.ini
# or
sudo vim /etc/php5/fpm/php.ini
# or
sudo vim /etc/php5/cli/php.ini

可以用下列指令確認

php -i |grep php\.ini

我個人常用的設定為(for debug):

short_open_tag=On
memory_limit=2000M
error_reporting=E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT
display_error=On
post_max_size=20000M
upload_max_filesize=20000M
max_file_uploads=200

其中,memory_limit > post_max_size > upload_max_filesize

修改之後,得要重新啟動apache2

sudo /etc/init.d/apache2 restart
# or
sudo service apache2 restart

vim 快速修改方式:

#for apache2
sudo vim /etc/php5/apache2/php.ini
:1,$s/short_open_tag\ =\ Off/short_open_tag\ =\ On/g
:1,$s/memory_limit\ =\ 128M/memory_limit\ =\ 2000M/g
:1,$s/display_errors\ =\ Off/display_errors\ =\ On/g
:1,$s/post_max_size\ =\ 8M/post_max_size\ =\ 2000M/g
:1,$s/upload_max_filesize\ =\ 2M/upload_max_filesize\ =\ 2000M/g
:1,$s/max_file_uploads\ =\ 20/max_file_uploads\ =\ 200/g
/error_reporting
/
:1,$s/error_reporting\ =\ E_ALL\ &\ \~E_DEPRECATED\ &\ \~E_STRICT//g
aerror_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT
#for cli
sudo vim /etc/php5/cli/php.ini
:1,$s/short_open_tag\ =\ Off/short_open_tag\ =\ On/g
:1,$s/memory_limit\ =\ 128M/memory_limit\ =\ 2000M/g
:1,$s/display_errors\ =\ Off/display_errors\ =\ On/g
:1,$s/post_max_size\ =\ 8M/post_max_size\ =\ 2000M/g
:1,$s/upload_max_filesize\ =\ 2M/upload_max_filesize\ =\ 2000M/g
:1,$s/max_file_uploads\ =\ 20/max_file_uploads\ =\ 200/g
/error_reporting
/
:1,$s/error_reporting\ =\ E_ALL\ &\ \~E_DEPRECATED\ &\ \~E_STRICT//g
aerror_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT