Plesk 17.x courier-imaps: Maximum connection limit reached for IP

Imagine you got 5 people in the office and IMAP randomly fails for some people, you are unable to receive or send emails and Apple Mail gives you a vague error “Verify that the username and password are correct”.

Chances are you are hitting the PERIP limit.
Take a look at /var/log/maillog, look for these errors:

Jan 1 12:41:34 109 courier-imapd: Maximum connection limit reached for ::ffff:XXX.XXX.XXX.XXX
Jan 1 12:41:34 109 courier-imapd: Maximum connection limit reached for ::ffff:XXX.XXX.XXX.XXX

Edit these 2 files
/etc/courier-imap/imapd
/etc/courier-imap/imapd-ssl

Edit both of them, you need to change these 2 lines in the first one, and add to the -ssl version:

MAXDAEMONS = 160
MAXPERIP = 120

You can make the same changes in /etc/courier-imap/pop3d and pop3d-ssl

You need to restart imap service for these settings to take affect, on regular centos you run

~# systemctl restart courier-imap

but if you are running Plesk, the service won’t even exist, instead you need to do

~# /usr/local/psa/admin/sbin/mailmng --restart-service

CentOS 7 – stdatomic.h: No such file or directory

I got this error while installing Mplayer on Centos7.
This is the full error

libavutil/atomic.h:32:7: warning: "HAVE_ATOMICS_SUNCC" is not defined [-Wundef]
 #elif HAVE_ATOMICS_SUNCC
       ^
CC	libavutil/camellia.o
CC	libavutil/cast5.o
CC	libavutil/channel_layout.o
CC	libavutil/color_utils.o
CC	libavutil/cpu.o
libavutil/cpu.c:20:23: fatal error: stdatomic.h: No such file or directory
 #include 
                       ^
compilation terminated.
make[1]: *** [libavutil/cpu.o] Error 1
make[1]: Leaving directory `/root/mplayer/ffmpeg'
make: *** [ffmpeg/libavutil/libavutil.a] Error 2

Basically you have 2 options, 1/ upgrade gcc to 4.9 ( very long process ), or 2/ download stdatomic.h and add it into the package you’re installing. You definitely want to go with option no.2

Go here https://gist.github.com/nhatminhle/5181506 and download the file ( you get link in upper right corner – hit Raw button ).
And then look where is it used in the package you are installing

root@lj: mplayer# pwd
/root/mplayer

root@lj: mplayer# wget https://gist.githubusercontent.com/nhatminhle/5181506/raw/541482dbc61862bba8a156edaae57faa2995d791/stdatomic.h

root@lj: mplayer# find ./ -name "*.c" | xargs grep "stdatomic" -n
./ffmpeg/compat/atomics/pthread/stdatomic.c:27:#include "stdatomic.h"
./ffmpeg/libavutil/cpu.c:20:#include 

Open stdatomic.c on line 27 and cpu.c on line 20 and make following change, from

#include 

to

//#include 
#include 

That’s it – this is by far the easiest way to deal with this error.

CentOS7 httpd permission denied for write, even with 777 permission

CentOS can be real pain when it comes to permissions.
Even if you set 777 to a folder you still won’t be able to write to it in Apache.
You need to enable it on system level as well:

chcon -R -t httpd_sys_rw_content_t /var/www/vhosts/localhost/httpdocs/files/
chcon -R -t httpd_sys_content_t /var/www/vhosts/localhost/httpdocs/files/
chcon -R -t httpd_sys_content_rw_t /var/www/vhosts/localhost/httpdocs/files/

Now Apache will be able to write to /var/www/vhosts/localhost/httpdocs/files/ and all subfolders.

CentoOS 7 – color terminal

There’s no magical 1 command, you need to do this in steps for each program you would like to use.

Color nano

root@lj: /# git clone https://github.com/nanorc/nanorc.git
root@lj: /# cd nanorc
root@lj: /# make install

And add into ~/.nanorc

include ~/.nano/syntax/html.nanorc
include ~/.nano/syntax/css.nanorc
include ~/.nano/syntax/php.nanorc
include ~/.nano/syntax/ALL.nanorc

Bash color

Add into ~/.bashrc

PS1='\e[33;1m\u@\h: \e[31m\W\e[0m\$ '

Git color

root@lj: /# git config --global color.ui auto

Cat color

This unfortunately isn’t possible. There’s a way around it though.

root@lj: /# yum install python-pygments
root@lj: /# echo "alias dog='pygmentize -g -O style=colorful,linenos=1'" > ~/.bashrc

mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0

I’ve encountered following error when running mongodb php module

Dec 12 09:56:02 lj php-fpm[3142]: [12-Dec-2016 09:56:02] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mongodb.so' - /usr/lib64/php/modules/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0

Few google searches reveal this can be fixed by simply making sure json is loaded prior to mongodb.so – which by default isn’t.
There are many ways to do that, for example find how your json is loaded

[root@lj php.d]# php -i | grep "json"
/etc/php.d/json.ini,

Now open json.ini and add

extension=mongodb.so

at the end – and remove mongodb.ini from the folder.

Or rename json.ini to 20-json.ini and mongodb.ini to 30-mongodb.ini
You can also add priority at top of the ini file priority=30

Don’t forget to restart php after each change, if you are running mod_php, just do systemctl restart httpd, for php-fpm it’s systemctl restart php-fpm.

Now the weird thing is – none of this worked for me.
No matter how I loaded mongodb, it always failed with this error. I got the latest pecl packages, everything up to date – it simply didn’t work.
The only solution for me was to roll back to previous version of mongodb

[root@lj php.d]# pecl uninstall mongodb
[root@lj php.d]# pecl install mongodb-1.1.9
[root@lj php.d]# echo "extension=mongodb.so" > /etc/php.d/zz-99-mongo.ini

I called the file zz-99 to make sure it’s always loaded last. My ini files do not start with 20-*.ini to set priority.
Good luck.