1 00:00:04,620 --> 00:00:10,800 Up to now we've dealt with and configured in genetics to serve static files of various types leaving 2 00:00:10,800 --> 00:00:16,470 the rendering of that file to be handled by the client or browser based on its content type or MIME 3 00:00:16,470 --> 00:00:17,430 type. 4 00:00:17,470 --> 00:00:23,520 Now while serving static files is great a critical part of most web servers is the ability to serve 5 00:00:23,550 --> 00:00:29,050 dynamic content that's been generated from a server side language such as P. HP. 6 00:00:29,100 --> 00:00:33,870 If you recall from the first section of this course I mentioned that engine X isn't able to embed its 7 00:00:33,870 --> 00:00:41,430 server side language processors so instead then we'll configure a standalone BHB service namely p p 8 00:00:41,430 --> 00:00:48,180 if P. M. to which engine X will pass the request for processing and then upon receiving the response 9 00:00:48,360 --> 00:00:52,380 typically has h.t. amelle return there to the client. 10 00:00:52,380 --> 00:00:56,060 This is essentially engine X functioning as a reverse proxy server. 11 00:00:56,160 --> 00:01:00,960 One of the strong points but we'll dig into that specific topic later on in the course. 12 00:01:00,960 --> 00:01:04,950 Step one then is to actually install the page b f P. M. service. 13 00:01:05,100 --> 00:01:08,170 We can safely use our package manager to do this. 14 00:01:08,220 --> 00:01:10,290 So again UPDATE AP t.. 15 00:01:10,290 --> 00:01:11,770 Just good practice. 16 00:01:12,950 --> 00:01:21,860 And once that's done run apt get install the HP F. P. M. which will install the latest stable release 17 00:01:21,920 --> 00:01:30,860 of BHP fbm available to a peaty which we can see here happens to be BHB seven point one confirm. 18 00:01:30,860 --> 00:01:34,650 Fast forward through this and all done now. 19 00:01:34,670 --> 00:01:41,450 As with most services we install using a p t p s p f P. M. is very conveniently already configured as 20 00:01:41,450 --> 00:01:43,080 a system D service. 21 00:01:43,130 --> 00:01:49,980 Same as we've done for engine X which we can see happened year as Patch B seven point one dash F. P. 22 00:01:49,980 --> 00:01:50,670 M.. 23 00:01:51,020 --> 00:01:53,880 Not just pitch b f be m as we installed it. 24 00:01:54,200 --> 00:01:59,690 This version number being a common naming convention of BHB just in order to have multiple versions 25 00:01:59,690 --> 00:02:00,980 in use at once. 26 00:02:00,980 --> 00:02:04,390 Should that be a requirement for development or testing. 27 00:02:04,430 --> 00:02:12,380 We can confirm that the service exists by listing all the system D services system C T L list units 28 00:02:12,710 --> 00:02:18,580 filtering the results with grep for anything containing be and there we have it. 29 00:02:18,620 --> 00:02:22,350 As expect it be B seven point one f P. M.. 30 00:02:22,700 --> 00:02:28,420 Check the status of our newbie HP Service System C T L status. 31 00:02:28,480 --> 00:02:36,140 B seven point one dash F be M which is already running a single master process and two workers. 32 00:02:36,290 --> 00:02:42,770 So with B F be m running and ready to process page B requests Let's head over to engine next hour conf 33 00:02:42,800 --> 00:02:47,270 and configure the passing of our appear to be files to this service. 34 00:02:47,270 --> 00:02:51,460 First addition to this file is the inclusion of the index directive. 35 00:02:51,710 --> 00:02:57,950 This being a standard directive which tells engine X which file to load if the request point to a directory 36 00:02:58,450 --> 00:03:02,690 the default so the current value being indexed to HD moul. 37 00:03:02,900 --> 00:03:10,770 Hence why when we request our domain slash indexed or HDMI loads route Plus this index value. 38 00:03:11,060 --> 00:03:12,570 This like the try files. 39 00:03:12,580 --> 00:03:15,930 DirecTV can take multiple arguments in order of importance. 40 00:03:15,980 --> 00:03:22,670 So with the inclusion of BHB we'll typically want to serve index Dogpatch P first if it exists in a 41 00:03:22,670 --> 00:03:24,750 directory and if not. 42 00:03:24,750 --> 00:03:28,900 Secondly look for indexed or h.t. amelle the default. 43 00:03:28,910 --> 00:03:34,520 This by no means being a hard and fast rule but the most likely configuration when dealing with a to 44 00:03:34,520 --> 00:03:36,430 be based project. 45 00:03:36,470 --> 00:03:44,300 Next I'll get rid of this location create a new one for Slash So a prefix match for anything in which 46 00:03:44,300 --> 00:03:49,670 we're going to try it with try files the request that you are by then. 47 00:03:49,700 --> 00:03:56,420 Alternatively the requested you are I with an add a trailing slash in case it maps to a directory with 48 00:03:56,450 --> 00:04:00,110 either indexed of BHB or indexed dot aged here Mel. 49 00:04:00,140 --> 00:04:06,920 And finally if none of these exist go back to the default engine next foro for which we can write with 50 00:04:07,040 --> 00:04:09,210 equals forro for. 51 00:04:09,440 --> 00:04:13,250 So this location will take care of any requests for static content. 52 00:04:13,490 --> 00:04:19,580 Meaning that in a second location block using a regular expression match so it will take priority over 53 00:04:19,580 --> 00:04:20,920 this prefix match. 54 00:04:21,110 --> 00:04:27,410 We can match anything ending in dot BHB like so in order to pass a 2p edge. 55 00:04:27,410 --> 00:04:28,700 P if P. M.. 56 00:04:29,420 --> 00:04:30,140 Which will do. 57 00:04:30,140 --> 00:04:33,450 By means of the fast CGI protocol. 58 00:04:33,590 --> 00:04:39,800 If you're not familiar with fast CGI I've linked to some information in the list and resources but essentially 59 00:04:39,800 --> 00:04:44,870 it's a protocol like HTP for transferring binary data. 60 00:04:44,930 --> 00:04:49,940 You don't need to understand this but just know that it's how engine X will communicate with B. 61 00:04:49,970 --> 00:04:51,270 B F p. m.. 62 00:04:51,380 --> 00:04:54,760 We could have done this using the standard htb Protocol also. 63 00:04:54,860 --> 00:05:00,640 But fast CGI is slightly faster before we pass requests in this location context to be a. 64 00:05:00,680 --> 00:05:05,650 B f be m however we still need to include some other configuration parameters. 65 00:05:05,900 --> 00:05:08,270 Luckily as with our MIME types. 66 00:05:08,270 --> 00:05:14,780 Engine X provides a very good include with fast g.g. I preconfigured you might have spotted it during 67 00:05:14,780 --> 00:05:16,870 the installation but to double check. 68 00:05:16,880 --> 00:05:23,330 It's located at slash ATC slash engine X fast CGI dot conf. 69 00:05:23,570 --> 00:05:29,360 So in the same directory as the engine start con file meaning we can again just reference it relative 70 00:05:29,360 --> 00:05:38,720 to this file fast CGI dot conf then to pass this request to be a b f P. M. using fast e.g. I say FAST 71 00:05:38,740 --> 00:05:47,580 C I underscore pass and what we want to pass this to is a Unix socket created by page pfb M.. 72 00:05:47,690 --> 00:05:54,280 Think of a socket as an HTP port a file on which a service can listen for binary data. 73 00:05:54,310 --> 00:05:57,560 Hence the use of fast CGI as a protocol. 74 00:05:57,620 --> 00:06:03,620 Again understanding the fast CGI protocol and Unix sockets is by no means required for understanding 75 00:06:03,620 --> 00:06:05,890 how to configure BHB within generics. 76 00:06:05,990 --> 00:06:11,240 But it's good to at least get an overall understanding of what's happening and why it's done like this 77 00:06:11,930 --> 00:06:14,450 to indicate that this endpoint is a Unix socket. 78 00:06:14,450 --> 00:06:20,510 Then we can say Unix colon and the location of that socket. 79 00:06:20,510 --> 00:06:27,810 In this case it's going to be located at slash run slash BHB slash BHB seven point one dash. 80 00:06:27,830 --> 00:06:29,800 If B M dot soc. 81 00:06:30,140 --> 00:06:34,460 I'll show you how to find the socket location for your install in a second. 82 00:06:34,460 --> 00:06:40,610 Save this over to the terminal and before we reload this engine XT configuration we can make sure the 83 00:06:40,750 --> 00:06:43,730 HP fbm socket is in fact at that location. 84 00:06:43,730 --> 00:06:47,600 By searching for it I'll use the find command. 85 00:06:47,600 --> 00:06:49,430 Look in the root of this machine. 86 00:06:49,430 --> 00:06:58,700 So searching everything by name and we'll search for any thing ending worth F be M dot shock enter and 87 00:06:58,700 --> 00:07:00,640 found at that exact location. 88 00:07:00,650 --> 00:07:06,820 As I've configured engine X so knowing that's correct reload engine X configuration. 89 00:07:07,280 --> 00:07:12,650 We still don't have any BHB files to test this worth so we'll create a simple test file. 90 00:07:12,650 --> 00:07:16,230 Just write the contents directly to our new page B file. 91 00:07:16,310 --> 00:07:27,860 Make it BHB opening statement calling BHB info close BHB to slash sites slash demo slash info Dogpatch 92 00:07:28,020 --> 00:07:29,010 be. 93 00:07:29,300 --> 00:07:34,070 If you're not familiar with BHB this is just saying start processing the content as patch. 94 00:07:34,070 --> 00:07:41,780 Be here call the BHB info function which is a native P P function for displaying all of page piece configuration 95 00:07:41,780 --> 00:07:47,900 information and stop processing BHB which wasn't really necessary as the file ends here. 96 00:07:47,920 --> 00:07:51,350 Anyway it over to the browser so we can test this. 97 00:07:51,500 --> 00:07:57,620 I'll just reload the demesne without any path and we get that same indexed to htl page from the demo 98 00:07:57,620 --> 00:07:58,790 directory. 99 00:07:58,790 --> 00:08:05,690 This of course being as we've named the BHB file info dot BHP meaning on this root directory request 100 00:08:05,840 --> 00:08:12,590 engineer is first checking for indexed or HP which isn't found then for indexed or HDL and serving the 101 00:08:12,590 --> 00:08:14,280 old demo page. 102 00:08:14,300 --> 00:08:16,990 This request also not containing a BHB extension. 103 00:08:17,000 --> 00:08:19,950 Hence not being matched on the BHB location. 104 00:08:20,780 --> 00:08:23,390 Change this request for info Dogpatch. 105 00:08:23,480 --> 00:08:30,930 However meaning will match on the BHB location and we get this error 5 0 too bad gateway. 106 00:08:31,190 --> 00:08:36,980 This being a prime example of when engine x error logs can really help out check the very last entry 107 00:08:36,980 --> 00:08:45,750 of the error log with tail and N flag one meaning one line of the end of this file var log. 108 00:08:45,770 --> 00:08:52,730 Engine x error log critical error connecting to Unix socket slash run slash B. 109 00:08:52,780 --> 00:08:53,680 B B. 110 00:08:53,690 --> 00:08:54,660 B seven point one. 111 00:08:54,680 --> 00:09:00,350 If B em sock with the reason engine x cannot connect to the socket being permission denied. 112 00:09:00,350 --> 00:09:02,650 A very common situation in this case. 113 00:09:02,780 --> 00:09:07,660 We can very quickly find the reason for this permissions error by checking the user with which the engine 114 00:09:07,660 --> 00:09:11,180 XT process is running the worker process here. 115 00:09:11,280 --> 00:09:20,860 Nobody which is the default for change and X and the p p if P. M. process w w w dashed data. 116 00:09:21,020 --> 00:09:26,430 Meaning this nobody user does not have permission to appear to be fbm socket. 117 00:09:26,510 --> 00:09:31,620 There is of course a number of ways we can solve this including changing the permissions of the socket. 118 00:09:31,700 --> 00:09:39,440 But the most secure and easiest way by far is to configure engine X to run as the same user w w w dash 119 00:09:39,440 --> 00:09:42,330 data in the configuration file. 120 00:09:42,350 --> 00:09:49,900 Simply add in the main context user w w w dashed data safe. 121 00:09:50,590 --> 00:09:52,390 Reload engine x. 122 00:09:53,700 --> 00:10:00,950 Check that process again which is now correctly running as w w w desch Data reload info Dogpatch. 123 00:10:00,960 --> 00:10:03,560 Be in the browser and it works. 124 00:10:03,570 --> 00:10:10,230 We get that full output of the BHB info function meaning engine X received the request matched it on 125 00:10:10,230 --> 00:10:13,200 the BHB location past that to the pier. 126 00:10:13,210 --> 00:10:19,500 B if B MS service where it was processed and passed back to engine X which in turn then served that 127 00:10:19,500 --> 00:10:21,500 processed response to us. 128 00:10:22,340 --> 00:10:28,300 One last point to cover is this index directive with indexed or appear to be as the priority. 129 00:10:28,300 --> 00:10:32,830 Let's create an index stoppage be file in that demo directory again. 130 00:10:32,840 --> 00:10:39,280 I'll write some content directly to at Echo a h one date. 131 00:10:39,590 --> 00:10:47,760 Then as beatch be echo the date function with a format of day of the week L.. 132 00:10:47,870 --> 00:10:49,110 Day of the month. 133 00:10:49,130 --> 00:10:49,590 J. 134 00:10:49,610 --> 00:10:51,870 Capital S and month. 135 00:10:51,950 --> 00:10:52,700 F. 136 00:10:53,190 --> 00:10:53,850 End p. 137 00:10:53,880 --> 00:10:55,200 P processing. 138 00:10:55,410 --> 00:10:57,810 And close that each one statement. 139 00:10:57,810 --> 00:10:59,380 Writing there to slash sites. 140 00:10:59,400 --> 00:11:03,650 Slash demo slash indexed iph be back in the browser. 141 00:11:03,650 --> 00:11:05,540 Remove the request path. 142 00:11:05,670 --> 00:11:12,120 So previously serving indexed old h.t. a email and we get that indexed iph page instead. 143 00:11:12,210 --> 00:11:14,440 Meaning this indexed directive prioritized. 144 00:11:14,450 --> 00:11:21,090 Oh a new page B page over there h.t. a mail one that wraps up the basics of configuring a server side 145 00:11:21,090 --> 00:11:23,450 language process for INJ annexe. 146 00:11:23,520 --> 00:11:27,990 But be sure to check out all the links in the lesson and resources for more advanced configurations 147 00:11:28,020 --> 00:11:29,760 and implementations.