Install ClipBucket and Nginx on CentOS 7
ClipBucket is a community supported open source video sharing site and management script. In ClipBuckets's first incarnation, it was similar to popular video tube websites. However, after years of development, it has become a robust media platform when compared to paid video/media sharing websites. ClipBucket has the following features:
- Ads manager
- Content authorization
- HLS streaming
- Integration w/ Windows Server Active Directory
- Real-time statistics
- Revenue sharing
- Video on demand (VOD)
Prerequisites
- A CentOS 7 x64 Minimal ISO Library server instance.
- A sudo user.
Update the system
Log in as a regular user who has permission to use the sudo command. Update the system as follows.
sudo yum clean all && sudo yum install deltarpm -y && sudo yum update -y
Add The RPMFusion Repository
Neither the official CentOS 7 x64 or EPEL repositories contain RPMs for FFmpeg (includes FFProbe) and GPAC (includes MP4Box). The RPMFusion repository must be added as it contains the latest 2.8.x build of FFmpeg and latest 0.6.x build of GPAC. Use the command below to add the repository.
sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm -y
Install The Required Backend Multimedia Software For ClipBucket
In order for ClipBucket to display videos that are optimized for the web, several multimedia programs must be installed to automatically convert uploaded videos in the background. Install FFmpeg and MP4Box (part of GPAC) from the REMI repository.
sudo yum install ffmpeg gpac -y
In order to install the latest version of Ruby, the YAML library must be installed first.
sudo yum install libyaml -y
Now, install the latest version current version of Ruby (2.5.x).
sudo rpm -ivh https://github.com/feedforce/ruby-rpm/releases/download/2.5.0/ruby-2.5.0-1.el7.centos.x86_64.rpm
Install the Ruby Gems packaging program.
sudo yum install rubygems -y
Install the FLVTool2 gem.
sudo gem install flvtool2
The ImageMagick, MediaInfo and MPlayer/Mencoder programs need to be installed as well.
sudo yum install ImageMagick mediainfo mplayer -y
Install The Web Server Backend For ClipBucket
Install The Latest MariaDB Database Server Version
CentOS 7 comes with MariaDB version 5.5.x in it's default repository. In order to install the latest available version (10.x.x) of the MariaDB database server, the MariaDB RPM repository must be added.
Use the sed
command to create a custom repo file named MariaDB.repo
in the /etc/yum.repos.d/
directory.
sudo su -c "echo -e '[mariadb]\nname = MariaDB\nbaseurl = http://yum.mariadb.org/10.2/centos7-amd64\ngpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB\ngpgcheck=1' > /etc/yum.repos.d/MariaDB.repo"
Install the MariaDB database server. You will be prompted to import the GPG from MariaDB. Press the "Y
" key and the "Enter
" key to accept it.
sudo yum install MariaDB-server -y
Enable and start the MariaDB database server.
sudo systemctl start mysql
Secure the MariaDB database server. Replace ********
below with a new password for the root MySQL user. This is the equivalent of running the mysql_secure_installation
command without the prompts.
sudo mysql -e "UPDATE mysql.user SET Password=PASSWORD('********') WHERE User='root';DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');DELETE FROM mysql.user WHERE User='';DELETE FROM mysql.db WHERE Db IN('test', 'test\_%');DROP DATABASE test;FLUSH PRIVILEGES"
Back up the original server.cnf
in /etc/my.cnf.d/
.
sudo mv /etc/my.cnf.d/server.cnf /root/server.cnf.original
Create a new server.cnf
file using the echo
command. This config gives true UTF8 support. Be sure to change the default-time-zone
option, to reflect the timezone location of your VPS if you so choose. Modify innodb_buffer_pool_instances
, based on your innodb_buffer_pool_size
, if your database size is larger than 2GB. Example: innodb_buffer_pool_size
= 4GB, change innodb_buffer_pool_instances
to 4, for 1GB a piece. Modify innodb_buffer_pool_size
based on your working dataset. innodb_large_prefix
is used for the Error 1071 workaround. innodb_io_capacity
and innodb_io_capacity_max
are increased from the default since Vultr VPS SSD drives provides two orders of magnitude higher IOPs. Modify key_buffer_size
, if you have a lot of tables using MyISAM.
sudo su -c "echo -e '[mysqld]\nbinlog_format\t\t\t\t\t= mixed\ncharacter-set-client-handshake\t\t\t= FALSE\ncharacter-set-server\t\t\t\t= utf8mb4\ncollation-server\t\t\t\t= utf8mb4_unicode_ci\ndefault-time-zone\t\t\t\t= -05:00\nexpire_logs_days\t\t\t\t= 7\ninit_connect\t\t\t\t\t= 'SET collation_connection = utf8mb4_unicode_ci, NAMES utf8mb4'\ninnodb\t\t\t\t\t\t= FORCE\ninnodb_buffer_pool_instances\t\t\t= 1\ninnodb_buffer_pool_size\t\t\t\t= 256M\ninnodb_file_format\t\t\t\t= barracuda\ninnodb_flush_method\t\t\t\t= O_DIRECT\ninnodb_large_prefix\ninnodb-log-file-size\t\t\t\t= 32M\ninnodb-log-files-in-group\t\t\t= 2\ninnodb_io_capacity\t\t\t\t= 30720\ninnodb_io_capacity_max\t\t\t\t= 40960\ninnodb_lock_wait_timeout\t\t\t= 60\ninteractive_timeout\t\t\t\t= 60\nkey_buffer_size\t\t\t\t\t= 2M\nlc_messages\t\t\t\t\t= en_US\nlc_messages_dir\t\t\t\t\t= /usr/share/mysql\nlog_error\t\t\t\t\t= /var/log/mysql/mysql-error.log\nmax_connections\t\t\t\t\t= 16\nmyisam-recover-options\t\t\t\t= FORCE,BACKUP\nskip_external_locking\nskip-log-bin\nskip_name_resolve\nskip_networking\nslow_query_log\t\t\t\t\t= 1\nslow_query_log_file\t\t\t\t= /var/log/mysql/mysql-slow.log\nsync_binlog\t\t\t\t\t= 1\nsysdate-is-now\t\t\t\t\t= 1\nthread_cache_size\t\t\t\t= 4\nthread_pool_size\t\t\t\t= 2\ntmpdir\t\t\t\t\t\t= /tmp\nwait_timeout\t\t\t\t\t= 60' > /etc/my.cnf.d/server.cnf"
Create a directory named mysql
in the /var/log/
directory where the MariaDB database server logs will reside. Change the user and group ownership for the /var/log/mysql
directory and its files from the root
user/group to the mysql
user/group.
sudo mkdir /var/log/mysql && sudo chown mysql.mysql /var/log/mysql
Restart the MariaDB database server.
sudo systemctl restart mysql
The MariaDB database server is now set up and ready.
Install The PHP-FPM 7.0.x Server Version & Necessary PHP Extensions
In order to process PHP, the PHP-FPM 7.0 daemon must be installed and configured. In order to install a version of PHP-FPM newer than the default 5.4.x, the REMI repo must be installed which contains PHP versions 5.6.x, 7.0.x and 7.1.x.
Install the REMI repo and the necessary PHP modules.
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y && sudo yum install php70-php-cli php70-php-pecl-imagick php70-php-fpm php70-php-mysql php70-php-opcache -y
Make a backup of the php-fpm.conf
file in the /etc/opt/remi/php70/
directory by renaming it to php-fpm.conf.original
.
sudo mv /etc/opt/remi/php70/php-fpm.conf /etc/opt/remi/php70/php-fpm.conf.original
Create a new php-fpm.conf
file by using the echo
command.
sudo su -c "echo -e 'include=/etc/opt/remi/php70/php-fpm.d/*.conf\n[global]\ndaemonize = yes\nemergency_restart_threshold = 2\nemergency_restart_interval = 1m\nerror_log = /var/log/php-fpm/php-fpm-7.0-error.log\npid = /var/run/php-fpm-7.0.pid\nprocess_control_timeout = 10s' > /etc/opt/remi/php70/php-fpm.conf"
Make a backup of the www.conf
file in the /etc/opt/remi/php70/php-fpm.d/
directory by renaming it to www.conf.original
.
sudo mv /etc/opt/remi/php70/php-fpm.d/www.conf /etc/opt/remi/php70/php-fpm.d/www.conf.original
Create a new www.conf
file by using the echo
command.
sudo su -c "echo -e '[www]\ngroup = apache\nlisten = /var/run/php-fpm-7.0.sock\nlisten.backlog = 65536\nlisten.owner = apache\nlisten.group = apache\npm = static\npm.max_children = 2\npm.max_requests = 10240\nuser = apache' > /etc/opt/remi/php70/php-fpm.d/www.conf"
Make a backup of the php.ini
file in the /etc/opt/remi/php70/
directory by renaming it to php.ini.original
.
sudo mv /etc/opt/remi/php70/php.ini /etc/opt/remi/php70/php.ini.original
Create a new php.ini
file by using the echo
command. Change the memory_limit
, post_max_size
and upload_max_filesize
to be slightly larger than the largest file you intend to upload. Change date.timezone
to the timezone of your choosing. I recommend the geographical timezone of your VPS instance.
sudo su -c "echo -e '[PHP]\nallow_url_fopen = On\nalways_populate_raw_post_data = -1\ndisplay_errors = Off\nerror_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT\nexpose_php = Off\nlog_errors = On\nmax_execution_time = 7201\nmemory_limit = 256M\noutput_buffering = 4096\npost_max_size = 256M\nregister_argc_argv = Off\nrequest_order = \"GP\"\nupload_max_filesize = 256M\nvariables_order = \"GPCS\"\n[Date]\ndate.timezone = America/New_York\n[Session]\nsession.cache_limiter =\nsession.gc_divisor = 1000\nsession.hash_bits_per_character = 5\nsession.save_handler = files\nsession.save_path = \"/var/opt/remi/php70/lib/php/session/\"\nurl_rewriter.tags = \"a=href,area=href,frame=src,input=src,form=fakeentry\"' > /etc/opt/remi/php70/php.ini"
Create the php-fpm
directory inside of the /var/log/
directory where the PHP-FPM server logs will reside.
sudo mkdir /var/log/php-fpm/
Enable and start the PHP-FPM server.
sudo systemctl enable php70-php-fpm && sudo systemctl start php70-php-fpm
Install The Web Server Frontend For ClipBucket
###Install & Configure The Nginx Web Server Install the latest version of the Nginx web server.
sudo yum install nginx -y
Make a backup of the nginx.conf
file in the /etc/nginx
directory by renaming it to nginx.conf.original
.
sudo mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.original
Create a new nginx.conf
file by using the echo
command.
sudo su -c "echo -e 'error_log /var/log/nginx/error_log info;\nevents { multi_accept on; worker_connections 1024; }\nhttp {\n\taccess_log none;\n\tcharset utf-8;\n\tclient_body_timeout 10s;\n\tclient_header_timeout 10s;\n\tclient_max_body_size 256M;\n\tdefault_type application/octet-stream;\n\tgzip_comp_level 6;\n\tgzip on;\n\tgzip_proxied any;\n\tgzip_types application/json application/javascript application/x-javascript application/xml application/xml+rss text/css text/javascript text/plain text/xml;\n\tgzip_vary on;\n\tinclude /etc/nginx/mime.types;\n\tinclude /etc/nginx/conf.d/headers.conf;\n\tinclude /etc/nginx/sites-enabled/*.conf;\n\tindex index.html index.php;\n\tkeepalive_timeout 8 8;\n\treset_timedout_connection on;\n\tsend_timeout 2s;\n\tsendfile on;\n\tserver_tokens off;\n\ttcp_nopush on;\n\ttcp_nodelay on;\n\tupstream php-7.0 { server unix:/var/run/php-fpm-7.0.sock; }\n}\nuser apache apache;\nworker_processes auto;' > /etc/nginx/nginx.conf"
Create the site-available
and site-enabled
directories in the /etc/nginx/
directory.
sudo mkdir /etc/nginx/{sites-available,sites-enabled}
Create the deny-log-not-found.conf
, expires.conf
and headers.conf
files in the /etc/nginx/conf.d/
directory. The deny-log-not-found.conf
file prohibits access to hidden files (e.g .htaccess
, .git
and others). The expires.conf
file sets the "Expires" and "Cache-Control" response headers to the max time available for common static files like images and text. The headers.conf
file sets the response headers to prevent MIME-type sniffing, click-jacking and block XSS (cross site scripting) exploits.
sudo su -c "echo -e 'location ~ /\. { deny all; }\nlocation = /(favicon.ico|robots.txt) { log_not_found off; }' > /etc/nginx/conf.d/deny-log-not-found.conf" && sudo su -c "echo -e 'location ~* ^.+\.(atom|bmp|bz2|css|doc|eot|exe|gif|gz|ico|jpeg|jpg|js|mid|midi|mp4|ogg|ogv|otf|pdf|png|ppt|rss|rft|svg|svgz|tar|tgz|ttf|wav|woff|woff2|xls|zip)$ { expires max; log_not_found off; }' > /etc/nginx/conf.d/expires.conf" && sudo su -c "echo -e 'add_header X-Content-Type-Options \"nosniff\";\nadd_header X-Frame-Options \"SAMEORIGIN\";\nadd_header X-Robots-Tag \"noarchive,noodp,noydir\";\nadd_header X-Xss-Protection \"1; mode=block\";' > /etc/nginx/conf.d/headers.conf"
Create the example.com.conf
file in the /etc/nginx/sites-available/
directory which will point to the directory that will contain ClipBucket. Replace all instances of example.com
below with your actual FQDN/domain name.
sudo su -c "echo -e 'server {\n\tinclude /etc/nginx/conf.d/deny-log-not-found.conf;\n\tinclude /etc/nginx/conf.d/expires.conf;\n\tindex index.php;\n\tlocation / {\n\t\ttry_files \$uri \$uri/ /index.php;\n\t\trewrite ^/(.*)v([0-9]+) /watchvideo.php?v=\$2&\$query_string;\n\t\trewrite ^/([a-zA-Z0-9-]+)/?\$ /view_channel.php?uid=\$1&seo_diret=yes;\n\t\t}\n\tlocation ~ \.php\$ { fastcgi_pass php-7.0; include /etc/nginx/fastcgi.conf; }\n\tlocation /categories {\n\t\trewrite ^/categories/?\$ /categories.php;\n\t\t}\n\tlocation /channel {\n\t\trewrite ^/channel/(.*) /view_channel.php?user=\$1;\n\t\t}\n\tlocation /channels {\n\t\trewrite ^/channels/(.)/(.)/(.)/(.)/(.*) /channels.php?cat=\$1&sort=\$3&time=\$4&page=\$5&seo_cat_name=\$2;\n\t\trewrite ^/channels/([0-9]+) /channels.php?page=\$1;\n\t\trewrite ^/channels/?\$ /channels.php;\n\t\t}\n\tlocation /collection {\n\t\trewrite ^/collection/(.)/(.)/(.*) /view_collection.php?cid=\$1&type=\$2&\$query_string;\n\t\t}\n\tlocation /collections {\n\t\trewrite ^/collections/(.)/(.)/(.)/(.)/(.*) /collections.php?cat=\$1&sort=\$3&time=\$4&page=\$5&seo_cat_name=\$2;\n\t\trewrite ^/collections/([0-9]+) /collections.php?page=\$1;\n\t\trewrite ^/collections/?\$ /collections.php;\n\t\t}\n\tlocation /contact {\n\t\trewrite ^/contact/?\$ /contact.php;\n\t\t}\n\tlocation /create_group {\n\t\trewrite ^/create_group /create_group.php;\n\t\t}\n\tlocation /group {\n\t\trewrite ^/group/([a-zA-Z0-9].+) /view_group.php?url=\$1&\$query_string;\n\t\t}\n\tlocation /groups {\n\t\trewrite ^/groups/(.)/(.)/(.)/(.)/(.*) /groups.php?cat=\$1&sort=\$3&time=\$4&page=\$5&seo_cat_name=\$2; rewrite ^/groups/([0-9]+) /groups.php?page=\$1;\n\t\trewrite ^/groups/?\$ /groups.php;\n\t\t}\n\tlocation /item {\n\t\trewrite ^/item/(.)/(.)/(.)/(.) /view_item.php?item=\$3&type=\$1&collection=\$2;\n\t\t}\n\tlocation /members {\n\t\trewrite ^/members/?\$ /channels.php;\n\t\t}\n\tlocation /my_account {\n\t\trewrite ^/my_account /myaccount.php;\n\t\t}\n\tlocation /page {\n\t\trewrite ^/page/([0-9]+)/(.*) /view_page.php?pid=\$1;\n\t\t}\n\tlocation /photo_upload {\n\t\trewrite ^/photo_upload/(.*) /photo_upload.php?collection=\$1;\n\t\trewrite ^/photo_upload/?\$ /photo_upload.php;\n\t\t}\n\tlocation /photos {\n\t\trewrite ^/photos/(.)/(.)/(.)/(.)/(.*) /photos.php?cat=\$1&sort=\$3&time=\$4&page=\$5&seo_cat_name=\$2;\n\t\trewrite ^/photos/([0-9]+) /photos.php?page=\$1;\n\t\trewrite ^/photos/?\$ /photos.php;\n\t\t}\n\tlocation = /rss {\n\t\trewrite ^(.*)\$ /rss.php;\n\t\t}\n\tlocation /rss {\n\t\trewrite ^/rss/([a-zA-Z0-9].+)\$ /rss.php?mode=\$1&\$query_string;\n\t\t}\n\tlocation /search {\n\t\trewrite ^/search/result/?\$ /search_result.php;\n\t\t}\n\tlocation /signup {\n\t\trewrite ^/signup/?\$ /signup.php;\n\t\t}\n\tlocation = /sitemap.xml {\n\t\trewrite ^(.*)\$ /sitemap.php;\n\t\t}\n\tlocation /upload {\n\t\trewrite ^/upload/?\$ /upload.php;\n\t\t}\n\tlocation /user {\n\t\trewrite ^/user/(.*) /view_channel.php?user=\$1;\n\t\t}\n\tlocation /users {\n\t\trewrite ^/users/?\$ /channels.php;\n\t\t}\n\tlocation /video {\n\t\trewrite ^/video/(.)/(.) /watch_video.php?v=\$1&\$query_string; rewrite ^/video/([0-9]+)(.*) /watchvideo.php?v=\$1&\$query_string;\n\t\t}\n\tlocation /videos {\n\t\trewrite ^/videos/(.)/(.)/(.)/(.)/(.*) /videos.php?cat=\$1&sort=\$3&time=\$4&page=\$5&seo_cat_name=\$2;\n\t\trewrite ^/videos/([0-9]+) /videos.php?page=\$1;\n\t\trewrite ^/videos/?\$ /videos.php?\$query_string;\n\t\t}\n\tlocation /view_topic {\n\t\trewrite ^/view_topic/([a-zA-Z0-9].+)tid([0-9]+) /view_topic.php?tid=\$2&\$query_string;\n\t\t}\n\tserver_name example.com www.example.com;\n\troot /var/www/html;\n}' > /etc/nginx/sites-available/example.com.conf"
Create a symlink for the example.com.conf
file, located in the /etc/nginx/sites-available/
directory, in the /etc/nginx/sites-enabled/
directory. Replace example.com
below with your actual FQDN/domain name.
sudo su -c "cd /etc/nginx/sites-enabled && ln -s ../sites-available/example.com.conf ."
Enable and start the PHP-FPM server.
sudo systemctl enable nginx && sudo systemctl start nginx
Nginx is now setup and ready to deliver pages.
Install ClipBucket
Download the latest version of ClipBucket and extract the contents of the upload
directory inside of the ClipBucket tar-gzipped file into the /var/www/html
directory.
sudo su - apache -c "wget -N -P /tmp/ https://github.com/arslancb/clipbucket/archive/4881.tar.gz -q" -s /bin/bash && sudo mkdir -p /var/www/html && sudo chown -R apache.apache /var/www/html && sudo su - apache -c "tar -C /var/www/html -zxf /tmp/4881.tar.gz clipbucket-4881/upload/ --strip-components=2" -s /bin/bash && sudo rm /tmp/4881.tar.gz
Create a database for ClipBucket and user with SELECT
, INSERT
, UPDATE
, DELETE
, CREATE
, DROP
, INDEX
and ALTER
permissions, change ********
to a custom password for the clipbucket_example_com
user and enter the MySQL root password when prompted. Replace all instances of example_com
in the command below with your actual FQDN/domain name.
sudo mysql -u root -p -e "CREATE DATABASE clipbucket_example_com; GRANT ALTER,CREATE,DELETE,DROP,INDEX,INSERT,SELECT,UPDATE ON clipbucket_example_com.* TO clipbucket_example_com_admin@localhost IDENTIFIED BY '********'"
Now, open your browser and enter the server URL, (http://www.example.com
), for your instance. If you getting an Unable to connect
or This site can’t be reached
message, this is because CentOS's default firewall setting disallows incoming connections to the http
port. The following command will open it.
sudo firewall-cmd --permanent --zone=public --add-service=http && sudo firewall-cmd --reload
Refresh the page in your browser and you will see the ClipBucket installation page.
Click the blue Ok, I agree, Now let me Continue!
button to continue to step 2.
Click the blue Continue To Next Step
button to continue to step 3.
Before proceeding to the next step of the installation, make sure that there are green checks against every directory in the list. Click the blue Continue To Next Step
button to continue to step 4.
Input the actual database name in the Database Name
text area. In the Database User
text area, input the actual database user; and in the Database Password
text area, the actual database password. Click the blue Check Connection
to continue to step 5.
Input an admin username, admin password and valid email in the Admin username
, Admin Password
and Admin Email
fields. Click the blue Save and Continue
button to continue to step 6.
Replace the default web site title, web site slogan and website URL. Click the blue Save and Continue
button to continue to step 7.
Click the blue Skip & Finish
button if you don't want to register and proceed to the next step.
On the final page, the installer instructs you to remove the cb_install
directory on the server to complete installation.
Remove the /var/www/html/cb_install
directory as instructed on the last installation page. Navigate back to the SSH client program and use the command below to remove the /var/www/html/cb_install/
directory.
sudo rm -rf /var/www/html/cb_install
Back in the browser, click the red Continue to Admin Area
button to proceed to the login page.
Enter your admin username and password to login.
After logging in, click the General
link in the left menu to expand the accordion. Click the Website Configurations
link and click the Uploading and Conversion Settings
tab. Change the selector for Use Crons
to Yes
, the FFMPEG Path
text area to /usr/bin/ffmpeg
, the PHP Path
text area to /usr/bin/php70
, the MP4Box Path
test area to /usr/bin/MP4Box
and input /usr/bin/mplayer
in the MPlayer Path
text area. Click the blue Update Settings
button to save the changes.
To verify the max size of files that can be uploaded to ClipBucket, click the Tool Box
link, in the left menu, to expand the accordion. Click the Server Modules Info
link. POST MAX SIZE
, UPLOAD MAX FILESIZE
and MEMORY LIMIT
will all have green checks and match the max upload filesize you set in the /etc/opt/remi/php70/php.ini
file and the client_max_body_size
variable in the /etc/nginx/nginx.conf
file.
To verify that changes you made on the Uploading and Conversion Settings
tab, click the Server Conversion Info
link. You will have green checks in the fields for FFMPEG
, PHP CLI
, Media Info
, MP4Box
, ImageMagick
and FFProbe
.
Navigate back to the SSH client program to setup the cron jobs necessary for ClipBucket to convert video in the background.
sudo su -c "echo -e '* * * * * /usr/bin/php70 -q /var/www/html/actions/video_convert.php\n* * * * * /usr/bin/php70 -q /var/www/html/actions/verify_converted_videos.php\n0 0,12,13 * * * /usr/bin/php70 -q /var/www/html/actions/update_cb_stats.php' > /var/spool/cron/apache" -s /bin/bash && sudo chown apache.apache /var/spool/cron/apache
ClipBucket is now ready for video upload and conversion. If you wish to customize it further, refer to the official ClipBucket documentation.