nGinx/PHP not Upgrading – Fix Update Errors

When trying to update/upgrade nGinx or PHP by typing apt-get update && apt-get upgrade, do you get some error like the following error or any other error?

dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)

If so, try typing in these three lines of code, one at a time, and hopefully, you’ll be able to upgrade nGinx/PHP:

apt-get clean
apt-get dist-upgrade
apt-get -f install

Troubleshooting

These two commands may provide additional information, used for troubleshooting any nGinx update/upgrade errors or issues:

which nginx
dpkg -L nginx

Run Cron Job as www-data or Different User

To run a cron job as a specific user or www-data, follow these simple steps.

Type in: nano /etc/crontab

Then, add your cron job at the end of this file with the user’s name before the command to run. For example:

0 0-3,5-23 * * * www-data /usr/bin/php /var/website/script.php >> /var/website/log/`date "+\%Y-\%m-\%d.\%H-\%M-\%S"`.script.cron.txt 2>&1

The above cron job runs hourly except at 4am, and is run by www-data. It also saves output to a log file (named based on the current time) and disables email alerts sent to you upon cron execution.

Install FFmpeg on Ubuntu Linux Command Line

This quick tutorial will help you install FFmpeg if typing apt-get install ffmpeg via SSH is not installing FFmpeg for you, but instead giving you some message like:

Package ffmpeg is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package ‘ffmpeg’ has no installation candidate

Let’s cut to the chase. Just type in these three commands to install FFmpeg on Ubuntu Linux 14.04 (Trusty) via SSH command line:

3-Step FFmpeg Ubuntu Installation Tutorial

  1. add-apt-repository ppa:mc3man/trusty-media
  2. apt-get update && apt-get dist-upgrade
  3. apt-get install ffmpeg

Further reading:

Install Postfix

When you are prompted to configure Postfix, push Enter.

Postfix Installation Ajenti Ubuntu Linux

Then make sure Internet Site is selected and push Enter.

Postfix Configuration Internet Site Ubuntu

For System mail name, put your server name without the subdomain and push Tab and then push Enter. For example, if your server’s name is john.example.com, put in example.com in this field.

Postfix Configuration System Mail Name

For Root and postmaster mail recipient, enter in the admin’s username. Push Tab and then push Enter.

Postfix Configuration Root and Postmaster Recipient

For Other destinations to accept mail for, ensure something like the following is entered in:

server1.example.com, example.com, localhost.example.com, localhost

Then push Tab and then push Enter.

Postfix Configuration Other Destinations to Accept Mail

For Force synchronous updates on mail queue, select No. Then push Tab and then push Enter.

Postfix Configuration Force Synchronous Updates Mail Queue

For Local networks, you may leave this blank to use the defaults or enter in 127.0.0.0/8. Then push Tab and then push Enter.

Postfix Configuration Local Networks Ubuntu

For Mailbox size limit (bytes), enter in 0, which means no limit. Then push Tab and then push Enter.

Postfix Configuration Mailbox Size Limit Bytes

For Local address extension character, put in a plus sign: +. Then push Tab and then push Enter.

Postfix Configuration Local Address Extension Character

For Internet protocols to use, select all. Then push Tab and then push Enter.

Postfix Configuration Internet Protocols to Use All

Postfix Configuration Finished Setup

You might see a warning like the following:

WARNING: /etc/aliases exists, but does not have a root alias

If so, type in the following:

postconf -e 'home_mailbox = Maildir/'

Then type this:

postconf -e 'mailbox_command ='

Now, we will configure Postfix to do SMTP AUTH using SASL (saslauthd). To do so, type in the following:

postconf -e 'smtpd_sasl_local_domain =' && postconf -e 'smtpd_sasl_auth_enable = yes' && postconf -e 'smtpd_sasl_security_options = noanonymous' && postconf -e 'broken_sasl_auth_clients = yes' && postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination' && postconf -e 'inet_interfaces = all'

Now, we will add two lines to /etc/postfix/sasl/smtpd.conf by typing in the following:

echo -e "pwcheck_method: saslauthd\nmech_list: plain login" >> /etc/postfix/sasl/smtpd.conf

Now, we will generate certificates to be used for TLS encryption and/or certificate Authentication by typing in the following set of commands, one at a time:

touch smtpd.key
chmod 600 smtpd.key
openssl genrsa 1024 > smtpd.key
openssl req -new -key smtpd.key -x509 -days 3650 -out smtpd.crt

When asked for a Country Name, put in the two-letter code for your country (e.g. US). For State or Province Name, enter in your state (e.g. DC). For Locality Name, enter in your city (e.g. Washington). For Organization Name, enter the name of your organization. For Organizational Unit Name, enter in anything. For the Common Name, enter in the domain name you want associated with your server (or your IP address if you don’t have a domain name). For Email Address, enter in the administrator’s email address.

Now type in the following:

openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

When asked for a PEM pass phrase, enter in a secure password. Then re-enter it when prompted. When asked for a Country Name, put in the two-letter code for your country (e.g. US). For State or Province Name, enter in your state (e.g. DC). For Locality Name, enter in your city (e.g. Washington). For Organization Name, enter the name of your organization. For Organizational Unit Name, enter in anything. For the Common Name, enter in the domain name you want associated with your server (or your IP address if you don’t have a domain name). For Email Address, enter in the administrator’s email address.

Now, enter in the following set of commands:

mv smtpd.key /etc/ssl/private/ && mv smtpd.crt /etc/ssl/certs/ && mv cakey.pem /etc/ssl/private/ && mv cacert.pem /etc/ssl/certs/

Next, enter in the following set of commands to configure Postfix to do TLS encryption for both incoming and outgoing mail:

postconf -e 'smtp_tls_security_level = may' && postconf -e 'smtpd_tls_security_level = may' && postconf -e 'smtpd_tls_auth_only = no' && postconf -e 'smtp_tls_note_starttls_offer = yes' && postconf -e 'smtpd_tls_key_file = /etc/ssl/private/smtpd.key' && postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt' && postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem' && postconf -e 'smtpd_tls_loglevel = 1' && postconf -e 'smtpd_tls_received_header = yes' && postconf -e 'smtpd_tls_session_cache_timeout = 3600s' && postconf -e 'tls_random_source = dev:/dev/urandom' && postconf -e 'myhostname = server1.example.com'

In case you accidentally exit the Postfix configuration too early or do not see the Postfix configuration menu, simply type in the following to re-configure Postfix:

dpkg-reconfigure postfix

Best VPS Server Backup Strategy Tutorial

This backup method will back up your local VPS databases, files, and configuration settings to another (remote) server of yours. It will also back up your remote server’s files to your local VPS.

Step 1: Install Zip

We must first make sure the zip package is installed. To do so, type in the following via SSH:

dpkg -l zip

If you get something like dpkg-query: no packages found matching zip, then you do not have the zip package installed. However, if you get something that lists the name and version number of the zip package, this means you have the zip package installed.

If you do not have the zip package installed, type the following to install it:

apt-get install zip

When prompted whether or not you want to continue, type Y and then hit Enter.

Step 2: Generate SSH Keys

On your local server, via SSH, type in the following to generate SSH Keys:

ssh-keygen -t rsa -b 4096

When asked to “Enter file in which to save the key”, hit Enter.

When asked to “Enter passphrase (empty for no passphrase)”, hit Enter.

When asked to “Enter same passphrase again”, hit Enter.

Now, type in the following to copy the public key to the remote server using ssh-copy-id:

ssh-copy-id -i ~/.ssh/id_rsa.pub root@123.123.123.123

When asked “Are you sure you want to continue connecting”, type yes and hit Enter.

When prompted for the password of your remote server, type it in and hit Enter.

Now, test to make sure the SSH keys were properly added by trying to log in to the remote server by typing in the following:

ssh root@123.123.123.123

You should be granted access to your remote server without being prompted for a password.

Repeat these same steps on your remote server if you also want to back up your remote server to your local server.

Log on to your other server. Via SSH, type in the following to generate SSH Keys:

ssh-keygen -t rsa -b 4096

When asked to “Enter file in which to save the key”, hit Enter.

When asked to “Enter passphrase (empty for no passphrase)”, hit Enter.

When asked to “Enter same passphrase again”, hit Enter.

Now, type in the following to copy the public key to your other server using ssh-copy-id:

ssh-copy-id -i ~/.ssh/id_rsa.pub root@321.321.321.321

When asked “Are you sure you want to continue connecting”, type yes and hit Enter.

When prompted for the password of your remote server, type it in and hit Enter.

Now, test to make sure the SSH keys were properly added by trying to log in to the remote server by typing in the following:

ssh root@321.321.321.321

You should be granted access to your remote server without being prompted for a password.

Step 3: Create Backup Directory

We must first create a directory which will store the backups. On each of your servers, type in the following to create the directory which will store the backups:

mkdir /var/backups

Step 4: Create Configuration File for MySQL Database Dumps without using Password

On each of your servers, type in the following to create a new file (with restricted permissions) which will allow us to back up all databases without having to enter in a password each time. Substitute yourpassword with the actual password for your root MySQL user.

echo -e '[mysqldump]\npassword=yourpassword' > /etc/custom/.my.cnf && chmod 0440 /etc/custom/.my.cnf

Step 5: Back Up

On each of your servers you’d like to back up, type in the following to create a backup script:

rm -f /var/backups/firstserver.zip && echo "mysqldump --defaults-file=/etc/custom/.my.cnf --user='root' --all-databases --events --ignore-table=mysql.event > /var/backups/databases.sql && crontab -l > /var/backups/crontab && zip -r /var/backups/firstserver.zip /etc/hosts /etc/hostname /etc/apt/sources.list /etc/ajenti /etc/custom /etc/nginx /etc/nginx.custom.d /etc/ssl/private/pure-ftpd.pem /etc/pure-ftpd/conf/TLS /etc/fail2ban/jail.local /etc/network/if-pre-up.d/firewall /etc/sysctl.conf /etc/sudoers.d/my_sudoers /etc/rc.local /etc/mysql/my.cnf /etc/init/mysql.conf /etc/php5/fpm/php.ini /var/www /var/log /var/backups/databases.sql /var/backups/crontab && rm /var/backups/databases.sql && rm /var/backups/crontab && chmod 0440 /var/backups/firstserver.zip && rsync -avz --partial --delete /var/backups/firstserver.zip root@123.123.123.123:/var/backups/firstserver.zip" > /etc/custom/backup.sh

Type the following to apply proper permissions to the backup script file we just created:

chmod 0750 /etc/custom/backup.sh

Now, type in the following to run the backup script:

/etc/custom/backup.sh

Step 6: Enable Automatic Backups

To enable automatic backups every day, we must add our newly created backup script to the crontab. To do so, type in the following:

cat <(crontab -l) <(echo "@daily /etc/custom/backup.sh") | crontab -

Further Reading:

Fix phpList Error: IMAP is not included in your PHP Installation

It is hard to find a newsletter and email marketing software as nice as phpList. If you have installed this wonderful software on your own VPS/Dedicated server, and are getting the phpList error, Error: IMAP is not included in your PHP Installation, continue reading to learn how to easily fix this error.

phpList Process Bounces Error IMAP PHP not Installed

This error means you do not have the IMAP PHP extension installed. To install it, simply SSH into your server and type in the following:

apt-get install php5-imap

When asked if you want to continue, type Y and hit Enter.

Then, type in the following:

php5enmod imap

Now, restart your PHP processor by typing in the following:

service php5-fpm restart

Finally, restart your Nginx web server by typing in the following:

service nginx restart

If you are using an Apache web server, restart it by typing this instead:

service apache2 restart

Import MySQL Database File via Command Line Ubuntu Linux

Importing a MySQL database from the terminal in Linux is very easy. All it takes is one simple line:

mysql -u username -p database_name < myDatabase.sql

Make sure you enter in your MySQL username in place of username. In place of database_name, enter in the name of the database you are importing in to. After you enter this line of code via SSH, you will be prompted for the password of the MySQL user. Go ahead and enter in the password, and your database should get imported.