Skip to content

Set up my own Stream Server

YouPHPTube edited this page Sep 22, 2017 · 29 revisions

There is a video to help you to configure it: https://tutorials.youphptube.com/video/10-min-youphptube-stream-server-installation This video does not include HLS support what is included on this tutorial

1. Get YouPHPTube version 4.1 or greater

For new installations

git clone https://github.com/DanielnetoDotCom/YouPHPTube.git

Tutorial video: https://tutorials.youphptube.com/video/how-to-install-youphptube-in-a-fresh-ubuntu-server

Or if you already have YouPHPTube installed, you just need to update:

git pull

Tutorial Video: https://tutorials.youphptube.com/video/how-to-update-your-youphptube-version

2. Install Nginx and Nginx-RTMP

I have follow this tutorial: https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp and this one https://www.vultr.com/docs/setup-nginx-on-ubuntu-to-stream-live-hls-video But if you do not want to read all of it, here is a nginx rtmp tutorial command compilation also I have added the needed php extension php7.0-xml:

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev php7.0-xml && sudo mkdir ~/build && cd ~/build && sudo git clone git://github.com/arut/nginx-rtmp-module.git && sudo wget http://nginx.org/download/nginx-1.12.0.tar.gz && sudo tar xzf nginx-1.12.0.tar.gz && cd nginx-1.12.0 && sudo ./configure --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-rtmp-module && sudo make && sudo make install && sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /usr/local/nginx/ssl/nginx.key -out /usr/local/nginx/ssl/nginx.crt && sudo /etc/init.d/apache2 restart

3. Enable nginx rtmp statistics and set up RTMP support

Just use the command below and go to step 4

sudo cp ~/build/nginx-rtmp-module/stat.xsl /usr/local/nginx/html && sudo mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old && cd /usr/local/nginx/conf/ && sudo wget https://raw.githubusercontent.com/DanielnetoDotCom/YouPHPTube/master/plugin/Live/install/nginx.conf

Open the config file

sudo nano /usr/local/nginx/conf/nginx.conf

and edit the lines:

on_publish http://[YouPHPTubeURL]/plugin/Live/on_publish.php; on_play http://[YouPHPTubeURL]/plugin/Live/on_play.php; on_record_done http://[YouPHPTubeURL]/plugin/Live/on_record_done.php;

replacing the [YouPHPTubeURL] with your YouPHPTube address

If you finish the above commands just go to step 4 now. Or, if you not, just follow this tutorial: https://helping-squad.com/nginx-rtmp-setup-rtmp-statistics/.

First of all we have to copy the stat.xsl file, that comes with the nginx-rtmp-module sources, to nginx\html.

sudo cp ~/build/nginx-rtmp-module/stat.xsl /usr/local/nginx/html

Then edit again the config file: sudo nano /usr/local/nginx/conf/nginx.conf add te sections rtmp stat and rtmp control on your file, after this your server section should looks like this.

server {
	listen       81;
	server_name  localhost;
	location / {
		root   html;
		index  index.html index.htm;
	}

	# rtmp stat
	location /stat {
		rtmp_stat all;
		rtmp_stat_stylesheet stat.xsl;
	}
	location /stat.xsl {
		root html;
	}
	# rtmp control
	location /control {
		rtmp_control all;
	}

	error_page   500 502 503 504  /50x.html;
	location = /50x.html {
		root   html;
	}
}

To set up RTMP support you need to add rtmp{} section to nginx.conf (can be found in PREFIX/conf/nginx.conf). Stock nginx.conf contains only http{} section.

sudo nano /usr/local/nginx/conf/nginx.conf

append the following code at the end of the file

rtmp {
    server {
         listen 1935;
         chunk_size 4096;

         application live {
                 live on;
                 record off;                    
                 on_publish http://[Your.YouPHPTube.url]/plugin/Live/on_publish.php;
         }
    }
 }

I also change the default listen HTTP port, 80 to 81 because, in my case, Nginx is on the same server as Apache.

4. Install Live Plugin and Live Chat plugin

Go to menu->plugins and turn on the switch for Live and Live Chat

Plugin Manager

5. Setup variables on Plugin manager

On the same screen as you turn on the switch click on the edit button of the Live Plugin. On the demo site we use this code:

{"button_title":"LIVE","server":"rtmp://[nigix-server]/live","playerServer":"https://[nigix-server]:444/live","stats":"http://[nigix-server]:81/stats"}

Click on the install database button

What those variables means:

server = Where your stream will be submited, usually it is used in the publisher software

playerServer = can be different or the same as server variable. It is in case you need to encode the incoming stream and send a different stream to the players

stats = it is the stats of Nginx-RTMP, this tutorial helps: https://helping-squad.com/nginx-rtmp-setup-rtmp-statistics/

6. Make the chat-server.php run

Open an terminal from your webserver and type this command:

nohup php /[path-to-YouPHPTube]/plugin/LiveChat/chat-server.php &

and press Ctrl+C

7. Start Nginx

sudo /usr/local/nginx/sbin/nginx

8. Test RTMP module on http://[your address]:[81]/stats

port is optional, in my case Nginx is on the same server as apache.

9. in case you use a HTTPS connnection you may need to Enable secure WebSocket

sudo nano /etc/apache2/mods-available/proxy.conf

Make the file looks like this

<IfModule mod_proxy.c>
        ProxyPass /wss/ ws://127.0.0.1:8888/
</IfModule>

restart Apache

/etc/init.d/apache2 restart

Clone this wiki locally