Project

General

Profile

Support #667

Updated by Daniel Curtis over 8 years ago

This is a guide for setting up FreeSWITCH with Nginx, PostgreSQL, and FusionPBX on FreeBSD 9. 

 h2. Prepare the Environment 

 * Make sure the system is up to date: 
 <pre> 
 pkg update && pkg upgrade && portsnap fetch extract 
 </pre> 

 * Install a few dependencies: 
 <pre> 
 pkg install portmaster screen sox cmake autoconf automake lua51 curl git gmake jpeg ldns libedit binutils freetype2 libtool openssl pcre pkgconf flex speex sqlite3 wget subversion postgresql94-client sofia-sip x264 libvpx opus ffmpeg 

 pkg2ng 
 </pre> 

 h2. Install FreeSWITCH 

 * Make a source directory: 
 <pre> 
 mkdir /usr/local/src 
 </pre> 

 *NOTE*: I could not build FreeSWITCH from ports, so this guide will compile from GitHub. 

 * Clone the latest version of freeswitch: 
 <pre> 
 cd /usr/local/src 
 git clone -b v1.6 https://freeswitch.org/stash/scm/fs/freeswitch.git 
 </pre> 

 * Disable mod_fsv: 
 <pre> 
 cd freeswitch 
 sed -i '' -e 's/applications\/mod_fsv/#applications\/mod_fsv/' modules.conf 
 </pre> 

 * Build and install freeswitch: 
 <pre> 
 ./bootstrap.sh -j 
 ./configure --enable-core-pgsql-support 
 gmake 
 gmake install cd-sounds-install cd-moh-install 
 </pre> 

 * Create the rc script: 
 <pre> 
 vi /usr/local/etc/rc.d/freeswitch 
 </pre> 
 #* And add the following 
 <pre> 
 #!/bin/sh 
 # 
 # PROVIDE: freeswitch 
 # REQUIRE: LOGIN cleanvar 
 # KEYWORD: shutdown 
 # 
 # Add the following lines to /etc/rc.conf to enable freeswitch: 
 # freeswitch_enable:         Set it to "YES" to enable freeswitch. 
 #                            Default is "NO". 
 # freeswitch_flags:          Flags passed to freeswitch-script on startup. 
 #                            Default is "". 
 # 
 . /etc/rc.subr 
 name="freeswitch" 
 rcvar=${name}_enable 
 load_rc_config $name 
 : ${freeswitch_enable="NO"} 
 : ${freeswitch_pidfile="/usr/local/freeswitch/run/freeswitch.pid"} 
 start_cmd=${name}_start 
 stop_cmd=${name}_stop 
 pidfile=${freeswitch_pidfile} 
 freeswitch_start() { 
         /usr/local/freeswitch/bin/freeswitch ${freeswitch_flags} 
         echo -n "Starting FreeSWITCH: " 
 } 
 freeswitch_stop() { 
         /usr/local/freeswitch/bin/freeswitch -stop 
 } 
 run_rc_command "$1" 
 </pre> 

 * Make the script executable: 
 <pre> 
 chmod +x /usr/local/etc/rc.d/freeswitch 
 </pre> 

 * Start and enable freeswitch to start at boot: 
 <pre> 
 echo 'freeswitch_enable="YES"' >> /etc/rc.conf 
 echo 'freeswitch_flags="-nc"' >> /etc/rc.conf 
 service freeswitch start 
 </pre> 
 #* *NOTE*: If your Freeswitch server has a IP address and not behind a NAT router, add the @-nonat@ parameter to the freeswitch_flags. This will disable NAT traversal feature of FreeSWITCH. 

 h2. Install FusionPBX 

 * Install fusionpbx: 
 <pre> 
 portmaster www/fusionpbx 
 </pre> 
 #* *NOTE*: Make sure to enable *[X]PDOPGSQL* while configuring fuzionpbx.  

 h2. Install Nginx 

 * Install Nginx 
 <pre> 
 portmaster www/nginx 
 </pre> 

 * Start and enable nginx at boot: 
 <pre> 
 echo 'nginx_enable="YES"' >> /etc/rc.conf 
 service nginx start 
 </pre> 

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

 * Edit the main nginx config file: 
 <pre> 
 vi /usr/local/etc/nginx/nginx.conf 
 </pre> 
 #* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks: 
 <pre> 
 #user    nobody; 
 worker_processes    1; 
 error_log    /var/log/nginx-error.log; 

 events { 
   worker_connections    1024; 
 } 

 http { 
   include         mime.types; 
   default_type    application/octet-stream; 

   sendfile          on; 
   #tcp_nopush       on; 

   #keepalive_timeout    0; 
   keepalive_timeout    65; 

   #gzip    on; 

   # Load config files from the /etc/nginx/conf.d directory 
   include /usr/local/etc/nginx/conf.d/*.conf; 

 } 
 </pre> 

 * Now create a config for pbx.example.com: 
 <pre> 
 vi /usr/local/etc/nginc/conf.d/pbx.example.com.conf 
 </pre> 
 #* And add the following: 
 <pre> 
 server{ 
       listen 80; 
       server_name pbx.example.com; 

       access_log /var/log/nginx-access.log; 
       error_log /var/log/nginx-error.log; 

       client_max_body_size 10M; 
       client_body_buffer_size 128k; 

       root /usr/local/www/fusionpbx; 

       location / { 
         root /usr/local/www/fusionpbx; 
         index index.php; 
       } 

       location ~ \.php$ { 
           fastcgi_pass unix:/var/run/php-fpm.sock; 
           fastcgi_index index.php; 
           include fastcgi_params; 
           fastcgi_param     SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       } 

       # Disable viewing .htaccess & .htpassword & .db 
       location ~ .htaccess { 
               deny all; 
       } 
       location ~ .htpassword { 
               deny all; 
       } 
       location ~^.+.(db)$ { 
               deny all; 
       } 
 } 
 </pre> 



 h3. Configure PHP 

 * Configure the default PHP settings 
 <pre> 
 cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini 
 </pre> 
 
 * Edit /usr/local/etc/php-fpm.conf: 
 <pre> 
 vi /usr/local/etc/php-fpm.conf 
 </pre> 
 #* Make the following changes: 
 <pre> 
 listen = /var/run/php-fpm.sock 
 listen.owner = www 
 listen.group = www 
 listen.mode = 0666 
 </pre> 

 * Start and enable PHP-FPM at boot: 
 <pre> 
 echo 'php_fpm_enable="YES"' >> /etc/rc.conf 
 service php-fpm start 
 </pre> 

 h2. Setup Database 

 *NOTE*: This guide has an external postgresql server and does not cover setting up the server. 

 * Create the database and user: 
 <pre> 
 su postgres 
 createuser -s -e FusionPBX 
 createdb -O FusionPBX FusionPBX 
 psql -d FusionPBX -U FusionPBX 
 ALTER USER FusionPBX with PASSWORD 'SuperSecretPassword'; 
 </pre> 

 * Then open http://pbx.example.com in a web browser and finish the installation.  

 h2. Resources 

 * http://wiki.fusionpbx.com/index.php?title=FreeBSD_Install 
 * https://freeswitch.org/confluence/display/FREESWITCH/FreeBSD 
 * https://code.google.com/p/libyuv/wiki/GettingStarted

Back