8 Install Postfix, Dovecot, MySQL
Run
yast2 -i postfix postfix-mysql mysql mysql-community-server mysql-client libmysqlclient-devel dovecot12 dovecot12-backend-mysql pwgen cron python
If you get the error patterns-openSUSE-minimal_base-conflicts-12.1-25.21.1.x86_64 conflicts with python provided by python-2.7.2-7.1.3.x86_64, select the option deinstallation of patterns-openSUSE-minimal_base-conflicts-12.1-25.21.1.x86_64 and hit OK -- Try Again:
Hit Accept on the next screen...
... and finally OK:
Open /etc/postfix/master.cf...
vi /etc/postfix/master.cf
... and uncomment the following line:
[...] tlsmgr unix - - n 1000? 1 tlsmgr [...] |
Create the following symlink:
ln -s /usr/lib64/dovecot/modules /usr/lib/dovecot
Start MySQL, Postfix, and Dovecot and enable the services to be started at boot time.
systemctl enable mysql.service
systemctl start mysql.service
systemctl enable postfix.service
systemctl start postfix.service
systemctl enable dovecot.service
systemctl start dovecot.service
Now I install the getmail package:
yast2 -i getmail
To secure the MySQL installation, run:
mysql_secure_installation
Now you will be asked several questions:
server1:~ # mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <-- ENTER
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <-- Y
New password: <-- yourrootsqlpassword
Re-enter new password: <-- yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <-- Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- Y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <-- Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <-- Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
server1:~ #
Now your MySQL setup should be secured.
9 Amavisd-new, Spamassassin And Clamav
Install Amavisd-new, Spamassassin and Clamav antivirus. Run
yast2 -i amavisd-new clamav clamav-db zoo unzip unrar bzip2 unarj perl-DBD-mysql
Open /etc/amavisd.conf...
vi /etc/amavisd.conf
... and add the $myhostname line with your correct hostname below the $mydomain line:
[...] $mydomain = 'example.com'; # a convenient default for other settings $myhostname = "server1.$mydomain"; [...] |
Then create a symlink from /var/run/clamav/clamd to /var/lib/clamav/clamd-socket:
mkdir -p /var/run/clamav
ln -s /var/lib/clamav/clamd-socket /var/run/clamav/clamd
OpenSUSE 12.1 has a /run directory for storing runtime data. /run is now a tmpfs, and /var/run is now bind mounted to /run from tmpfs, and hence emptied on reboot.
This means that after a reboot, the directory /var/run/clamav that we have just created will not exist anymore, and therefore clamd will fail to start. Therefore we create the file /etc/tmpfiles.d/clamav.conf now that will create this directory at system startup (see http://0pointer.de/public/systemd-man/tmpfiles.d.html for more details):
vi /etc/tmpfiles.d/clamav.conf
D /var/run/clamav 0755 root root - |
Before we start amavisd and clamd, we must edit the /etc/init.d/amavis init script - I wasn't able to reliably start, stop and restart amavisd with the default init script:
vi /etc/init.d/amavis
Comment out the following lines in the start and stop section:
[...] start) # ZMI 20100428 check for stale pid file #if test -f $AMAVIS_PID ; then # checkproc -p $AMAVIS_PID amavisd # if test $? -ge 1 ; then # # pid file is stale, remove it # echo -n "(stale amavisd pid file $AMAVIS_PID found, removing. Did amavisd crash?)" # rm -f $AMAVIS_PID # fi #fi echo -n "Starting virus-scanner (amavisd-new): " $AMAVISD_BIN start #if ! checkproc amavisd; then # rc_failed 7 #fi rc_status -v #if [ "$AMAVIS_SENDMAIL_MILTER" == "yes" ]; then # rc_reset # echo -n "Starting amavis-milter:" # startproc -u vscan $AMAVIS_MILTER_BIN -p $AMAVIS_MILTER_SOCK > /dev/null 2>&1 # rc_status -v #fi ;; stop) echo -n "Shutting down virus-scanner (amavisd-new): " #if checkproc amavisd; then # rc_reset $AMAVISD_BIN stop #else # rc_reset #fi rc_status -v #if [ "$AMAVIS_SENDMAIL_MILTER" == "yes" ]; then # rc_reset # echo -n "Shutting down amavis-milter: " # killproc -TERM $AMAVIS_MILTER_BIN # rc_status -v #fi ;; [...] |
Because we have changed the init script, we must run
systemctl --system daemon-reload
now.
To enable the services, run:
systemctl enable amavis.service
systemctl enable clamd.service
systemctl start amavis.service
systemctl start clamd.service
10 Install Nginx, PHP5 (PHP-FPM), And Fcgiwrap
Nginx is available as a package for OpenSUSE which we can install as follows:
yast2 -i nginx-1.0
If Apache2 is already installed on the system, stop it now...
systemctl stop apache2.service
... and remove Apache's system startup links:
systemctl disable apache2.service
Then we create the system startup links for nginx and start it:
systemctl enable nginx.service
systemctl start nginx.service
(If both Apache2 and nginx are installed, the ISPConfig 3 installer will ask you which one you want to use - answer nginx in this case. If only one of these both is installed, ISPConfig will do the necessary configuration automatically.)
We can make PHP5 work in nginx through PHP-FPM (PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites) which we install as follows:
yast2 -i php5-fpm
Before we start PHP-FPM, rename /etc/php5/fpm/php-fpm.conf.default to /etc/php5/fpm/php-fpm.conf:
mv /etc/php5/fpm/php-fpm.conf.default /etc/php5/fpm/php-fpm.conf
Change the permissions of PHP's session directory:
chmod 1733 /var/lib/php5
Then open /etc/php5/fpm/php-fpm.conf...
vi /etc/php5/fpm/php-fpm.conf
... and change error_log to /var/log/php-fpm.log and uncomment pm.min_spare_servers and pm.max_spare_servers:
[...] error_log = /var/log/php-fpm.log [...] pm.min_spare_servers = 5 [...] pm.max_spare_servers = 35 [...] |
Next create the system startup links for php-fpm and start it:
systemctl enable php-fpm.service
systemctl start php-fpm.service
PHP-FPM is a daemon process that runs a FastCGI server on port 9000, as you can see in the output of
netstat -tapn
server1:~ # netstat -tapn
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3310 0.0.0.0:* LISTEN 10357/clamd
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 9869/dovecot
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10521/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1275/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 9816/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 10695/php-fpm.conf)
tcp 0 0 127.0.0.1:10024 0.0.0.0:* LISTEN 10337/amavisd (mast
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 9694/mysqld
tcp 0 0 192.168.0.100:22 192.168.0.199:4630 ESTABLISHED 1332/0
tcp 0 0 :::22 :::* LISTEN 1275/sshd
tcp 0 0 ::1:25 :::* LISTEN 9816/master
server1:~ #
To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications:
yast2 -i php5-mysql php5-bcmath php5-bz2 php5-calendar php5-ctype php5-curl php5-dom php5-ftp php5-gd php5-gettext php5-gmp php5-iconv php5-imap php5-ldap php5-mbstring php5-mcrypt php5-odbc php5-openssl php5-pcntl php5-pgsql php5-posix php5-shmop php5-snmp php5-soap php5-sockets php5-sqlite php5-sysvsem php5-tokenizer php5-wddx php5-xmlrpc php5-xsl php5-zlib php5-exif php5-pear php5-sysvmsg php5-sysvshm
Now restart PHP-FPM:
systemctl restart php-fpm.service
To get CGI support in nginx, we install Fcgiwrap.
Fcgiwrap is a CGI wrapper that should work also for complex CGI scripts and can be used for shared hosting environments because it allows each vhost to use its own cgi-bin directory.
As there's no fcgiwrap package for OpenSUSE, we must build it ourselves. First we install some prerequisites:
yast2 -i git patch automake glibc-devel gcc flex compat-readline4 db-devel wget gcc-c++ make vim libtool FastCGI-devel
Create the following symlinks:
ln -s /usr/include/fastcgi/fastcgi.h /usr/local/include/
ln -s /usr/include/fastcgi/fcgi_config.h /usr/local/include/
ln -s /usr/include/fastcgi/fcgi_stdio.h /usr/local/include/
ln -s /usr/include/fastcgi/fcgiapp.h /usr/local/include/
ln -s /usr/include/fastcgi/fcgimisc.h /usr/local/include/
ln -s /usr/include/fastcgi/fcgio.h /usr/local/include/
ln -s /usr/include/fastcgi/fcgios.h /usr/local/include/
Now we can build fcgiwrap as follows:
cd /usr/local/src/
git clone git://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure
make
make install
This installs fcgiwrap to /usr/local/sbin/fcgiwrap.
Next we install the spawn-fcgi package which allows us to run fcgiwrap as a daemon:
yast2 -i spawn-fcgi
We can now start fcgiwrap as follows:
spawn-fcgi -u wwwrun -g www -s /var/run/fcgiwrap.socket -S -M 0770 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/local/sbin/fcgiwrap
You should now find the fcgiwrap socket in /var/run/fcgiwrap.socket, owned by the user wwwrun and group www. We must now add the user nginx to the group www:
usermod -A www nginx
Reload nginx afterwards:
systemctl reload nginx.service
If you don't want to start fcgiwrap manually each time you boot your system, open /etc/init.d/boot.local...
vi /etc/init.d/boot.local
... and add the spawn-fcgi command at the end of the file - this will automatically start fcgiwrap at the end of the boot process:
[...] /usr/bin/spawn-fcgi -u wwwrun -g www -s /var/run/fcgiwrap.socket -S -M 0770 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/local/sbin/fcgiwrap |
That's it! Now when you create an nginx vhost, ISPConfig will take care of the correct vhost configuration.
10.1 Install phpMyAdmin
Next we install phpMyAdmin:
yast2 -i phpMyAdmin
As this installs Apache as a dependency, remove Apache's system startup links:
systemctl disable apache2.service
phpMyAdmin is now located in the /srv/www/htdocs/phpMyAdmin directory, but we want it in the /usr/share/phpmyadmin/ directory, so we create a symlink:
ln -s /srv/www/htdocs/phpMyAdmin /usr/share/phpmyadmin
After you have installed ISPConfig 3, you can access phpMyAdmin as follows:
The ISPConfig apps vhost on port 8081 for nginx comes with a phpMyAdmin configuration, so you can use http://server1.example.com:8081/phpmyadmin or http://server1.example.com:8081/phpMyAdmin to access phpMyAdmin.
If you want to use a /phpmyadmin or /phpMyAdmin alias that you can use from your web sites, this is a bit more complicated than for Apache because nginx does not have global aliases (i.e., aliases that can be defined for all vhosts). Therefore you have to define these aliases for each vhost from which you want to access phpMyAdmin.
To do this, paste the following into the nginx Directives field on the Options tab of the web site in ISPConfig:
location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpMyAdmin { rewrite ^/* /phpmyadmin last; } |
If you use https instead of http for your vhost, you should add the line fastcgi_param HTTPS on; to your phpMyAdmin configuration like this:
location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass 127.0.0.1:9000; fastcgi_param HTTPS on; # <-- add this line fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpMyAdmin { rewrite ^/* /phpmyadmin last; } |
If you use both http and https for your vhost, you need to add the following section to the http {} section in /etc/nginx/nginx.conf (before any include lines) which determines if the visitor uses http or https and sets the $fastcgi_https variable (which we will use in our phpMyAdmin configuration) accordingly:
vi /etc/nginx/nginx.conf
[...] http { [...] ## Detect when HTTPS is used map $scheme $fastcgi_https { default off; https on; } [...] } [...] |
Don't forget to reload nginx afterwards:
systemctl reload nginx.service
Then go to the nginx Directives field again, and instead of fastcgi_param HTTPS on; you add the line fastcgi_param HTTPS $fastcgi_https; so that you can use phpMyAdmin for both http and https requests:
location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass 127.0.0.1:9000; fastcgi_param HTTPS $fastcgi_https; # <-- add this line fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpMyAdmin { rewrite ^/* /phpmyadmin last; } |