Linux FTP ProFtpd server configuration: setup timeouts

First step before making any changes to configuration files is to create backup:
# cp -fvp /etc/proftpd.conf /etc/proftpd.conf-2013-03-08.bak

Second step is to check service configuration to make sure it is correct.
# proftpd -td10
Checking syntax of configuration file

Syntax check complete.

Edit configuration file /etc/proftpd.conf: add timout directives inside <Global> </Global> section.
TimeoutNoTransfer 900
TimeoutStalled 600
TimeoutIdle 1200

Detaied options description below:

The TimeoutNoTransfer directive configures the maximum number of seconds a client is allowed to spend connected, after authentication, without issuing a command which results in creating an active or passive data connection (i.e. sending/receiving a file, or receiving a directory listing).

The TimeoutStalled directive sets the maximum number of seconds a data connection between the proftpd server and an FTP client can exist but have no actual data transferred (i.e. “stalled”). If the seconds argument is set to 0, data transfers are allowed to stall indefinitely (the default).

The TimeoutIdle directive configures the maximum number of seconds that proftpd will allow clients to stay connected without receiving any data on either the control or data connection. If data is received on either connection, the idle timer is reset. Setting TimeoutIdle to 0 disables the idle timer completely (clients can stay connected for ever, without sending data). This is generally a bad idea as a “hung” tcp connection which is never properly disconnected (the remote network may have become disconnected from the Internet, etc) will cause a child server to never exit (at least not for a considerable period of time) until manually killed.

Next step after making configuration changes is to check FTP service configuration again:
# proftpd -td10

Restart service.

1. If your ProFTPD server installed as part of xinetd:
# /sbin/service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]

2. If your ProFTPD server installed as standard Linux service:
# /sbin/service proftpd restart
or
# /etc/init.d proftpd restart

Linux: enable or disable PHP APC opcode cache for virtual host

1. To install PHP APC module run commands:
# yum install php-devel php-pear pcre-devel
# pecl install apc

2. Example configuration file for APC
# more /etc/php.d/apc.ini
extension=apc.so
apc.enabled=”1″
; [ disable APC opcode cache by default
apc.cache_by_default=0
; ]
apc.shm_segments=”1″
apc.num_files_hint=”1024″
apc.ttl=”7200″
apc.user_ttl=”7200″
apc.gc_ttl=”3600″
apc.cache_by_default=”1″
;apc.filters=””
apc.slam_defense=”0″
apc.file_update_protection=”2″
apc.enable_cli=”0″
apc.max_file_size=”1M”
apc.stat=”1″
apc.write_lock=”1″
apc.report_autofilter=”0″
apc.include_once_override=”0″
apc.rfc1867=”0″
apc.rfc1867_prefix=”upload_”
apc.rfc1867_name=”APC_UPLOAD_PROGRESS”
apc.rfc1867_freq=”0″
apc.localcache=”0″
apc.localcache.size=”512″
apc.coredump_unmap=”0″
;default is 32M
apc.shm_size=512M
apc.mmap_file_mask=”/tmp/apcphp5.XXXXXX”
apc.mmap_address=703687441776
; file uploads progress for Drupal
apc.rfc1867=”1″
#

To check web server Apache configuration run command:
# /sbin/service httpd configtest

To apply new APC module configuration restart web server Apache using command:
# /sbin/service httpd restart

3. Example changes in main .htaccess file for virtual host shkodenko.com
# vim /home/taras/shkodenko.com/public_html/.htaccess

3.1. To enable APC opcode cache for virtual host inside IfModule block add line:

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>

# [ enable APC opcode cache for domain
php_flag apc.cache_by_default On
# ]

</IfModule>

3.2. To disable APC opcode cache for virtual host inside IfModule block add line:

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>

# [ disable APC opcode cache for domain
php_flag apc.cache_by_default Off
# ]

</IfModule>

Backup WordPress website procedure for Linux

To backup your WordPress website on Linux you can follow these steps:

1. Log in via ssh to your server.

2. Change directory where your website files are located. For example:
$ cd /home/shkodenko/public_html

3. Find out MySQL connection settings using command:
$ grep -ni "DB" ./wp-config.php

You will need these lines below.
19:define(‘DB_NAME’, ‘db_name’);
22:define(‘DB_USER’, ‘db_user’);
25:define(‘DB_PASSWORD’, ‘db_password’);
28:define(‘DB_HOST’, ‘localhost’);

4. Create backup of MySQL database using mysqldump utility. For example:
$ mysqldump -h localhost -u db_user -p db_name > ./wp-content/uploads/db_name.sql

5. I am checking MySQL dump using tail and head utilities:
$ tail -n 15 -f ./wp-content/uploads/db_name.sql
$ head -n 15 -f ./wp-content/uploads/db_name.sql
I am using sha1sum command to get SQL dump file checksum:

$ sha1sum -b ./wp-content/uploads/db_name.sql
I am checking SQL dump file information usinng ls command:

$ ls -Alh ./wp-content/uploads/db_name.sql
All these steps above in 5 can be skipped. I making these checks for history and possible future verification purposes if something will go wrong.

6. Making archive:
tar cpjf /home/shkodenko/shkodenko.com-backup.tar.bz2 ./

7. Some additional commands for verification with backup file:
$ sha1sum -b /home/shkodenko/shkodenko.com-backup.tar.bz2
$ ls -Alh /home/shkodenko/shkodenko.com-backup.tar.bz2

8. Cleaning garbage:
$ rm -fv ./wp-content/uploads/db_name.sql

Linux FTP ProFtpd server configuration: enable display hidden files

I have been working with some Linux servers with Plesk control panel. By default ProFtpd FTP server is configured to not display hidden files.

To fix this edit ProFtpd main configuration file /etc/proftpd.conf add line below:
ListOptions “-a”
inside <Global> </Global> section.

Check ProFtpd configuration using command:

# proftpd -t6

Checking syntax of configuration file
Syntax check complete.

Restart service.

1. If your ProFTPD server installed as part of xinetd:

# /sbin/service xinetd restart

Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]

2. If your ProFTPD server installed as standard Linux service:

# /sbin/service proftpd restart

or

# /etc/init.d proftpd restart

Linux: check system, PHP and MySQL date and time

Sometimes it can be useful to verify if system, PHP and MySQL date and time is synced.
I am using this set of commands to check:

# date ; php -r "echo date('r').PHP_EOL;" ; mysql -e "SELECT NOW();"

Also, it can be useful to check the same information on remote server without logging in to it. It can be done using the same above set of commands plus ssh utility:

ssh taras@shkodenko.com 'date ; php -r "echo date(\"r\").PHP_EOL;" ; mysql -e "SELECT NOW();"'

Linux: how to kill hanged process

Sometimes, when I am working on Linux, some programs are hanging system, so further work is impossible.
I am using this set of commands to find out PID and other data of hanged process in good readable format (KeePass as example):

$ ps aux |head -n 1; ps aux |grep -v grep |grep -i pass
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
1000 29015 13.1 0.2 824732 40408 ? Sl 14:56 0:02 /usr/bin/mono /usr/bin/KeePass/KeePass.exe

Using this command below to terminated hanged process:

$ kill -s 9 29015

Do you have something to say more on this subject?

MySQL error: failed to connect to server on ‘xxx.yyy.zzz.aaa’ (113)

Sometimes using MySQL Workbench I am getting this kind of errors:

Failed to Connect to MySQL at xxx.yyy.zzz.aaa:3306 with user db_user
Can’t connect to MySQL server on ‘xxx.yyy.zzz.aaa’ (113)

To fix it add configuration directive:
skip_name_resolve = off
to main MySQL configuration file /etc/my.cnf using your favorite text editor (mine is Vim).
to section [mysqld]
and restart MySQL server using command as root:

# /etc/init.d/mysqld restart