Setting up a hosting environment with Froxlor on Gentoo

In the webhosting environment I will use Nginx, PHP 5.5 FPM and MariaDB. For customer management Froxlor will be used.
To successfully set up our hosting environment on Gentoo, we need to install a few packages beforehand. Afterwards we will use the configuration files provided by froxlor.

USE Flags

Before the packages for the base hosting environment are emerged the use flags should be set. I added  a directory called package.use in /etc/portage and placed a file called hosting_environment there. This has the advantage to that everything concerning the hosting can be placed in this file. Be sure to modify these use flags to your needs!

# required by sys-apps/unscd-0.51
# required by unscd (argument)
=sys-libs/glibc-2.20-r2 nscd

# Webserver
www-servers/nginx spdy

# Interpreters
dev-lang/php bcmath bzip2 calendar ctype curl discard-path exif fastbuild filter force-cgi-redirect ftp fpm gd hash iconv imap intl json mysql mysqli mysqlnd pcntl pdo pcre posix reflection sharedmem session simplexml sockets spell spl sqlite truetype tokenizer unicode xml xmlwriter xmlrpc xslt xsl zip

# Database
dev-db/mariadb -perl

Emerge packages

Run the following command and check the output if it fits your needs. Then get coffee.

emerge -av nginx php mariadb libnss-mysql unscd

Database (MariaDB)

As database I decided to use MariaDB over MySQL. There is not a big difference between these two, as MariaDB is a drop-in replacement for MySQL. But please refer to the following pages for more information:

https://mariadb.com/kb/en/mariadb/mariadb-vs-mysql-features/
https://mariadb.com/kb/en/mariadb/mariadb-vs-mysql-compatibility/

Configuring MariaDB

My current estimation is, that most of the action on the database server will be read-only transactions the my.cnf will be optimized towards this. All configuration options can be looked up at https://mariadb.com/kb/en/mariadb/server-system-variables/ which I recommend reading. As for now I dump my my.cnf configuration

# The following options will be passed to all MySQL clients
[client]
#password                                       = your_password
port                                            = 3306
socket                                          = /var/run/mysqld/mysqld.sock

[mysql]
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[mysqladmin]
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[mysqlcheck]
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[mysqldump]
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[mysqlimport]
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[mysqlshow]
character-sets-dir=/usr/share/mysql/charsets
default-character-set=utf8

[myisamchk]
character-sets-dir=/usr/share/mysql/charsets

[myisampack]
character-sets-dir=/usr/share/mysql/charsets

# use [safe_mysqld] with mysql-3
[mysqld_safe]
log-error               = /var/log/mysql/mysql.err

# add a section [mysqld-4.1] or [mysqld-5.0] for specific configurations
[mysqld]
bind-address            = 127.0.0.1
user                    = mysql
port                    = 3306
socket                  = /var/run/mysqld/mysqld.sock
pid-file                = /var/run/mysqld/mysqld.pid
log-error               = /var/log/mysql/mysqld.err
basedir                 = /usr
datadir                 = /var/lib/mysql
skip-external-locking

#
# * Locale
#
character-set-server    = utf8
lc_messages_dir         = /usr/share/mysql
lc_messages             = en_US

#
# * Tuning options
#
max_connections                 = 100
connect_timeout                 = 5
wait_timeout                    = 600
max_allowed_packet              = 16M
thread_cache_size               = 16
sort_buffer_size                = 4M
tmp_table_size                  = 32M
max_heap_table_size             = 32M
table_open_cache                = 400
net_buffer_length               = 16K
read_buffer_size                = 256K
read_rnd_buffer_size            = 512K

#
# * MyISAM + Aria
#
bulk_insert_buffer_size         = 16M
key_buffer_size                 = 1G
myisam_sort_buffer_size         = 128M

#
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit               = 1M
query_cache_size                = 256M

# security:
# using "localhost" in connects uses sockets by default
# skip-networking

#
# * Replication
#
#log-bin
#expire-log-days                = 10
server-id               = 1

# point the following paths to different dedicated disks
tmpdir                                          = /tmp/
#log-update                             = /path-to-dedicated-directory/hostname

#
# * InnoDB
#
innodb_buffer_pool_size = 2G
#innodb_data_home_dir           = /var/lib/mysql/
#innodb_log_arch_dir            = /var/lib/mysql/
#innodb_log_group_home_dir      = /var/lib/mysql/
innodb_data_file_path = ibdata1:10M:autoextend:max:128M
innodb_log_file_size = 512M
innodb_log_buffer_size = 8M
innodb_log_files_in_group=2
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_file_per_table

# Uncomment this to get FEDERATED engine support
#plugin-load=federated=ha_federated.so
loose-federated

[mysqldump]
quick
max_allowed_packet                      = 16M

[mysql]
# uncomment the next directive if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer_size                         = 20M
sort_buffer_size                        = 20M
read_buffer                             = 2M
write_buffer                            = 2M

[myisamchk]
key_buffer_size                         = 20M
sort_buffer_size                        = 20M
read_buffer_size                        = 2M
write_buffer_size                       = 2M

[mysqlhotcopy]
interactive-timeout

[mariadb]

Further reading concerning MySQL/MariaDB tuning:

http://www.tocker.ca/2013/09/17/what-to-tune-in-mysql-56-after-installation.html
http://www.percona.com/blog/2014/01/28/10-mysql-settings-to-tune-after-installation/

Migrating old Databases

Since my setup is not completely from scratch I will migrate the old databases. Most of the databases and tables are stored as MyISAM, which I will change to the default database storage engine InnoDB.

Starting the database

systemctl enable mysqld@.service
systemctl start mysqld@.service

To check the logs issue the following command

journalctl -b -u mysqld.service

PHP-FPM

It’s a little bit tricky to setup PHP since later the hosting users will be read from the froxlor database, but since we do not have it yet a local user will be created for the initial setup.

groupadd -g 9999 froxlorlocal
useradd -g froxlorlocal -M -s /bin/false -u 9999 froxlorlocal

Configuration

First the date.timezone in the php.ini should be set, as well as any other option you want to set for PHP.

date.timezone = Europe/Berlin

As froxlor later will generate a fpm-php configuration file for the panel, we will for now configure the default [www] fpm pool.

listen = /run/php-fpm-froxlorlocal.socket
listen.owner = froxlorlocal
listen.group = froxlorlocal
listen.mode = 0666
user = froxlorlocal
group = froxlorlocal

Enabling and starting PHP-FPM

systemctl enable php-fpm@5.5.service
systemctl start php-fpm@5.5.service

Again check the logs for erros

journalctl -b -u php-fpm@5.5.service

Webserver (Nginx)

As webserver I decided to use Nginx over Apache mainly because I noticed that Nginx is less memory intense and performs better, but inform yourself!

Configuration

To be able to install froxlor a temporary server has to be set up which is done by adding the following part to the nginx configuration file. Whereas the <IP> should be replaced with the external IP of the server and <HOSTNAME> with a FDQN under which the server is reachable.

...
server {
   listen <IP>;
   server_name <HOSTNAME>;
   index index.php;
   root /var/www/froxlor
   location ~ \.php$ {
       try_files $uri =404;
       include /etc/nginx/fastcgi.conf;
       fastcgi_pass unix:/run/php-fpm-froxlorlocal.socket;
   }
}
...

Enabling and starting PHP-FPM

systemctl enable nginx.service
systemctl start nginx.service

Froxlor Panel

Now that the base hosting environment is running, froxlor can be installed which is now pretty strait forward.

cd /var/www
wget http://files.froxlor.org/releases/froxlor-latest.tar.gz
tar xvfz froxlor-latest.tar.gz
chown froxlorlocal.froxlorlocal -R froxlor
rm froxlor-latest.tar.gz

Now open a browser and enter http://<HOSTNAME>/ and you should see the froxlor installation screen. Follow the instructions and setup froxlor.

Conclusion

A basic hosting environment has been setup and we can start working on configuring the rest of the system. Later on the previously configured PHP-FPM Pool [www] will be deleted in favor of the froxlor generated pools.

I also would recommend to go through the froxlor panel settings first and then start to configure the other services which I describe in these Posts:

URL1 (WIP)
URL2 (WIP)

2 Comment

  1. d00p says:

    nicely done, but you do know that we have an ebuild for gentoo? See http://redmine.froxlor.org/projects/froxlor/wiki/InstallationGentoo

  2. Benjamin says:

    Yes I do know, but as said my setup differs a little bit and I like to have such basic things done by hand. I might try the ebuild later in a VM.

Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.