{"id":2940,"date":"2018-02-27T17:03:18","date_gmt":"2018-02-27T14:03:18","guid":{"rendered":"https:\/\/www.howtoforge.com\/tutorial\/perfect-server-debian-9-nginx-bind-dovecot-ispconfig-3.1\/"},"modified":"2018-02-27T17:03:18","modified_gmt":"2018-02-27T14:03:18","slug":"the-perfect-server-debian-9-nginx-bind-dovecot-ispconfig-3-1","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/the-perfect-server-debian-9-nginx-bind-dovecot-ispconfig-3-1\/","title":{"rendered":"The Perfect Server &#8211; Debian 9 (Nginx, BIND, Dovecot, ISPConfig 3.1)"},"content":{"rendered":"<div><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/the-perfect-server-debian-9-nginx-bind-dovecot-ispconfig-3-1.gif\" class=\"ff-og-image-inserted\" alt=\"\" title=\"\"><\/div>\n<p>This tutorial shows how to prepare a Debian\u00a09 server (with Nginx, BIND, Dovecot) for the installation of <a href=\"http:\/\/www.ispconfig.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">ISPConfig 3.1<\/a>, and how to install ISPConfig 3.1. ISPConfig 3 is a web hosting control panel that allows you to configure the following services through a web browser: Apache or nginx web server, Postfix mail server, Courier or Dovecot IMAP\/POP3 server, MySQL, BIND or MyDNS nameserver, PureFTPd, SpamAssassin, ClamAV, and many more. This setup covers Nginx web server, BIND as DNS Server, and Dovecot as IMAP \/ POP3 server.<\/p>\n<h2 id=\"-preliminary-note\">1 Preliminary Note<\/h2>\n<p>In this tutorial, I use the hostname <span class=\"system\">server1.example.com<\/span> with the IP address <span class=\"system\">192.168.1.100<\/span> and the gateway <span class=\"system\">192.168.1.1<\/span>. These settings might differ for you, so you have to replace them where appropriate.\u00a0<span>Before proceeding further you need to have a minimal installation of Debian 9. This might be a Debian minimal image from your hosting provider or you use the <\/span><a href=\"https:\/\/www.howtoforge.com\/tutorial\/debian-minimal-server\/\" target=\"_blank\" rel=\"noopener\">Minimal Debian Server<\/a><span>\u00a0tutorial to setup the base system.<\/span><\/p>\n<h2 id=\"nbspinstall-the-ssh-server\">2\u00a0Install the SSH Server<\/h2>\n<p>If you did not install the OpenSSH server during the system installation, you can do it now:<\/p>\n<p class=\"command\">apt-get -y install ssh openssh-server<\/p>\n<p>From now on you can use an SSH client such as <a href=\"http:\/\/www.chiark.greenend.org.uk\/%7Esgtatham\/putty\/download.html\" target=\"_blank\" rel=\"noopener noreferrer\">PuTTY<\/a> and connect from your workstation to your Debian 9 server and follow the remaining steps from this tutorial.<\/p>\n<h2 id=\"-install-a-shell-text-editor-optional\">3 Install a shell text editor (Optional)<\/h2>\n<p>I&#8217;ll\u00a0<span>use <\/span><span face=\"Courier New, Courier, mono\"><i>nano<\/i><\/span><span> text editor in this tutorial. Some users prefer the classic vi editor, therefore I will install both editors here. The default <\/span><span class=\"system\">vi<\/span><span> program has some strange behavior on Debian and Ubuntu; to fix this, we install <\/span><span class=\"system\">vim-nox<\/span><span>:<\/span><\/p>\n<p class=\"command\">apt-get -y install nano vim-nox<\/p>\n<p>(You don&#8217;t have to do this if you use a different text editor such as joe.)<\/p>\n<h2 id=\"-configure-thenbsphostname\">4 Configure the\u00a0Hostname<\/h2>\n<p><span>The hostname of your server should be a subdomain like &#8220;server1.example.com&#8221;. Do not use a domain name without subdomain part like &#8220;example.com&#8221; as hostname as this will cause problems later with your mail setup. First, you should check the hostname in\u00a0<\/span><span class=\"system\">\/etc\/hosts<\/span><span>\u00a0and change it when necessary. The line should be: &#8220;IP Address &#8211; space &#8211; full hostname incl. domain &#8211; space &#8211; subdomain part&#8221;. E<\/span>dit <span class=\"system\">\/etc\/hosts<\/span>. Make it look like this:<\/p>\n<p class=\"command\">nano \/etc\/hosts<\/p>\n<pre>127.0.0.1 localhost.localdomain localhost&#13;\n192.168.1.100 server1.example.com server1&#13;\n&#13;\n# The following lines are desirable for IPv6 capable hosts&#13;\n::1 localhost ip6-localhost ip6-loopback&#13;\nff02::1 ip6-allnodes&#13;\nff02::2 ip6-allrouters<\/pre>\n<p>Then edit the \/etc\/hostname file:<\/p>\n<p class=\"command\">nano \/etc\/hostname<\/p>\n<p>It shall contain only the subdomain part, in our case:<\/p>\n<pre>server1<\/pre>\n<p>Finally,\u00a0reboot the server to apply the change:<\/p>\n<p class=\"command\">reboot<\/p>\n<p>Log in again and check if the hostname is correct now with these commands:<\/p>\n<p class=\"command\">hostname<br \/>hostname -f<\/p>\n<p>The output shall be like this:<\/p>\n<p class=\"system\"><a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"c0b2afafb480b3a5b2b6a5b2f1\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>:\/tmp# hostname<br \/>server1<br \/><a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"3f4d50504b7f4c5a4d495a4d0e\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>:\/tmp# hostname -f<br \/>server1.example.com<\/p>\n<h2 id=\"-update-your-debian-installation\">5 Update Your Debian Installation<\/h2>\n<p>First make sure that your <span class=\"system\">\/etc\/apt\/sources.list<\/span> contains the <span class=\"system\">stretch\/updates<\/span> repository (this makes sure you always get the newest updates for the ClamAV virus scanner &#8211; this project publishes releases very often, and sometimes old versions stop working), and that the <span class=\"system\">contrib<\/span> and <span class=\"system\">non-free<\/span> repositories are enabled.<\/p>\n<p class=\"command\">nano \/etc\/apt\/sources.list<\/p>\n<pre readability=\"6\">deb http:\/\/ftp.us.debian.org\/debian\/ stretch main contrib non-free<br\/>deb-src http:\/\/ftp.us.debian.org\/debian\/ stretch main contrib non-free<p>deb http:\/\/security.debian.org\/debian-security stretch\/updates main contrib non-free<br\/>deb-src http:\/\/security.debian.org\/debian-security stretch\/updates main contrib non-free<\/p><\/pre>\n<p><strong>IMPORTANT:<\/strong> Add the Debian Backports repository as shown above.<\/p>\n<p>Run<\/p>\n<p class=\"command\">apt-get update<\/p>\n<p>to update the apt package database and<\/p>\n<p class=\"command\">apt-get upgrade<\/p>\n<p>to install the latest updates (if there are any).<\/p>\n<h2 id=\"-change-the-default-shell\">6 Change the Default Shell<\/h2>\n<p><span class=\"system\">\/bin\/sh<\/span> is a symlink to <span class=\"system\">\/bin\/dash<\/span>, however we need <span class=\"system\">\/bin\/bash<\/span>, not <span class=\"system\">\/bin\/dash<\/span>. Therefore we do this:<\/p>\n<p class=\"command\">dpkg-reconfigure dash<\/p>\n<p><span class=\"system\">Use dash as the default system shell (\/bin\/sh)?<\/span> <span class=\"highlight\">&lt;&#8211; No<\/span><\/p>\n<p>If you don&#8217;t do this, the ISPConfig installation will fail.<\/p>\n<h2 id=\"-synchronize-the-system-clock\">7 Synchronize the System Clock<\/h2>\n<p>It is a good idea to synchronize the system clock with an NTP (<strong>n<\/strong>etwork <strong>t<\/strong>ime <strong>p<\/strong>rotocol) server over the Internet. Simply run<\/p>\n<p class=\"command\">apt-get install ntp<\/p>\n<p>and your system time will always be in sync.<\/p>\n<h2 id=\"-install-postfix-dovecot-mysql-rkhunter-andnbspbinutils\">8 Install Postfix, Dovecot, MySQL, rkhunter and\u00a0binutils<\/h2>\n<p>We can install Postfix, Dovecot, MySQL, rkhunter, and Binutils with a single command:<\/p>\n<p class=\"command\"><span>apt-get install postfix postfix-mysql postfix-doc mariadb-client mariadb-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve <\/span><span>dovecot-lmtpd<\/span><span>\u00a0sudo<\/span><\/p>\n<p>You will be asked the following questions:<\/p>\n<p><span class=\"system\">General type of mail configuration:<\/span> <span class=\"highlight\">&lt;&#8211; Internet Site<\/span><br \/><span class=\"system\">System mail name:<\/span> <span class=\"highlight\">&lt;&#8211; server1.example.com<\/span><\/p>\n<p>To secure the MariaDB \/ MySQL installation and to disable the test database, run this command:<\/p>\n<p class=\"command\">mysql_secure_installation<\/p>\n<p>We don&#8217;t have to change the MySQL root password as we just set a new one during installation. Answer the questions as follows:<\/p>\n<p class=\"system\"><span>Change the root password? [Y\/n]\u00a0<\/span><span class=\"highlight\">&lt;&#8211; y<\/span><br \/><span>New password:<span>\u00a0<\/span><\/span><span class=\"highlight\">&lt;&#8211; Enter a new MySQL root password<\/span><br \/><span>Re-enter new password:<span>\u00a0<\/span><\/span><span class=\"highlight\">&lt;&#8211; Repeat the MySQL root password<\/span><br \/><span>Remove anonymous users? [Y\/n]<span>\u00a0<\/span><\/span><span class=\"highlight\">&lt;&#8211; y<\/span><br \/><span>Disallow root login remotely? [Y\/n]<span>\u00a0<\/span><\/span><span class=\"highlight\">&lt;&#8211; y<\/span><br \/><span>Remove test database and access to it? [Y\/n]<span>\u00a0<\/span><\/span><span class=\"highlight\">&lt;&#8211; y<\/span><br \/><span>Reload privilege tables now? [Y\/n]<span>\u00a0<\/span><\/span><span class=\"highlight\">&lt;&#8211; y<\/span><\/p>\n<p>Next, open the TLS\/SSL and submission ports in Postfix:<\/p>\n<p class=\"command\">nano \/etc\/postfix\/master.cf<\/p>\n<p>Uncomment the <span class=\"system\">submission<\/span> and <span class=\"system\">smtps<\/span> sections as follows (leave <span class=\"system\">-o milter_macro_daemon_name=ORIGINATING<\/span> as we don&#8217;t need it):<\/p>\n<pre>[...]&#13;\nsubmission inet n - - - - smtpd<br\/>-o syslog_name=postfix\/submission<br\/>-o smtpd_tls_security_level=encrypt<br\/>-o smtpd_sasl_auth_enable=yes<br\/>-o smtpd_client_restrictions=permit_sasl_authenticated,reject<br\/># -o smtpd_reject_unlisted_recipient=no<br\/># -o smtpd_client_restrictions=$mua_client_restrictions<br\/># -o smtpd_helo_restrictions=$mua_helo_restrictions<br\/># -o smtpd_sender_restrictions=$mua_sender_restrictions<br\/># -o smtpd_recipient_restrictions=<br\/># -o smtpd_relay_restrictions=permit_sasl_authenticated,reject<br\/># -o milter_macro_daemon_name=ORIGINATING<br\/>smtps inet n - - - - smtpd<br\/>-o syslog_name=postfix\/smtps<br\/>-o smtpd_tls_wrappermode=yes<br\/>-o smtpd_sasl_auth_enable=yes<br\/>-o smtpd_client_restrictions=permit_sasl_authenticated,reject<br\/># -o smtpd_reject_unlisted_recipient=no<br\/># -o smtpd_client_restrictions=$mua_client_restrictions<br\/># -o smtpd_helo_restrictions=$mua_helo_restrictions<br\/># -o smtpd_sender_restrictions=$mua_sender_restrictions<br\/># -o smtpd_recipient_restrictions=<br\/># -o smtpd_relay_restrictions=permit_sasl_authenticated,reject<br\/># -o milter_macro_daemon_name=ORIGINATING&#13;\n[...]<\/pre>\n<p>Restart Postfix afterwards:<\/p>\n<p class=\"command\"><span>service\u00a0postfix restart<\/span><\/p>\n<p>We want\u00a0MariaDB to listen on all interfaces, not just localhost, therefore we edit <span class=\"system\">\/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/span>\u00a0and comment out the line <span class=\"system\">bind-address = 127.0.0.1<\/span>\u00a0<span>\u00a0and add the line\u00a0<\/span><em>sql-mode=&#8221;NO_ENGINE_SUBSTITUTION&#8221;<\/em><span>:<\/span><\/p>\n<p class=\"command\">nano\u00a0\/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/p>\n<pre readability=\"5\">[...]&#13;\n<br\/># Instead of skip-networking the default is now to listen only on&#13;\n# localhost which is more compatible and is not less secure.&#13;\n#bind-address = 127.0.0.1<p>sql-mode=\"NO_ENGINE_SUBSTITUTION\"<\/p><p>[...]<\/p><\/pre>\n<p>Set the password authentication method in MariaDB to native so we can use PHPMyAdmin later to connect as root user:<\/p>\n<p class=\"command\">echo &#8220;update mysql.user set plugin = &#8216;mysql_native_password&#8217; where user=&#8217;root&#8217;;&#8221; | mysql -u root<\/p>\n<p>Edit the file\u00a0\/etc\/mysql\/debian.cnf and set the MYSQL \/ MariaDB root password there twice in the rows that start with password.<\/p>\n<p class=\"command\">nano \/etc\/mysql\/debian.cnf<\/p>\n<p>The MySQL root password that needs to be added is shown in red, in this example, the password is &#8220;howtoforge&#8221;.<\/p>\n<p class=\"system\"># Automatically generated for Debian scripts. DO NOT TOUCH!<br \/>[client]<br \/>host = localhost<br \/>user = root<br \/>password =\u00a0<span class=\"highlight\">howtoforge<\/span><br \/>socket = \/var\/run\/mysqld\/mysqld.sock<br \/>[mysql_upgrade]<br \/>host = localhost<br \/>user = root<br \/>password =<span>\u00a0<\/span><span class=\"highlight\">howtoforge<\/span><br \/>socket = \/var\/run\/mysqld\/mysqld.sock<br \/>basedir = \/usr<\/p>\n<p>To prevent the error &#8216;<strong><em>Error in accept: Too many open files<\/em><\/strong>&#8216; we will set higher open file limits for MariaDB now.<\/p>\n<p>Open the file \/etc\/security\/limits.conf with an editor:<\/p>\n<p class=\"command\">nano \/etc\/security\/limits.conf<\/p>\n<p>and add these lines at the end of the file.<\/p>\n<pre>mysql soft nofile 65535<br\/>mysql hard nofile 65535<\/pre>\n<p>Next, create a new directory\u00a0\/etc\/systemd\/system\/mysql.service.d\/ with the mkdir command.<\/p>\n<p class=\"command\">mkdir -p\u00a0\/etc\/systemd\/system\/mysql.service.d\/<\/p>\n<p>and add a new file inside:<\/p>\n<p class=\"command\">nano \/etc\/systemd\/system\/mysql.service.d\/limits.conf<\/p>\n<p>paste the following lines into that file:<\/p>\n<pre>[Service]<br\/>LimitNOFILE=infinity<\/pre>\n<p>Save the file and close the nano editor.<\/p>\n<p>Then we reload systemd and restart MariaDB:<\/p>\n<p class=\"command\">systemctl daemon-reload<br \/>service mysql restart<\/p>\n<p>Now check that networking is enabled. Run<\/p>\n<p class=\"command\">netstat -tap | grep mysql<\/p>\n<p>The output should look like this:<\/p>\n<p class=\"system\"><a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"27554848536754425551425516\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>:~#\u00a0netstat\u00a0-tap\u00a0|\u00a0grep\u00a0mysql<br \/>tcp6\u00a0 \u00a0 \u00a0 \u00a00\u00a0 \u00a0 \u00a0 0 [::]:mysql\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [::]:*\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 LISTEN\u00a0 \u00a0 \u00a0 4027\/mysqld<br \/><a href=\"https:\/\/www.howtoforge.com\/cdn-cgi\/l\/email-protection\" class=\"__cf_email__\" data-cfemail=\"9be9f4f4efdbe8fee9edfee9aa\" target=\"_blank\" rel=\"noopener\">[email\u00a0protected]<\/a>:~#<\/p>\n<h2 id=\"-install-amavisdnew-spamassassin-and-clamav\">9 Install Amavisd-new, SpamAssassin, and ClamAV<\/h2>\n<p>To install amavisd-new, SpamAssassin, and ClamAV, we run:<\/p>\n<p class=\"command\"><span>apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl\u00a0<\/span><span>libdbd-mysql-perl<\/span><span><span>\u00a0<\/span>postgrey<\/span><\/p>\n<p>The ISPConfig 3 setup uses amavisd which loads the SpamAssassin filter library internally, so we can stop SpamAssassin to free up some RAM:<\/p>\n<p class=\"command\"><span>service\u00a0spamassassin stop<\/span><br \/><span>systemctl disable spamassassin<\/span><\/p>\n<h2 id=\"-install-metronome-xmpp-server-optional\">9.1 Install Metronome XMPP Server (optional)<\/h2>\n<p>This step installs the Metronome XMPP Server which provides a chat server that is compatible with the XMPP protocol. This step is optional, if you do not need a chat server, then you can skip this step. No other ISPConfig functions depend on this software.<\/p>\n<p>Add the Prosody package repository in Debian.<\/p>\n<p class=\"command\">echo &#8220;deb http:\/\/packages.prosody.im\/debian\u00a0stretch main&#8221; &gt; \/etc\/apt\/sources.list.d\/metronome.list<br \/>wget http:\/\/prosody.im\/files\/prosody-debian-packages.key -O &#8211; | sudo apt-key add &#8211;<\/p>\n<p>Update the package list:<\/p>\n<p class=\"command\">apt-get update<\/p>\n<p>Install the programs that are required for the build process<\/p>\n<p class=\"command\">apt-get install build-essential<\/p>\n<p>and install the packages with apt.<\/p>\n<p class=\"command\">apt-get install git lua5.1 liblua5.1-0-dev lua-filesystem\u00a0libidn11-dev libssl-dev lua-zlib lua-expat lua-event lua-bitop lua-socket lua-sec luarocks\u00a0luarocks<\/p>\n<p class=\"command\">luarocks install lpc<\/p>\n<p>Add a shell user for Metronome.<\/p>\n<p class=\"command\">adduser &#8211;no-create-home &#8211;disabled-login &#8211;gecos &#8216;Metronome&#8217; metronome<\/p>\n<p>Download Metronome to the \/opt directory and compile it.<\/p>\n<p class=\"command\">cd \/opt; git clone https:\/\/github.com\/maranda\/metronome.git metronome<br \/>cd .\/metronome; .\/configure &#8211;ostype=debian &#8211;prefix=\/usr<br \/>make<br \/>make install<\/p>\n<p>Metronome has now be installed to \/opt\/metronome.<\/p>\n<nav> <\/nav>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to prepare a Debian\u00a09 server (with Nginx, BIND, Dovecot) for the installation of ISPConfig 3.1, and how to install ISPConfig 3.1. ISPConfig 3 is a web hosting control panel that allows you to configure the following services through a web browser: Apache or nginx web server, Postfix mail server, Courier or &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2940","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=2940"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2940\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}