1 Notes
+ Installation and Configuration (Aug. 22, 2014, 8 a.m.)

Source: 1-Install MySQL: apt-get install mysql-server mysql-client During installation set an optional password. 2-Install Nginx, as in the tutorial file of nginx, in my tutorials. 3-Create a directory named roundcube (or something else) in an optional path: mkdir /home/mohsen/roundcube/ sudo chown www-data.www-data roundcube -R 4-Install PHP: We can make PHP5 work in nginx through FastCGI. Fortunately, Debian Squeeze provides a FastCGI-enabled PHP5 package which we install like this (together with some PHP5 modules like php5-mysql which you need if you want to use MySQL from your PHP scripts): sudo apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-intl php5-pgsql 5-Install lighttpd: There's no standalone FastCGI daemon package for Debian Squeeze, therefore we use the spawn-fcgi program from lighttpd. We install lighttpd as follows: sudo apt-get install lighttpd NOTEEE: You will see an error message saying that lighttpd can't start because port 80 is already in use: Starting web server: lighttpd2011-02-24 01:43:18: (network.c.358) can't bind to port: 80 Address already in use failed! invoke-rc.d: initscript lighttpd, action "start" failed. That's how it's supposed to be because nginx is already listening on port 80. Run update-rc.d -f lighttpd remove so that lighttpd will not start at boot time. NOTE: Once I did this "update-rc.d ..." and well it should have been removed this lighttpd from auto starting when the VPS starts. But when I restarted the VPS it did run automatically and it caused nginx not run, so the websites would not open. If this happened, just run this "update-rc..." command again and reboot the VPS. We've installed lighttpd because we need just one program that comes with the package, /usr/bin/spawn-fcgi, which we can use to start FastCGI processes. Take a look at spawn-fcgi --help to learn more about it. 6-To start a PHP FastCGI daemon listening on port 9000 on localhost and running as the user and group www-data, we run the following command: /usr/bin/spawn-fcgi -a -p 9001 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/ Of course, you don't want to type in that command manually whenever you boot the system, so to have the system execute the command automatically at boot time, open /etc/rc.local... 7-Create an optional folder (e.g. configs) in /roundcube/ and then: nano configs/virtual_host (this file name is also optional) Then: server { server_name; access_log /home/mohsen/roundcube/logs/mohsenhassani_access.log; error_log /home/mohsen/roundcube/logs/mohsenhassani_errors.log; location / { root /home/mohsen/roundcube/; index index.html index.php; } location ~ \.php$ { fastcgi_pass; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/mohsen/roundcube$fastcgi_script_name; include fastcgi_params; } } 8-Reload nginx: sudo /usr/local/nginx/sbin/nginx -s reload OR Better to: (I don't know why using -s reload it won't work; I mean it won't notice about the changes sometimes). sudo /usr/local/nginx/sbin/nginx -s stop sudo /usr/local/nginx/sbin/nginx 9-Installing APC: APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and XCache. It is strongly recommended to have one of these installed to speed up your PHP page. APC can be installed as follows: sudo apt-get install php-apc 10-Configure the default timezone in PHP: nano /etc/php5/cli/php.ini date.timezone = "Asia/Tehran" 11-Stop PHP: First you have to find the PID by which PHP is running: netstat -tap Look for the process which is taking port <9001> and kill it by it id: kill <pid> 12-Afterwards we create a new spawn-fcgi process: /usr/bin/spawn-fcgi -a -p 9001 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/ 13-Installing Roundcube: Installation consists of downloading the gz file from the address:, and extracting it in the /roundcube/ directory. wget tar xvfz roundcubemail-0.7.1.tar.gz cd roundcubemail-0.7.1/ mv * /home/mohsen/roundcube/ mv .htaccess /home/mohsen/roundcube/ 14-Make the document root and the Roundcube files in it writable by the nginx daemon which is running as user www-data and group www-data: chown www-data.www-data /home/mohsen/roundcube/ -R 15-Reload nginx 16-For installing postgres user and database and its tables, access postgres shell, and: createuser --pwprompt roundcube createdb -O roundcube -E UNICODE roundcubemail psql roundcubemail \c - roundcube \i ./roundcube/SQL/postgres.initial.sql The last command should create tables. Done. 17-In this page, If you see the <NEXT> button as active, (I mean if it's clickable and not disabled) then everything is okay and you can go to the next step by clicking the <NEXT> button; But if it's not active, then you have to fix the errors listed in the page. Just keep in mind that every time you fix an error, and you want to test if it works, you have to kill the php5-cgi using the <netstat> command as said in step 11, and then run it again using step 6. Then again refresh the setup page to see if the <NEXT> button is active. 18-The configuration for postgres database is as the follow: (it's mentioned in the INSTALL file of roundcube too) $ createuser roundcube $ createdb -O roundcube -E UNICODE roundcubemail $ psql roundcubemail roundcubemail =# ALTER USER roundcube WITH PASSWORD 'the_new_password'; roundcubemail =# \c - roundcube roundcubemail => \i /home/mohsen/roundcube/SQL/postgres.initial.sql -------------------------------------------------------------------------------------------- Ok Now I could receive mails, but could not send mails, the damned "relay access denied" again; for solving the error: $rcmail_config['smtp_user'] = '%u'; $rcmail_config['smtp_pass'] = '%p'; $rcmail_config['smtp_auth_type'] = 'plain'; $rcmail_config['smtp_server'] = ''; $rcmail_config['smtp_port'] = 25; ------------------------------------------------------------------------------------------- Roundcube is dependent on linux users. I mean if you don't have an account on the VPS, you can't use roundcube. If you don't have an account, you'll get an error like "Login failed." and still if you have an account you might get an error like "Connection to the storage server failed." which is because you have no directory named "Maildir" at the /home/ of the user. So create one, and you'll go okay :) And of courseee, the "Maildir" directory should be of group and user same as of its /home/; I mean: chown mohsen.mohsen /home/mohsen/Maildir Don't forget to restart spawn-cfgi -------------------------------------------------------------------------------------------- For creating a new web mail for my customers: 1-Using adduser command add a username as their receiving name. For example In this case the username is "mohsen". 2-Creating a directory named 'Maildir' in their home: su <new_username> cd /home/<username> mkdir Maildir chown mohsen.mohsen /home/mohsen/Maildir -R 3-Register their domain name '' in server_name: nano /home/mohsen/configs/roundcube 4-Register their domain name '' in mydestination: nano /etc/postfix/ 5-That's it! Restart nginx and you have to open the address: Everything should work. << Don't forget to create a sub-domain named "mail." in their domain panel and forward it to server. >> -------------------------------------------------------------------------------------------- Erorrs that I have encountered so far: Note: Before reading the errors and the solutions, don't forget to stop the spawn-fcgi, and run it again. And also reload nginx AFTER any changes you do for solving any of the problems. Erorr 1-suhosin.session.encrypt: NOT OK(is '1', should be '0'): For solving this error I needed to edit the file nano /etc/php5/conf.d/suhosin.ini and uncomment this line (by deleting the ; semi-colon) and edit it as follow: suhosin.session.encrypt = off And only kill the spawn-fcgi and run it again. No need to reload nginx. Error 2-date.timezone Not OK or any other errors pertaining the date.timezone: Edit the file: nano /etc/php5/cgi/php.ini Search for "timezone", and change it as follow: date.timezone = "Asia/Tehran" Re-run the spaw-fcgi It's essential to set the variable "auto_create_user" to true in file "roundcube/config/": rcmail_config['auto_create_user'] = true And after the first user has been created and logged in, set it to false. So having this variable set to true and restarting the spawn-fcgi I could finally log in. -------------------------------------------------------------------------------------------- Error: The uploaded file exceeds the maximum size of 2.0 MB.: For solving this error: nano /etc/php5/cli/php.ini Search for "upload_max_filesize" and change its value to for example 100M. NOPE! Not solved yet....