{"id":20,"date":"2020-09-27T21:15:07","date_gmt":"2020-09-27T21:15:07","guid":{"rendered":"http:\/\/blog.prestigecode.com\/?p=20"},"modified":"2020-09-27T21:15:07","modified_gmt":"2020-09-27T21:15:07","slug":"vhosts-and-the-second-laravel-application","status":"publish","type":"post","link":"https:\/\/blog.prestigecode.com\/index.php\/2020\/09\/27\/vhosts-and-the-second-laravel-application\/","title":{"rendered":"Vhosts and the second Laravel application"},"content":{"rendered":"\n<h2>Preface:<\/h2>\n\n\n\n<p>So today I decided to resume my work on trying to add this second &#8220;API.&#8221; I call it that since this will be used mostly with my other applications as a way to connect and share data across them. Anyways, I wanted to take advantage of this new authentication scaffolding that was released with Laravel 8.0. I ran into a slight problem when I tried to implement this new scaffolding with my previously-outdated-now-updated Laravel application which I use as the main resource hub for Antilobby. Since it&#8217;s already an application that I&#8217;ve worked on a bit, there have been some issues with actually using this new Auth method. So after tinkering with things for a while and accidentally deleting the entire Antilobby database (oops! don&#8217;t run <code>php artisan migrate:fresh<\/code> if you are integrating an existing database with Laravel), I decided that it&#8217;s probably not going to be viable to continue trying to use this new Auth method.<\/p>\n\n\n\n<p>Shortly after some brainstorming, I figured&#8230; well why not just do a fresh install of Laravel and then try again. It&#8217;s likely going to work if I do that. But before I even started doing that, I wanted to see how viable it is to share authentication between multiple Laravel projects. The entire reason why I wanted to deploy this new Auth method is so that I can begin crafting a new secure way to submit data to the Antilobby database. Right now, it&#8217;s rather easy to insert any type of data you want if you had the right information. So before I really begin seriously working on this project, I want to iron out ways that people can &#8220;hack&#8221; this application.<\/p>\n\n\n\n<h2>Auth and MVC<\/h2>\n\n\n\n<p>An area that I wanted to improve on for my Laravel application since I am still learning it, is to really follow the Model logic used in the Model-View-Controller architecture. After I try out this new authentication scaffolding available to me and get it working, I&#8217;ll go ahead and make the new APIs for the Antilobby desktop application. They will support adding data to the Antilobby resource hub so I can really start providing some really cool graphs to you all (or just me ^.^). By creating Models for all of the data I collect, not only will it be easier to use Laravel&#8217;s query builder more effectively, but I&#8217;ll also be able to use these all of the APIs. So as you see, there is a bit of work to do.<\/p>\n\n\n\n<h2>Last but not least&#8230; Vhosts.<\/h2>\n\n\n\n<p>BUT before I could do any of that work, I had to find a way to deploy a second application on the server that hosts <a rel=\"noreferrer noopener\" href=\"https:\/\/prestigecode.com\/api\/antilobby\" target=\"_blank\">The Resource Hub<\/a>. In order for me to keep using just one SSL certificate, I need to also proxy the request through Apache, like I do with Antilobby. I had some issues with this since it gets a tiny bit tricky to not only proxy multiple requests but also direct each different request to the appropriate directory. Both applications are located in different directories and also have specific &#8220;public&#8221; directories within the application itself that must be the root of the application otherwise, people can find out some sensitive information. It took me a few hours of no luck, looking through Apache mod documentation to find a solution that really solved it the way I wanted it to be done. I had been using subfolder directories to proxy these requests and it got tricky when I needed to detect these subdirectories AFTER going through the Apache server. I came back to it today after being able to have my subconscious work at the solution and, voila. Why not just use a different port? Duh. I knew how to redirect a request using different ports and I was pretty sure it wouldn&#8217;t have any effect on the end result. Made sure the port was accessible, changed the vhost on both servers, saved, rebooted&#8230; tada!<\/p>\n\n\n\n<p>Just one little problem. I ran into a weird redirect that happens if you visit the root proxy directory, it repeats the directory without a slash. <img class=\"wp-image-23\" style=\"width: 150px;\" src=\"https:\/\/gyazo.com\/6d7555de49bce01e044a88d82085198b\" alt=\"\"><\/p>\n\n\n\n<figure class=\"wp-block-video aligncenter\"><video autoplay loop muted src=\"https:\/\/i.gyazo.com\/6d7555de49bce01e044a88d82085198b.mp4\"><\/video><\/figure>\n\n\n\n<p>For now, I won&#8217;t worry about that since it doesn&#8217;t really create a problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Preface: So today I decided to resume my work on trying to add this second &#8220;API.&#8221; I call it that since this will be used mostly with my other applications as a way to connect and share data across them. Anyways, I wanted to take advantage of this new authentication scaffolding that was released with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":10,"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":52,"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/posts\/20\/revisions\/52"}],"wp:attachment":[{"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.prestigecode.com\/index.php\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}