Project

General

Profile

Support #436

Updated by Daniel Curtis about 9 years ago

{{>toc}} 

 This is a simple guide for setting up Diaspora* on a FreeBSD FAMP server. 

 h1. Prerequisites 

 * Update the system and ports tree 
 <pre> 
 pkg update && pkg upgrade 
 portsnap fetch extract 
 </pre> 

 * Install ca_root_nss 
 <pre> 
 cd /usr/ports/security/ca_root_nss 
 make config 
 make reinstall clean 
 </pre> 
 #* *NOTE*: Make sure to enable @*[X]* ETCSYMLINK@ when running make config. This is to prevent an error later when running @bundle install@. 

 * Install portmaster: 
 <pre> 
 cd /usr/ports/potrs-mgmt/portmaster 
 pkg2ng 
 </pre> It is assumed that you have a fresh install of FreeBSD, using portsnap for ports tree management. You will also need a non-root user that will own the Diaspora* installation and processes. 

 * It is *vitally important* that you do not use tabs in make.conf. This will break your system! The settings here are in addition to any others you already have, and are required to prevent conflicts. 
 <pre> 
 echo 'WITH_PKGNG=yes' >> /etc/make.conf 
 echo 'WITHOUT="X11"' >> /etc/make.conf 
 echo 'OPTIONS_UNSET=X11' >> /etc/make.conf 
 echo '#! DO NOT USE SPACES OR COMMENTS IN THE FOLLOWING LINE EVER!' >> /etc/make.conf 
 echo 'DEFAULT_VERSIONS=      perl5=5.16 ruby=2.1 python=2.7 postgresql=9.3 mysql=5.5' >> /etc/make.conf 
 echo 'PERL5_DEFAULT=5.16' >> /etc/make.conf 
 echo 'RUBY_VER=2.1' >> /etc/make.conf 
 echo 'WANT_PGSQL_VER=93' >> /etc/make.conf 
 echo 'WANT_MYSQL_VER=55m      #! 55m for MariaDB, 55p for Percona' >> /etc/make.conf 
 </pre> 

 * The following packages are optional but recommended before you begin building Diaspora* on FreeBSD: 
 <pre> 
 pkg install bash portmaster shells/bash security/sudo devel/gmake devel/git devel/subversion lang/python27 ftp/curl devel/automake ca_root_nss sudo gmake git subversion python27 curl automake    graphics/ImageMagick-nox11 print/ghostscript9-nox11 lang/ruby21 www/node www/npm devel/libtool devel/bison devel/readline textproc/rubygem-nokogiri databases/redis ImageMagick-nox11 ghostscript9-nox11 ruby21 node libtool bison readline 
 </pre> 

 * Enable and start Redis Install rubygem-nokogiri from ports: 
 <pre> 
 echo 'redis_enable="YES"' >> /etc/rc.conf cd /usr/ports/textproc/rubygem-nokogiri 
 service redis start make install clean 
 </pre> 

 --- 

 h1. Setup Diaspora Environment 

 * Add the diaspora user along with the group using the helper script: 
 <pre> 
 mkdir /usr/local/www/diaspora 
 pw add user -n adduser 
 </pre> 
 #* And use the following: 
 <pre> 
 Username: diaspora -m -s /usr/local/bin/bash -c "Diaspora*" 
 Full name: Diaspora* 
 Uid (Leave empty for default):  
 Login group [diaspora]:  
 Login group is diaspora. Invite diaspora into other groups? []:  
 Login class [default]:  
 Shell (sh csh tcsh bash rbash git-shell nologin) [sh]: bash 
 Home directory [/home/diaspora]: /usr/local/www/diaspora 
 Home directory permissions (Leave empty for default):  
 Use password-based authentication? [yes]: no 
 Lock out the account after creation? [no]:  
 yes 
 no 
 </pre>  

 

 h2. Install RVM 

 * Switch to the diaspora user: 
 <pre> 
 su - diaspora 
 </pre> 

 * Install RVM and Ruby 2.1 
 <pre> 
 curl -sSL https://get.rvm.io | bash -s stable 
 source /usr/local/www/diaspora/.rvm/scripts/rvm 
 echo '[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm"' >> ~/.bashrc 
 rvm autolibs read-fail 
 rvm install 2.1 
 </pre> 

 * Install bundler inside of RVM: 
 <pre> 
 gem install rubygems-bundler bundler 
 </pre> 

 * To make life easier for yourself, you should set your Diaspora* environment variables in the shell rc for your shell of choice. Here are some examples: 
 * bash 
 <pre> 
 echo 'export RAILS_ENV="production"' >> ~/.bashrc 
 echo 'export DB="mysql2"' >> ~/.bashrc 
 </pre> 

 * Exit back into root: 
 <pre> 
 exit 
 </pre> 

 --- 

 h1. MariaDB 5.5 Server 

 PostgreSQL will always offer the best performance on FreeBSD, especially on multi-core systems. PostgreSQL 9.3 offers significant performance benefits over prior versions as well. However my production environment limits the use of PostgreSQL, so I will use MariaDB instead 

 * Install MariaDB: 
 <pre> 
 portmaster databases/mariadb55-client databases/mariadb55-server pkg install mariadb55-client mariadb55-server 
 </pre> 

 h2. Configure MariaDB 

 * Copy a base MariaDB configuration to use 
 <pre> 
 cp /usr/local/share/mysql/my-small.cnf /var/db/mysql/my.cnf 
 </pre> 

 * Tuning: Copy one of the default config files and change the max packet size: 
 <pre> 
 vi /var/db/mysql/my.cnf 
 </pre> 
 #* and modify max_allowed_packet to 32M 
 <pre> 
 max_allowed_packet = 32M 
 </pre> 

 * Enable and start MariaDB 
 <pre> 
 echo 'mysql_enable="YES"' >> /etc/rc.conf 
 service mysql-server start 
 </pre> 

 * Prepare Database for use by running the secure installation: 
 <pre> 
 mysql_secure_installation 
 </pre> 
 *NOTE*: Choose a strong root password and answer yes to all questions. 

 h3. Create Database MariaDB Databases and User Users 

 * Login to MariaDB and create appropriate databases and users. 
 <pre> 
 mysql -u root -p 
 </pre> 
 #* and run the following SQL queries to create the *diasporadb* database and *diasporauser* user: 
 <pre> 
 CREATE DATABASE diasporadb CHARACTER SET utf8; 

 CREATE USER 'diasporauser'@'127.0.0.1' IDENTIFIED BY 'SuperSecretPassword'; 

 GRANT ALL PRIVILEGES ON diasporadb.* TO 'diasporauser'@'127.0.0.1'; 

 flush privileges; 
 exit 
 </pre> 

 --- 

 h1. Install Redis 

 * Install redis 
 <pre> 
 pkg install redis 
 </pre> 

 * Enable and start Redis 
 <pre> 
 echo 'redis_enable="YES"' >> /etc/rc.conf 
 service redis start 
 </pre> 

 h1. Install Node.js 

 * Install Node.js and npm: 
 <pre> 
 pkg install node npm 
 </pre> 

 --- 

 h1. Install Diaspora* 

 * Download Diaspora* as the diaspora user run: 
 <pre> 
 su - diaspora 
 git clone    git://github.com/diaspora/diaspora.git 
 cd diaspora 
 </pre> 

 h2. Configure Diaspora* 

 * Copy the example configuration files 
 <pre> 
 cp config/database.yml.example config/database.yml 
 cp config/diaspora.yml.example config/diaspora.yml 
 </pre> 

 h2. Install With Bundler 

 * Start by setting bundler to use the system nokogiri gem. This is to prevent an error during install: 
 <pre> 
 bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/include/libxml2" 
 </pre>  

 * Install the Ruby libraries required by Diaspora: 
 <pre> 
 bundle install --without test development --path vendor/bundle 
 </pre> 

 h2. Diaspora* Database Setup 

 * Double check that the database.yml looks right: 
 <pre> 
 vi config/database.yml 
 </pre> 

 * Run the following to setup the database: 
 <pre> 
 bundle exec rake db:create db:schema:load 
 </pre> 

 h2. Start Diaspora 

 * Edit the production environment config: 
 <pre> 
 vi config/environments/production.rb 
 </pre> 
 #* And modify the following parameter: 
 <pre> 
 config.assets.compile = true 
 </pre> 

 * Precompile the assets used by Diaspora: 
 <pre> 
 RAILS_ENV=production bundle exec rake assets:precompile 
 </pre> 

 * Start Diaspora: 
 <pre> 
 ./script/server 
 </pre> 

 h1. Install Nginx 

 * Install Nginx with Passenger 
 <pre> 
 portmaster www/nginx www/rubygem-passenger cd /usr/ports/www/nginx 
 make config 
 make install clean 
 </pre> 
 *NOTE*: Make sure to enable [X]PASSENGER when during running @make config@ 

 * Install the nginx configuration Passenger gem: 
 <pre> 
 cd /usr/ports/www/rubygem-passenger 
 make config 
 make install clean 
 </pre> 
 *NOTE*: Make sure to enable (*) NGINX when during the rubygem-passenger configuration running @make config@ 

 h2. Configure Nginx 

 * Create a configuration directory to make managing individual server blocks easier: 
 <pre> 
 mkdir /usr/local/etc/nginx/conf.d 
 </pre> 

 * Configuring Nginx and Passenger, edit the @/usr/local/etc/nginx/nginx.conf@ file: 
 <pre> 
 vi /usr/local/etc/nginx/nginx.conf 
 </pre> 
 #* And add/modify the following 
 <pre> 
 user    www www; 
 worker_processes    4; 
 error_log    /var/log/nginx/error.log notice; 
 pid          /var/run/nginx.pid; 

 events { 
   worker_connections    1024; 
 } 

 http { 
   passenger_root /usr/local/lib/ruby/gems/2.1/gems/passenger-4.0.59; 
   passenger_ruby /usr/local/bin/ruby; 
   passenger_max_pool_size 15; 
   passenger_pool_idle_time 300; 
   #passenger_spawn_method direct; # Uncomment on Ruby 1.8 for ENC to work 

   include         mime.types; 
   default_type    application/octet-stream; 
   sendfile        on; 
   tcp_nopush      on; 
   keepalive_timeout    65; 
   tcp_nodelay          on; 

   # Load config files from the /etc/nginx/conf.d directory 
   include /usr/local/etc/nginx/conf.d/*.conf; 
 } 
 </pre> 
 *NOTE*: The above configuration will set the ruby used by passenger to the system default ruby. 

 * Find the exact ruby version that diaspora will use: 
 <pre> 
 su - diaspora 
 passenger-config --ruby-command 
 </pre> 
 #* Example output: 
 <pre> 
 passenger-config was invoked through the following Ruby interpreter: 
   Command: /usr/local/www/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby 
   Version: ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-freebsd9.3] 
   To use in Apache: PassengerRuby /usr/local/www/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby 
   To use in Nginx : passenger_ruby /usr/local/www/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby 
   To use with Standalone: /usr/local/www/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby /usr/local/www/diaspora/.rvm/gems/ruby-2.1.5@diaspora/gems/passenger-4.0.59/bin/passenger start 
 </pre> 

 * Exit back into Return to the root shell: 
 <pre> 
 exit 
 </pre> 

 h3. Diaspora nginx server block 

 * Create a server block for diaspora 
 <pre> 
 vi /usr/local/etc/nginx/conf.d/diaspora.conf 
 </pre> 
 #* And add the following: 
 <pre> 
 server { 
   listen         80; 
   server_name    diaspora.example.com; 

   passenger_enabled on; 
   passenger_ruby /usr/local/www/diaspora/.rvm/gems/ruby-2.1.5@diaspora/wrappers/ruby; 
   passenger_user               diaspora; 
   passenger_group              diaspora; 

   access_log /var/log/nginx-diaspora.log; 
   root /usr/local/www/diaspora/diaspora/public; 
 } 
 </pre> 

 * Restart nginx: 
 <pre> 
 service nginx restart 
 </pre>

Back