HOW-TO Setup a PLESK Dedicated Server
IMPORTANT NOTE FOR BEGGINERS
Before continue this tutorial, you need to have knowledge of SSH or you may ruin your server.
If you need installation support, better order this service from us, we will do this job for you for only 50USD. Usually could take aprox 2 hours.
We will need to get from you SSH access with root access.
Be sure that after get it, edit. Change the following things. Lines with # … every 1GB of RAM;
After my.cnf is configured, you can use MySQL Performance Tuning Primer Script, but MySQL must run minimum 24 hours to get correct data, to configure your server. Link to the script is:http://www.day32.com/MySQL/tuning-primer.sh or MySQLTuner http://wiki.mysqltuner.com/MySQLTuner, run it and correct the data in /etc/my.cnf (we prefer the second one)
yum remove drweb-qmail drweb
qmail-scanner clamd qgreylist spamassassin dcc pyzor razor-agents
service spamassassin restart
service clamd start
Configure qmail-scanner with the /etc/qmail-scanner.ini file.
For this you need to enable ATOMIC REPO – TEST
enabled = 1
Now all should work fine, you can check to send to you a test virus from http://www.aleph-tec.com/eicar/index.php
In meantime check log files to see if all work fine and no errors are there.
-f /var/spool/qmailscan/qmail-queue.log /usr/
We found a very nice auto installer. (http://www.servermonkeys.com/els.php)
wget --output-document=installer.sh http://servermonkeys.com/projects/els/installer.sh
Install ONLY APF, BDF from it, the rest will be ignored. You can still see els –help for other packages.
When you are done, you still need some modification.
Here you will add your IP to ignore it. VERY IMPORTANT to not be lock out from server.
The format of these files are line-seperated addresses, IP masking is supported.
# Try to detect syn-flood attacks [0=off,1=on]
# Parse klog for iptables logged attacks [0=off,1=on]
Here you setup to send to you some antidos alert.
Check as well for ports:
# Common ingress (inbound) TCP ports
IG_TCP_CPORTS="20,21,25,53,80,110,143,443,465,993,995,3306,5224,8443,8080,11443,11444,30000,35000_35999" (notice no 22 port for SSH – we suggest this, also if you use ASL, add 30000, 11443_11444 port for sitebuilder, SSO)
Also look for
USE_DS="1", usually have value 0, change to 1.
If you get: “Cannot load iptables” message, then you need to set in /etc/apf/conf.apf line SET_MONOKERN=”1″ (especially if you use VPS or ASL module from AtomicCorp)
If Firewall work OK do not forget to get out from DEV mode and restart …
# Set firewall dev cronjob
# 1 = enabled / 0 = disabled
10. Disable some executables
Many php exploit scripts use common *nix tools to download root kits or backdoors. By simply chmod’ing the files so that no none-wheel or root user can use them we can eliminate many possible problems. The downside to doing this is that shell users will be inconvenienced by not being able to use the the commands below. If you run LES, which I would suggest, then you do not need to run the first group of chmods. If you get an error on the chmod 000 because a directory does not exist to not worry they are not on every server.
Also a suggestion that make a backup of /usr/bin, /usr/sbin, /bin, /sbin if someone overwrite in time this executables (will be infected by a chrootkit) then is easy to replace.
Going a step further might be to run the same chmod permission setting on ‘/usr/bin/*cc*’. This will only allow root to run compile programs like ‘gcc’. Such hardening suggestions can help to stave off local and remote attacks, but don’t consider them 100% foolproof either. Think of this as just another layer of security. Now I cannot give to you a list here, cause can be different files which is not compile libraries, ex.mysqlaccess, contain *cc*. So best is to use like
700 byacc cc gcc gnatgcc i386-redhat-linux-gcc perlcc yacc
(this is just an example, see what *gcc return)
12. RKHUNTER & LYNIS
Now we will install rkhunter so we will at least know if the server has been cracked. Note that a false positive is not always bad and you need to investigate the error before thinking you are hacked. Things such as compiling a 2.6.9 kernel on your server will cause binaries to change and rkhunter to suspect the server was cracked. Also unfortunatelly rkhunter will give a lot of false positive as well, you will need to configure what to ignore in rkhunter.conf
13. Register Globals and Error Reporting and mod_security
First open the php.ini file
Register_globals is something that ideally php coders would code to allow to be turned off but many do not. Because of that disabling this feature may cause a lot of scripts to break. If you are on a shared host it is probably best if you do not enable this. If you are not a shared host then there is probably nothing wrong with it but do make sure by looking at all of your web sites to ensure it did not break any. That being said if you can get away with it then your server is going to be more secure. This comes down to the usability vs security issue, yes it makes it more secure but it also blocks some popular scripts. Use this at your own risk! To disable it search for “register_globals”. It will currently be set to “On” go ahead and change it to “Off”.
Next step is to find display_errors = On and change it to display_errors = Off, you can also turn on log_errors = On and if you like change
error_reporting = E_ALL & ~E_NOTICE into
error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
Disable some problematic php variables, which can be insecure for the server (but also be aware this disable_functions can affect some PHP programs).
Just a note here: If you disable functions, in some cases can broke Horde. There is a workaround for fix this, better disable and then use the workaround. Also can broke some other programs like Joomla, WordPress etc.
For workaround for HORDE – Breun was posted on PLESK forum a solution. Edit /etc/psa-horde/horde/conf.php (Plesk 8) or /etc/psa/webmail/horde/horde/conf.php (Plesk 9 and, I assume Plesk 10?)
1) Change $conf[‘mailer’][‘type’] from ‘sendmail’ to ‘smtp’ 2) Add the following line: $conf[‘mailer’][‘params’][‘host’] = ‘localhost’;
In this way, horde will use SMTP and no longer needs popen to be enabled.
Also I suggest to change some settings, search for them.
max_execution_time = 120
max_input_time = 240
memory_limit = 128M
expose_php = Off
Restart apache for it to take effect.
Register Global change can affect this settings some scripts, you need to tell to your customers about this.
Install mod_security with YUM. This tool can prevent a lot of problems, file injections, attacks etc to APACHE.
From this pages, you can get the Free Mod_Security Rules (Delayed 30+ days). http://downloads.prometheus-group.com/delayed/rules/ You can get it, and untar it to/etc/httpd/modsecurity.d Be sure that 00_asl_rbl.conf, 00_asl_whitelist.conf will be uninstalled, renamed or deleted (if anyone know an another workaround??!). But still consider to use ASL services, pay for it, you are more secured. (https://www.atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules#Delayed.2FUnsupported.2FFree_Rules)
Also create a file, this is for your custom security rules.
In some cases you can get error of tortix. Fix like this
touch /etc/httpd/modsecurity.d/tortix_waf.conf mkdir -p /etc/asl touch /etc/asl/whitelist
Then you can add a few line like for example. You can disable some rules what you do not need or create problems.
; LocationMatch .* &
; /LocationMatch &
SecRule REMOTE_ADDR "
; LocationMatch /var/www/vhosts/YOURDOMAIN/httpdocs/admin/ &
; /LocationMatch &
See more docs here: http://www.atomicorp.com/wiki/index.php/Mod_security
IMPORTANT: Mod_security can introduce a lot of issues, so if you think that you cannot handle it, or your clients will start to yell on you because they get a lot of 550 Forbidden, better use ASL WEB GUI or learn more about mod_sec on forums. Also Power Toys can help at least manage/disable more easily some rules.
14. Services Version Number
Version numbers can be used by various software scanners to determine if your server is vulnerable. Though you should have the latest versions of everything security though obscurity is one method that can be employed to help secure your server.
First we are going to hide the version information in apache.
Search for “ServerSignature”
It should say On, change it to Off
This will remove the identification of apache from error pages
Right below that add a line that has the following:
This will identify apache simply as “apache” with no version numbers or OS information
Save out of the file and restart apache
You can do a TEST before restart
Need to get: Syntax OK
Next we will disable named from giving a version.
Search for “query-source address * port 53;”
Add a line right below it with
Save and restart named
Remember this is just security though obscurity and you still need to keep the server updated! This is just going to stop some people from finding your server in the first place. It will not help at all if somebody is trying to actually hack the server.
15. PHP Optimizer/CACHE
On PHP 5.3 you cannot use php-zend-optimizer, you must use ZendGuard.
XCache is also easy to install, you can get from http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gz.
Check the place where the xcache.so is installed (some lib directory)
Then copy from xcache-1.3.0/xcache.ini into /etc/php.d/axcache.ini (use axcache to avoid problems with any zend extensions (Ioncube, Zend etc))
Edit /etc/php.d/axcache.ini and correct the path for xcache.so (to load from correct place).
Restart apache and check with php -v if is loaded.
If apache not restart, see if the problem is not with Zend Optimizer and XCache.
IMPORTANT: After restart Apache, and execute php -v you may get error messages like “Failed loading /usr/local/Zend/lib/Optimizer-3.3.0/php-5.2.x/ZendOptimizer.so: /usr/local/Zend/lib/Optimizer-3.3.0/php-5.2.x/ZendOptimizer.so: cannot restore segment prot after reloc: Permission denied”.
You will need to execute like this, just change the correct path to SO files.
chcon -t texrel_shlib_t /usr/lib/php/zend/ZendOptimizer-5.2.so
execstack -c /usr/
/Zend/lib/Optimizer-3.3.0/php-5.2.x/ZendOptimizer.so php -
If you fo not get any error, problem is solved. In some cases also SELinux can create problems, we always disable it and use ASL.
16. FTP Passive Mode Port
You need to edit /etc/proftpd.conf and add a line like
PassivePorts 35000 35999
After this see please APF Firewall settings at line IG_TCP_CPORTS= is there this port??
Then execute restart of XINETD
Also read this article about extra FTP info and check … http://www.grafxsoftware.com/faq.php/Web-Site-hacked-iframe-inserted-where-to-start/1/14/
If you want to change the FTP port, you need to change in /etc/proftpd.conf, also in /etc/services and open in your firewall the new port.
17. Secure MORE your server with ASL – (Subscribe here …)
Atomic Secured Linux is designed to improve overall system security by introducing both Kernel hardening techniques, as well as userspace utilities to your linux server. Currently, Atomic Secured Linux contains the latest 2.4 and 2.6 linux kernels, modified with the grsecurity.net kernel patch, mod_dosevasive and mod_security. Grsecurity is an innovative approach to security utilizing a multi-layered detection, prevention, and containment model. Even if is a pay service, it worth every penny. Belive me, we use it. Also have a PLESK Control Panel Addon where you can edit everything visual.
You can install ASL, but will require login and password. (Subscribe here, 158USD/year)
IMPORTANT: If you are using PLESK 11, then we suggest to use CGI mode for all domains, work very well. in this case you can skip SUPHP install.
A lot of people have problems with different PHP softwares like Joomla, Drupal, WordPress, different Gallery software, especially where need to upload pictures. Why? Because now in a new settings, PHP will work as apache:apache user and any files uploaded via a web interface will get this user rights. Any files uploaded via FTP clients, will get the domain ownership. SO, if you for example want to get all picture files added via WEB INTERFACE, you cannot download or overwrite via FTP because the file rights. Also on install a lot of people need to setup folders to 777 rights to uload in it.
So seems the mod_suPHP solution is nice and working with the following settings. Some people recommending mod_ruid2 but I did not found a way to have with that module php.ini for each directory. mod_suphp is older but it work 100% guaranteed.
IMPORTANT UPDATE: In 0.7.1 handle_userdir=true is deprecated, if you do an upgrade, just delete this line. If is new install, should not be there.
After this, /etc/httpd/conf.d/mod_suphp.conf (important this line LoadModule suphp_module modules/mod_suphp.so, rest can be uncommented on Debian/Ubuntu is not the same place, is in apache kind of directory); /etc/suphp.conf (use default, except umask=0022)
If is PHP5, change in /etc/suphp.conf
;Use correct permissions
Allow files to be group writeable. Is disabled by default.
Allow directories scripts are residing in to be group writeable.
Is disabled by default.
Allow files to be writeable by world. Is disabled by default:
WARNING: Enabling this option is very dangerous and causes major
security issues, especially the danger of arbitrary code execution!
Allow directories scripts are residing in to be writeable by world.
Is disabled by default:
WARNING: Enabling this option is dangerous!
Here change line suPHP_Engine on into #suPHP_Engine on (this is very important)
If you compiled suphp with setid-mode “force” or “paranoid”, you can specify the user- and groupname to run PHP-scripts with.
Example: suPHP_UserGroup ftpuser psacln
The major things come with: httpd.include of each domain need to add, before < /VirtualHost >, the line Include /var/www/vhosts/domain.com/conf/vhost.conf
Then create vhost.conf. (We suggest to use for this Power Toys, this will suggest exactly what you need to do and modify the file for you). Also from version 4.9.0 will fix the permissions if suphp will be turned to ON.
In vhost.conf you need (delete the spaces between < and > in the config.):
; IfModule mod_suphp.c &
php_admin_flag engine on
AddHandler x-httpd-php .php
AddHandler php5-script .php
AddHandler x-httpd-php .php .php5 .php4 .php3 .phtml
suPHP_AddHandler php5-script .php
; Files php.ini &
deny from all
; /Files &
; /Directory &
; /IfModule &
Need to focus on BOLD issues. DOMAIN is your domain, AddHandler one line is for PHP4, the other for PHP5, dunno if will work both together. Create in httpdocs/tmp directory, to write in it, as temporary upload dir. We still study this to move one directory up, but is not tested yet: DOMAIN/tmp/. After this, you need to add a php.ini file in your httpdocs directory, which will be use for that domain. this file cannot be read from outside because is restricted. To test if is work, create a file wit lines,
< ?php phpinfo(); ? > and call it from web. You can see if is loaded new PHP.INI or not and mod_suPHP is on.
People have asked for a good php.ini (for each httpdocs environment, on suPHP only). So here it is our suggestion for Joomla.
output_buffering = On
zlib.output_compression = On
max_execution_time = 120
max_input_time = 120
memory_limit = 256M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
register_long_arrays = Off
post_max_size = 32M
session.gc_maxlifetime = 3600
magic_quotes_gpc = On
upload_max_filesize = 32M
IMPORTANT: By default, we disabled mod_suphp, so you need to add to all existing domains manually (Power Toys will add automatically on new domains). Why is this so important? Because if you enable on all domains, and before you had 777 rights on folders or files, suPHP will give error on wrong GID or UID and will stop executing. So before enable, be sure that all folders on a domain is 755 and files 644.
19. Disable SELinux
Usually we disable SE Linux, we got only problems with it. We prefer to let ASL to do the job, but if you do not use ASL, no problem still we suggest to disable it. A lot of other security layers are out. In Fedora Core and RedHat Enterprise, edit /etc/selinux/config and change the SELINUX line to SELINUX=disabled
You can check the status with
You can also switch the system into permissive mode with the following command
20. Check if mail is sending out
Sometimes mailsending is not working, you can check easily if you send from shell command line a mail
Press Control + D. If mail goes out, is OK, or you get an error.
20. Additional PHP Modules to install, mod_dav_svn and mailparse
In the webhosting business, you should support more then the default modules for PHP and why not SVN. So I suggest to install the following modules:
pecl download mailparse
service httpd restart
Note that I’ve called the ini file ‘mmailparse.ini’ as the php.d ini files are loaded in alphabetical order. Mailparse needs mbstring so it needs to be loaded firstor else you will get a warning like ……PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/mailparse.so’ – /usr/lib64/php/modules/mailparse.so: undefined symbol: mbfl_name2no_encoding in Unknown on line 0
Also is good to have Image Magick installed, a lot of people use it. Simple, just run
Also we recommend to install a new PECL module, installprogress (http://pecl.php.net/package/uploadprogress). This is very used in the last period.
21. Add more Courier-IMAP connections
Plesk comes configured with a limit of 4 connections per IP address and a limit of 40 connections total. Modern IMAP clients such as Mozilla Thunderbird use mailbox caching to open up multiple connections to increase performance. In the case of Thunderbird, it opens up 5 connections by default which is already 1 connection more than Courier-IMAP’s default restriction. Add another few family or corporate computers behind a firewall and those additional users won’t be able to connect at all since a single Thunderbird client is already utilizing all 4 connections. This can increase the load of the server, but also is a must to not have complains from clients that they cannot connect to the server to get mails. You can raise this numbers depending on your server memory (our suggestion is for 2GB memory)
22. Backup your server
We suggest to setup a backup system to your server. This mean that in 99% of the cases, datacenters offer a backup place. Use that and backup your important files. Read how to do this at page – Automated Remote FTP Backup shell script
23. Avoid Dr.Web update notifications
In latest plesk version (plesk 9.5) following notifications generated from plesk and send to plesk administrator which irritate sometimes. You can stop such notifications by applying following fix on server.
Please open file /etc/cron.d/drweb-update using an editor and add ‘>/dev/null 2>&1‘ at the end of the line. In this case no email will be generated.
*/30 * * * * drweb /opt/drweb/update.pl >/dev/null 2>&1
23. Install mod-pagespeed for APACHE.
Thismodule can speed up your pages a lot.
yum install at rpm -Uhv https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
If all goes well, the module is already installed now, just restart apache. You can check if exist /etc/httpd/conf.d/pagespeed.conf Also you can play with this conf file as you like to test the best performance. Eventually I prefer to deactivate ModPagespeedStatistics OFF
24. ATMail search bug in PLESK 10.x.
After upgrading to Plesk 10, the search facility in Atmail stopped working, people search for emails and they get empty results. The problem is with the search.php file in the ATMail directory which was appending ’20’ to the search date range years, even though they already had a leading 20. This was producing an IMAP query like this:
FROM “test search” BEFORE “31-Dec-202011” SINCE “25-Sep-202010”
To fix, edit search.php in the atmail directory (/var/www/atmail/search.php)
Change Line 364: $before = “$BeforeDay-$BeforeMonth-$BeforeYear”;
Change Line 369: $after = “$AfterDay-$AfterMonth-$AfterYear”;
Go and login into PLESK admin and do the following steps.
Before all, click on update and do an update.
Click on SERVERS:
1. Change password: Change passwords to access into PLESK.
2. Access: Setup PLESK ADMIN access and add your IP, in this way you restrict ADMIN access from your IP.
3. System time: I use synchronize time with server: time.windows.com, anyway setup here the correct zone.
4. Mail preferences: Enable MAPS protection to zen.spamhaus.org;cbl.abuseat.org and also I use POP3 lock time to 20 minutes.(important)
5. Mailman settings: Setup email and password.
6. DNS – Read the manual.
7. Logo Setup – to setup your Company LOGO
8. Crontab – Set crontab message, if need change here the mail to not send to root.9. Activate Watchdog, each services, disk space etc.
Next step is CLIENTS AND DOMAINS, but this is documented in manuals, so I suggest to read it.
ADDITIONAL USEFULL TOOLS:
http://www.web-hosting-control-panel-addons.com/product.php/Power-Toys-for-PLESK/1/ – Power Toys for PLESK – Must have for PLESK
http://www.grafxsoftware.com/product.php/Backup-on-Demand-for-PLESK/189/ – Backup on Demand for Power Toys for PLESK
http://www.day32.com/MySQL/tuning-primer.sh – MySQL Performance Tuning Primer Script
http://gert.sos.be/demo/mysqlar/ – MySQL Activity Report
http://www.4psa.com/ – 4PSA have several nice tools for PLESK.
http://www.host-tracker.com/ – you can subscribe to this services to get reports (SMS if you need) about your server uptime.
http://jeremy.zawodny.com/mysql/mytop/ – MySQL Top program
http://www.ex-parrot.com/~pdw/iftop/ – IFTop, display bandwidth usage on an interface.
http://www.webta.org/projects/ – ApacheTOP
http://ngm.id.au/checkhab – checkHAB is a script based on checkattach
http://sourceforge.net/projects/automysqlbackup/ – MySQL Backup
http://www.mod-top.org/versions.html – Mod Top
ADDITIONAL USEFULL TRICK:
How To Filter Tagged Spam to a Spam IMAP Folder – http://forum.swsoft.com/showthread.php?s=&threadid=46883
Qmail-scanner package has options for blocking specific extensions –