Difference between revisions of "Install a new server"

From Organic Design wiki
(MariaDB: local only)
m (Web-server and PHP)
(29 intermediate revisions by the same user not shown)
Line 29: Line 29:
 
First, bring the system up to date.
 
First, bring the system up to date.
 
<source>
 
<source>
apt-get update
+
apt update
apt-get upgrade
+
apt upgrade
 
</source>
 
</source>
  
Line 68: Line 68:
  
  
Then we want to disable passwords for [[SSH]] access and use RSA keys as typing passwords is insecure. These changes were made to ''/etc/ssh/sshd_config'':
+
Then we want to disable passwords for [[SSH]] access and use RSA keys as typing passwords is insecure. Check or add these settings in ''/etc/ssh/sshd_config'':
 
<source>
 
<source>
 
AllowUsers fred bob sam
 
AllowUsers fred bob sam
 
PermitRootLogin no
 
PermitRootLogin no
 +
PasswordAuthentication no
 
RSAAuthentication yes
 
RSAAuthentication yes
 
PubkeyAuthentication yes
 
PubkeyAuthentication yes
PasswordAuthentication no
 
 
</source>
 
</source>
  
Line 91: Line 91:
 
</source>
 
</source>
  
 +
See also [https://www.booleanworld.com/protecting-ssh-fail2ban/ protecting SSH with fail2ban] if you'd like more control over blocking IPs after failed login attempts.
 +
 +
==== Fail2Ban ====
 +
Fail2ban allows the blocking of repeated login attempts to the server. Install it with '''apt install fail2ban''' and then add the following basic configuration to ''/etc/fail2ban/jail.local'':
 +
<source>
 +
[DEFAULT]
 +
destemail = your@email.here
 +
sendername = Fail2Ban
 +
 +
[sshd]
 +
enabled = true
 +
port = 22
 +
 +
[sshd-ddos]
 +
enabled = true
 +
port = 22
 +
</source>
  
 +
==== Rootkit Hunter ====
 
Install [http://rkhunter.sourceforge.net/ The Rootkit Hunter] with '''apt-get install rkhunter''' and uncomment the following lines as these files are normal on Debian systems and should not be considered as attacks. Also have a look at the Debian README file with '''zcat /usr/share/doc/rkhunter/README.Debian.gz'''.
 
Install [http://rkhunter.sourceforge.net/ The Rootkit Hunter] with '''apt-get install rkhunter''' and uncomment the following lines as these files are normal on Debian systems and should not be considered as attacks. Also have a look at the Debian README file with '''zcat /usr/share/doc/rkhunter/README.Debian.gz'''.
 
<source>
 
<source>
Line 109: Line 127:
 
rkhunter --propupd
 
rkhunter --propupd
 
rkhunter -c
 
rkhunter -c
 +
</source>
 +
 +
==== Monitoring filesystem events ====
 +
A good idea, especially if you suspect any kind of remote code execution (RCE) bugs in webapps etc is to monitor for changes in the filesystem. Here's a simple method using [https://github.com/emcrisostomo/fswatch FSWatch]. first download the latest release and unpack it, then install it:
 +
<source lang="bash">
 +
./configure
 +
make
 +
sudo make install
 +
sudo ldconfig
 +
</source>
 +
 +
I used the following command format to log what I'm interested in. I'm, using the inefficient ''poll-monitor'' here because I for some reason the default ''inotify-monitor'' wouldn't return events for files in sub-directories, I added the ''l 30'' option to specify a latency of 30 seconds to save CPU resource. I'm piping the output through ''egrep -v'' so I can specify a pattern to filter out of the log.
 +
<source lang="bash">
 +
fswatch --monitor=poll_monitor -trxl 30 /var/www | egrep -v "(gitlist-cache|\.log$)" >> /var/log/fswatch.log &
 +
</source>
 +
I added the command to the ''@reboot'' event in the ''crontab'' along with a second item to mail me the last 20 items in the log each day.
 +
<source>
 +
@reboot    root  fswatch --monitor=poll_monitor -trxl 30 /var/www | egrep -v "(gitlist-cache|\.log$)" >> /var/log/fswatch.log
 +
0 0 * * *  root  tail -n 20 /var/log/fswatch.log | mail -s "Daily FS changes" "foo@bar.baz"
 
</source>
 
</source>
  
 
=== Installing packages ===
 
=== Installing packages ===
 
Then begin installing the necessary packages,
 
Then begin installing the necessary packages,
<source>
+
<source lang="bash">
apt-get install sudo host screen build-essential python-dev ntp p7zip-full bzip2 unzip git poppler-utils encfs curl
+
apt install sudo fail2ban host screen cpulimit build-essential python-dev ntp p7zip-full bzip2 unzip git poppler-utils encfs curl htmldoc librsvg2-bin imagemagick redis-server
 
</source>
 
</source>
  
  
 
The following if you're going to be using email on the server:
 
The following if you're going to be using email on the server:
<source>
+
<source lang="bash">
apt-get install exim4-daemon-heavy dovecot-common dovecot-imapd spamassassin spamc maildirsync
+
apt install exim4-daemon-heavy dovecot-common dovecot-imapd spamassassin spamc maildirsync
</source>
 
 
 
 
 
The following for servers running wikis (install your web-server first, see below):
 
<source>
 
apt-get install htmldoc librsvg2-bin imagemagick redis-server
 
apt-get install php5-cli php5-mysqlnd php5-gd php5-mcrypt php5-xsl php5-intl php5-xmlrpc php5-curl php5-imap php-apc php5-redis
 
 
</source>
 
</source>
  
  
 
The following Perl packages and utilites:
 
The following Perl packages and utilites:
<source>
+
<source lang="bash">
apt-get install cpanminus libwww-perl libio-socket-ssl-perl libtimedate-perl
+
apt install libwww-perl libio-socket-ssl-perl libtimedate-perl
cpanm JSON Expect HTML::Entities Archive::Zip XML::Simple AnyEvent::WebSocket::Client Net::WebSocket::Server Net::DNS Term::ReadPassword
+
cpan JSON Expect HTML::Entities Archive::Zip XML::Simple Net::DNS Term::ReadPassword Perl::Version Email::MIME Email::Sender::Simple Math::Random::Secure
 
</source>
 
</source>
 
'''Note:''' If XML::Simple fails to install, try the ''apt'' package ''libxml-libxml-simple-perl'' first.
 
'''Note:''' If XML::Simple fails to install, try the ''apt'' package ''libxml-libxml-simple-perl'' first.
Line 141: Line 171:
 
'''Math markup:''' We've always used Latex for this, but the installation can be complicated and it requires over a GB (yes a Gigabyte!) of packages to be installed that we don't use for anything else. But now client side rendering is possible, or server-side via the new Mathoid node.js service both of which are vastly preferable. See [[MW:Extension:Math]] for more detail about installation options. For a fully client-side rendering solution with no server-side installation at all and no configuration, the simplest method is just to install the [[MW:Extension:SimpleMathJax|SimpleMathJax extension]].
 
'''Math markup:''' We've always used Latex for this, but the installation can be complicated and it requires over a GB (yes a Gigabyte!) of packages to be installed that we don't use for anything else. But now client side rendering is possible, or server-side via the new Mathoid node.js service both of which are vastly preferable. See [[MW:Extension:Math]] for more detail about installation options. For a fully client-side rendering solution with no server-side installation at all and no configuration, the simplest method is just to install the [[MW:Extension:SimpleMathJax|SimpleMathJax extension]].
  
 
+
=== NodeJS ===
You will now have a functioning server and LAMP environment.
+
Many services depend on [https://nodejs.org NodeJS] these days, so it's a good idea to have the latest long term service release installed. For Debian installation instructions check [https://github.com/nodesource/distributions#debinstall here].
  
 
=== MariaDB ===
 
=== MariaDB ===
 
Either install the '''mysql-server''' package with ''apt-get'', or go through [https://kb.askmonty.org/en/installing-mariadb-deb-files/ this procedure] for installing [[MariaDB]] instead which is a truly open source drop-in replacement for MySQL forked from the original by the creators.
 
Either install the '''mysql-server''' package with ''apt-get'', or go through [https://kb.askmonty.org/en/installing-mariadb-deb-files/ this procedure] for installing [[MariaDB]] instead which is a truly open source drop-in replacement for MySQL forked from the original by the creators.
  
You may want to ensure that it's only accepting local connections by adding '''bind-address=127.0.0.1''' to '''/etc/mysql/conf.d/mariadb.cnf'''.
+
Here's some settings for '''/etc/mysql/conf.d/mariadb.cnf''' that we've found to be a good idea:
 +
<source lang="nginx">
 +
bind-address=127.0.0.1    # Ensure the database is not open to external connections
 +
max_statement_time=0.5    # Don't allow long executing SQL statements that clog the machine up
 +
</source>
  
 
One issue that can occur after moving server for both MySQL and MariaDB is the following error produced every day:
 
One issue that can occur after moving server for both MySQL and MariaDB is the following error produced every day:
Line 156: Line 190:
 
</source>
 
</source>
 
This is due to the ''debian-sys-maint'' user not having permission to access ''mysqladmin'' to rotate the logs either due to the MySQL user missing, or having the wrong password (thanks to [http://www.lornajane.net/about Lornajane] for her solution in [http://www.lornajane.net/posts/2008/logrotate-error-on-ubuntu#comment-13031 this post]). Get the password from the ''/etc/mysql/debian.cnf'' configuration file and then either update the password if the user exists, or create the user with the correct password if not.
 
This is due to the ''debian-sys-maint'' user not having permission to access ''mysqladmin'' to rotate the logs either due to the MySQL user missing, or having the wrong password (thanks to [http://www.lornajane.net/about Lornajane] for her solution in [http://www.lornajane.net/posts/2008/logrotate-error-on-ubuntu#comment-13031 this post]). Get the password from the ''/etc/mysql/debian.cnf'' configuration file and then either update the password if the user exists, or create the user with the correct password if not.
<source>
+
<source lang="mysql">
 
USE mysql
 
USE mysql
 
UPDATE user SET Password = PASSWORD('**************') WHERE User = 'debian-sys-maint' && Host = 'localhost';
 
UPDATE user SET Password = PASSWORD('**************') WHERE User = 'debian-sys-maint' && Host = 'localhost';
Line 162: Line 196:
 
</source>
 
</source>
 
::or
 
::or
<source>
+
<source lang="mysql">
 
GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY PASSWORD '**************';
 
GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY PASSWORD '**************';
 
FLUSH PRIVILEGES
 
FLUSH PRIVILEGES
Line 168: Line 202:
  
 
You can check if the maintenance user has its access correctly configured with the following command:
 
You can check if the maintenance user has its access correctly configured with the following command:
<source>
+
<source lang="bash">
 
mysqladmin --defaults-file=/etc/mysql/debian.cnf ping
 
mysqladmin --defaults-file=/etc/mysql/debian.cnf ping
 
</source>
 
</source>
Line 174: Line 208:
 
'''Open files limits:''' After installing a lot of Joomla's all using table prefixes in shared databases, each using about 140 tables, I started getting "too many open files" errors, so I've doubled the ''open-files-limit'' and ''innodb_open_files'' values.
 
'''Open files limits:''' After installing a lot of Joomla's all using table prefixes in shared databases, each using about 140 tables, I started getting "too many open files" errors, so I've doubled the ''open-files-limit'' and ''innodb_open_files'' values.
  
== Post install checklist ==
+
== Web-server and PHP ==
*/etc/hostname, hostname -F /etc/hostname, /etc/hosts
+
First install the packages:
*DB info for wikia, webmail, crm
+
<source lang="bash">
*/etc/ssh/sshd_config
+
apt install nginx php7.0-fpm composer php7.0-cli php7.0-mysqlnd php7.0-gd php7.0-mcrypt php7.0-intl php7.0-curl php7.0-simplexml php7.0-mbstring php7.0-apc php7.0-bcmath php-imagick php7.0-zip
*/var/www and /home structures (should be automatically maintained by adding new server as a peer)
 
*Exim4 (this will need to be configured even for sending mail, see [[Configure mail server]])
 
*Import spamassassin bayesian rules
 
 
 
== Scheduled tasks ==
 
We have the following scheduled tasks running in our ''crontab'',
 
<source>
 
0   3 * * * root perl /var/www/tools/learn-spam.pl > /dev/null
 
0   4 * * * root perl /var/www/work/daily.pl > /dev/null
 
0   5 * * * root perl /var/www/work/backup.pl &> /dev/null
 
*/5 * * * * root wget -O - -q https://dev.organicdesign.co.nz --no-check-certificate > /dev/null
 
 
</source>
 
</source>
*The first is to keep the baysean rules up to date for our spam filter, see [[Configure mail server]] for more detail.
 
*The second runs our OD daily backup script which backs up our databases and site structures, users mail, our subversion repositories and server configuration files (this is private and specific to the OD server, a more generic script is [http://svn.organicdesign.co.nz/filedetails.php?repname=tools&path=%2Fbackup-host.pl backup-host.pl]).
 
*The third is a private script that sends reminder emails about payments and invoices due.
 
*The forth is to keep categorisation etc up to date in our private work wiki because the site can't run jobs quickly enough from page requests being private.
 
  
== PHP ==
+
The differences to the default ''php.ini'' file in our servers are as follows:
The differences to the default ''php.ini'' file in our servers are as follows (the parts after the ... need to be added to the end):
 
 
 
{{h|'''Note:''' this still needs updating to PHP 5.4.x settings.}}
 
 
<source>
 
<source>
max_execution_time = 300
 
memory_limit = 64M
 
log_errors = On
 
error_log = syslog
 
 
post_max_size = 100M
 
post_max_size = 100M
 +
    ︙
 
upload_max_filesize = 100M
 
upload_max_filesize = 100M
 
+
    ︙
...
+
[opcache]
 
+
opcache.enable=1
[suhosin]
+
opcache.enable_cli=1
suhosin.session.encrypt = Off
+
opcache.interned_strings_buffer=8
 +
opcache.max_accelerated_files=10000
 +
opcache.memory_consumption=128
 +
opcache.save_comments=1
 +
opcache.revalidate_freq=1
 
</source>
 
</source>
Note that the suhosin settings have their own ''php.ini'' configuration file in '''/etc/php5/apache2/conf.d/suhosin.ini''' which overrides the settings in the default ''php.ini''. Change the line containing the ''suhosin.session.encrypt'' option in this file to disable it (and don't forget to uncomment the line by removing the leading semicolon), then restart the web server.
 
  
== Web server ==
+
Un-comment the ''env'' entries towards the end of ''www.conf'' in the ''pool.d'' sub-directory as well:
First install [[Nginx]] and the ''fast-cgi'' module.
 
 
<source>
 
<source>
apt-get install nginx php5-fpm
+
;env[HOSTNAME] = $HOSTNAME
 +
;env[PATH] = /usr/local/bin:/usr/bin:/bin
 +
;env[TMP] = /tmp
 +
;env[TMPDIR] = /tmp
 +
;env[TEMP] = /tmp
 
</source>
 
</source>
 
 
Edit the ''/etc/php5/fpm/php.ini'' file and set '''cgi.fix_pathinfo''' to '''0''' to avoid [http://cnedelcu.blogspot.com.br/2010/05/nginx-php-via-fastcgi-important.html this] serious security problem allowing arbitrary PHP code to be executed on the server.
 
 
 
If using [[Apache]] do the following installation steps instead. Our main server is no longer running Apache, we changed over to Nginx on [[1 July 2013]].
 
<source>
 
apt-get install apache2 libapache2-svn libapache2-mod-php5
 
a2enmod ssl
 
a2enmod rewrite
 
</source>
 
 
 
Our configuration is in our private ''work'' subversion repository so that we have an organised history of changes made to the configuration and a good back up of it. We use a symlink from ''/etc/apache2/sites-available/default'' to ''/var/www/work/apache.conf'' or ''/etc/nginx/sites-available/default'' to ''/var/www/work/nginx.conf'' which is the configuration file's location on the server in an automatically updating working copy.
 
 
The configuration has two main sections for SSL and non-SSL. The non SSL section includes rules for most of the sites and falls back on a set of general rules assuming the sites to be part of the OD wiki farm if no other prior rules have matched. The first two rule sets map all requests having a ''webmail'' sub-domain to the Organic Design webmail application, and all requests having an ''svn'' sub-domain to the ''websvn'' application. There are also two other virtual-host containers at the end which make the ''tools'' and ''extensions'' subversion repositories publicly readable via HTTP.
 
  
 
=== Setting up SSL ===
 
=== Setting up SSL ===
Line 295: Line 298:
 
== Next steps ==
 
== Next steps ==
 
*[[Configure mail server]]
 
*[[Configure mail server]]
*[[Configure LAN]] ''- DHCP server and firewall''
+
*[[NextCloud]]
 
*[[Configure DNS]] ''- LAN/Server based DNS and dynamic DNS solutions''
 
*[[Configure DNS]] ''- LAN/Server based DNS and dynamic DNS solutions''
*[[Configure SMB]] ''- Samba file shares''
 
*[[Configure VPN]] ''- Remote access to file shares and other LAN resources''
 
*[[Configure IRC]] ''- Run a chat channel, your bot can publish notifications to the channel''
 
*[[Install a MediaWiki code-base]] ''- OD wikia specific procedure''
 
*[[Configure wiki security]]
 
*[[Tune a MediaWiki using Webpagetest and APC Cache]]
 
  
 
== See also ==
 
== See also ==
*[[Install a new server (CentOS)]]
+
*[[Server migration checklist]]
 +
*[[Install a new server (CentOS)]] ''- legacy''
 
*[[Backup]]
 
*[[Backup]]
 
*[[Hosting]]
 
*[[Hosting]]
 
*[[Add an IP address to a server]]
 
*[[Add an IP address to a server]]
*[http://www.monkeedev.co.uk/blog/2009/03/23/installing-mysql-51-on-debian-and-ubuntu-using-apt Installing MySQL 5.1 on Debian Lenny]
+
[[Category:Installation]]
*[http://tlug.dnho.net/?q=node/276 Convert a MySQL DB from latin1 to UTF8]
 
[[Category:Installation]][[Category:Wikia]]
 

Revision as of 22:26, 22 April 2019

Procedure.svg Install a new server
Organic Design procedure

Choose a hosting provider

First an appropriate hosting provider needs to be found, or if running a server in-house, see the Configure LAN procedure. Some possible points to check out when looking for a server hosting service apart from just the cost are:

  • Ease of hardware upgrading - can you upgrade disk/memory/cpu without reinstalling the system?
  • Contention rate (how many concurrent clients share the hardware if its a VPS)
  • Control panel usefulness (the most important features are rebooting and virtual console access)
  • OS choices available (up to date Debian or Ubuntu are most important for us)
  • Historical downtime statistics
  • What jurisdiction are they hosting in and what laws apply? for example can your run hidden services, i2p/tor routers or torrent daemons?
  • Do they accept Bitcoin or other crypto-currencies for payment?
  • What kind of data backup options do they provide?

Get reverse DNS set up

Any site that sends emails should have reverse DNS correctly configured. Having a reverse DNS correctly set up will help to prevent the site's mails being trashed as spam. Many mail-servers will do a reverse lookup on the sending IP address and ensure it matches the senders specified domain.

This is not done by the domain registrar, it's done by the company hosting the server (the IP address owner), sometimes they include the ability to set it in the server management interface. If not, raise a support ticket asking them if they can set up a PTR record for the server's IP pointing to your naked domain.

You can check the reverse DNS for a domain at DNSstuff in their IP section, and you can find out more about what reverse DNS is and why it's important here.

Set up a caching DNS server

Setting up a local caching non-forwarding DNS server is a good idea to ensure that DNS requests return quickly (especially useful if you have sites that make requests before returning the pages). It's also essential if you're running spam assassin because the domain black-lists (DNSBL) services operate over DNS and will often block requests made from large ISP's DNS servers. See Configure DNS for installation details.

Download and install Debian or Ubuntu

If the server has no OS then download and install Debian/Ubuntu first. Depending on the kind of access you have to the server and the kind of media it can accept, the following links may be of interest.

Setting up the OS environment

First, bring the system up to date.

apt update
apt upgrade

Give the server's root account (and any other accounts that send mail) a friendly name so it looks better in the inbox when it sends mail. Do this by replacing the name "root" in the full-name field in /etc/passwd as follows:

root:x:0:0:Organic Design server:/root:/bin/bash

Note: If you want mail from the root account sent to something other that root@yourdomain then, set the address in /root/.forward.

Timezone

Getting the following warning plus a bunch of others whenever Perl scripts run?

perl: warning: Falling back to the standard locale ("C").


Configure the locales and tick the time zones you'd like to have available on the system, make sure that en_US.8859-1 and en_US.UTF-8 are selected because it seems that some programs expect them to exist. Also make sure that all locales ate included that were mentioned anywhere within the warning messages.

dpkg-reconfigure locales


If you're still getting the problem, you can explicitly set the associated variables to one of the locales you made available by appending entries to your ~/.bashrc for example,

echo "export LC_ALL=en_US.UTF-8" >> /home/foo/.bashrc

Security

By default the server login is the root user with a password, so the first thing I did was to set up another user for myself, add the user to /etc/sudoers with full privileges and no password requirement. Note that you need to use the sudo or visudo utility to modify, not the usual vi or nano utilities.

The 'www-data line allows git repositories to be automatically updated in response to WebHooks events sent by Guthub in response to push events.

fred     ALL=(ALL) NOPASSWD : ALL
www-data ALL=(ALL) NOPASSWD : /usr/bin/git pull --no-edit


Then we want to disable passwords for SSH access and use RSA keys as typing passwords is insecure. Check or add these settings in /etc/ssh/sshd_config:

AllowUsers fred bob sam
PermitRootLogin no
PasswordAuthentication no
RSAAuthentication yes
PubkeyAuthentication yes


And don't forget to add your public RSA key to '~/.ssh/authorized_keys. Note that you'll probably need to create the directory since the account has just been created, and the owner and mode is important.

mkdir /home/USER/.ssh
echo "RSA_KEY" > /home/USER/.ssh/authorized_keys
chown USER:USER -R /home/USER/.ssh
chmod 644 /home/USER/.ssh/authorized_keys

Restart the SSH server and test that you can login from another terminal window before exiting the current session. You now login as your own user, not the root user, and then use sudo bash to gain a root shell.

service ssh restart

See also protecting SSH with fail2ban if you'd like more control over blocking IPs after failed login attempts.

Fail2Ban

Fail2ban allows the blocking of repeated login attempts to the server. Install it with apt install fail2ban and then add the following basic configuration to /etc/fail2ban/jail.local:

[DEFAULT]
destemail = your@email.here
sendername = Fail2Ban

[sshd]
enabled = true
port = 22

[sshd-ddos]
enabled = true
port = 22

Rootkit Hunter

Install The Rootkit Hunter with apt-get install rkhunter and uncomment the following lines as these files are normal on Debian systems and should not be considered as attacks. Also have a look at the Debian README file with zcat /usr/share/doc/rkhunter/README.Debian.gz.

ALLOWHIDDENDIR=/dev/.udev
ALLOWHIDDENDIR=/dev/.static
ALLOWHIDDENDIR=/dev/.initramfs
ALLOWHIDDENDIR=/dev/.mdadm
...
RTKT_FILE_WHITELIST="/etc/init.d/hdparm /etc/init.d/.depend.boot"
...
USER_FILEPROP_FILES_DIRS="/etc/init.d/.depend.boot"


Then run a properties update on it since we've added some custom files to the whitelist and need notification if they change, and then run a local test to see if there are any warnings.

rkhunter --propupd
rkhunter -c

Monitoring filesystem events

A good idea, especially if you suspect any kind of remote code execution (RCE) bugs in webapps etc is to monitor for changes in the filesystem. Here's a simple method using FSWatch. first download the latest release and unpack it, then install it:

./configure
make
sudo make install
sudo ldconfig

I used the following command format to log what I'm interested in. I'm, using the inefficient poll-monitor here because I for some reason the default inotify-monitor wouldn't return events for files in sub-directories, I added the l 30 option to specify a latency of 30 seconds to save CPU resource. I'm piping the output through egrep -v so I can specify a pattern to filter out of the log.

fswatch --monitor=poll_monitor -trxl 30 /var/www | egrep -v "(gitlist-cache|\.log$)" >> /var/log/fswatch.log &

I added the command to the @reboot event in the crontab along with a second item to mail me the last 20 items in the log each day.

@reboot     root   fswatch --monitor=poll_monitor -trxl 30 /var/www | egrep -v "(gitlist-cache|\.log$)" >> /var/log/fswatch.log
0 0 * * *   root   tail -n 20 /var/log/fswatch.log | mail -s "Daily FS changes" "foo@bar.baz"

Installing packages

Then begin installing the necessary packages,

apt install sudo fail2ban host screen cpulimit build-essential python-dev ntp p7zip-full bzip2 unzip git poppler-utils encfs curl htmldoc librsvg2-bin imagemagick redis-server


The following if you're going to be using email on the server:

apt install exim4-daemon-heavy dovecot-common dovecot-imapd spamassassin spamc maildirsync


The following Perl packages and utilites:

apt install libwww-perl libio-socket-ssl-perl libtimedate-perl
cpan JSON Expect HTML::Entities Archive::Zip XML::Simple Net::DNS Term::ReadPassword Perl::Version Email::MIME Email::Sender::Simple Math::Random::Secure

Note: If XML::Simple fails to install, try the apt package libxml-libxml-simple-perl first.


Math markup: We've always used Latex for this, but the installation can be complicated and it requires over a GB (yes a Gigabyte!) of packages to be installed that we don't use for anything else. But now client side rendering is possible, or server-side via the new Mathoid node.js service both of which are vastly preferable. See MW:Extension:Math for more detail about installation options. For a fully client-side rendering solution with no server-side installation at all and no configuration, the simplest method is just to install the SimpleMathJax extension.

NodeJS

Many services depend on NodeJS these days, so it's a good idea to have the latest long term service release installed. For Debian installation instructions check here.

MariaDB

Either install the mysql-server package with apt-get, or go through this procedure for installing MariaDB instead which is a truly open source drop-in replacement for MySQL forked from the original by the creators.

Here's some settings for /etc/mysql/conf.d/mariadb.cnf that we've found to be a good idea:

bind-address=127.0.0.1    # Ensure the database is not open to external connections
max_statement_time=0.5    # Don't allow long executing SQL statements that clog the machine up

One issue that can occur after moving server for both MySQL and MariaDB is the following error produced every day:

/etc/cron.daily/logrotate:
error: error running shared postrotate script for '/var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log '
run-parts: /etc/cron.daily/logrotate exited with return code 1

This is due to the debian-sys-maint user not having permission to access mysqladmin to rotate the logs either due to the MySQL user missing, or having the wrong password (thanks to Lornajane for her solution in this post). Get the password from the /etc/mysql/debian.cnf configuration file and then either update the password if the user exists, or create the user with the correct password if not.

USE mysql
UPDATE user SET Password = PASSWORD('**************') WHERE User = 'debian-sys-maint' && Host = 'localhost';
FLUSH PRIVILEGES
or
GRANT RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY PASSWORD '**************';
FLUSH PRIVILEGES

You can check if the maintenance user has its access correctly configured with the following command:

mysqladmin --defaults-file=/etc/mysql/debian.cnf ping

Open files limits: After installing a lot of Joomla's all using table prefixes in shared databases, each using about 140 tables, I started getting "too many open files" errors, so I've doubled the open-files-limit and innodb_open_files values.

Web-server and PHP

First install the packages:

apt install nginx php7.0-fpm composer php7.0-cli php7.0-mysqlnd php7.0-gd php7.0-mcrypt php7.0-intl php7.0-curl php7.0-simplexml php7.0-mbstring php7.0-apc php7.0-bcmath php-imagick php7.0-zip

The differences to the default php.ini file in our servers are as follows:

post_max_size = 100M
    ︙
upload_max_filesize = 100M
    ︙
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1

Un-comment the env entries towards the end of www.conf in the pool.d sub-directory as well:

;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

Setting up SSL

See SSL

Domain names

Adjust the names of the symlinks in the /var/www/domains directory to local domain names and ensure that those names are added to the /etc/hosts file.

  • Note: If you're installing your wikia structure on a local machine, then you must ensure that your domains such as foo.localhost are set in /etc/hosts as aliases for 127.0.0.1
  • DNS: if you need to set up a DNS server or Dymamic DNS system, see Configure DNS

Extracting Databases from a Backup

Extract the most recent database backup (this may overwrite existing databases of the same names)

7za x all-yyyy-mm-dd.sql.7z
mysql -u root -p < all.sql
mysqladmin -u root -p flush-privileges

Setting up SFTP access

The OpenSSH server comes with good SFTP support built in and allows users to be set up that have only SFTP access and can be restricted to specified sub-directories. The configuration is done from /etc/ssh/sshd_config (it must be the OpenSSH server), first enable the SFTP subsystem by un-commenting or adding the following directive:

Subsystem sftp internal-sftp


Next add a section like the following example for each user requiring access,

Match User foo
ChrootDirectory /var/www
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no


You can check for problems in the /var/log/auth.log file. The most common issue will be to do with permissions. The root folder that is given access to the SFTP subsystem must be owned by root and be in the root group. It must be writable only by root, but readable by the SFTP user. The connecting clients use a path relative to the chroot directory given to them in their matching configuration section.

SFTP windows clients

Windows users can use the FileZilla FTP client to connect to the server over SFTP using key-based logins.

First you need to import your private key by going into edit/settings and then SFTP in the treeview and click the Add Key button. This will then allow you to convert the key to the windows ppk format and save it in its list.

You can then set up a new site entry using protocol SFTP, and authentication type Interactive.

Setting up FTP access

Some clients may require standard FTP access which although not very secure, can have some restrictions put on it to make it a little safer such as restricting users to their home directories and using a non standard port. We use the GPL proFTPD server in standalone mode.

apt-get install proftpd


Edit the /etc/proftpd/proftpd.conf file and change the port to something other than 21 and add the following directive to restrict users to their home directories (or set it to a shared FTP directory).

DefaultRoot ~

Following Symlinks

Note that following symlinks is not supported if the DefaultRoot directive is used because the directive creates a "jail" preventing access to any directories outside of it. Some administrators have said that mount --bind can be used to achieve this but it hasn't worked for us as that seems to just create a normal symlink as well.

Next steps

See also