<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matteo Virgilio on Medium]]></title>
        <description><![CDATA[Stories by Matteo Virgilio on Medium]]></description>
        <link>https://medium.com/@matteovirgilio?source=rss-4fafd3a3d01e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2wRblgzD68aAwEdfduLavQ.jpeg</url>
            <title>Stories by Matteo Virgilio on Medium</title>
            <link>https://medium.com/@matteovirgilio?source=rss-4fafd3a3d01e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:49:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matteovirgilio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Laravel 5 — How to change the public folder and secure private files on shared hosting]]></title>
            <link>https://medium.com/@matteovirgilio/laravel-5-how-to-change-the-public-folder-and-secure-private-files-on-shared-hosting-a8e2e5b9b25f?source=rss-4fafd3a3d01e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8e2e5b9b25f</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[web]]></category>
            <dc:creator><![CDATA[Matteo Virgilio]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 22:00:23 GMT</pubDate>
            <atom:updated>2018-12-02T22:00:23.460Z</atom:updated>
            <content:encoded><![CDATA[<h3>Laravel 5 — How to change the public folder and secure private files on shared hosting</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-vJQqeCmpw-kghDFX8yJw.png" /></figure><p>From time to time it happens that you need to deploy Laravel on a shared hosting service. Most of those free or low-cost services do not allow you to change the root folder of your website to the Laravel’s ‘<em>public</em>’ directory (see <a href="https://laravel.com/docs/5.7/structure">here</a> for a reference on Laravel’s directory structure). In those cases, your Laravel application can be reached by pointing your browser to <a href="http://www.yourdomain.com/public">www.yourdomain.com/public</a> but this will leave you with that annoying ‘public’ string in the URL and, most importantly, with security threats due to private files being accessible from outside.</p><p>For this reason, I introduce you a simple configuration that can help you to keep things cleaner and safer without the need of changing any server/virtual host setting. Let us see how to do it step by step (please consider to backup your current website in order to recover in case of need).</p><p><strong>STEP 1</strong></p><p>Add ‘<em>Options -Indexes’ </em>(without quotes)<em> </em>at the end of the .htaccess file in your root folder.</p><p><strong>STEP 2</strong></p><p>Create the <em>‘private’ </em>folder inside the project root.</p><p><strong>STEP 3</strong></p><p>Copy all non-public files and folders inside <em>private</em> folder (e.g. app, bootstrap, config, database, .env, artisan, etc etc…).</p><p><strong>STEP 4</strong></p><p>Copy all files and folders contained inside the <em>public</em> folder to your project root. As a consequence, the <em>public </em>folder will be empty and can be deleted safely.</p><p><strong>STEP 5</strong></p><p>Modify (or create) an <em>.htaccess</em> file inside your <em>private</em> folder so that it looks like the following snippet:</p><pre>Options -Indexes<br>ErrorDocument 403 “Unauthorized”<br>deny from all</pre><p>Please notice this is an important step as it will ensure that your <em>private</em> folder is <strong>really</strong> private and cannot be accessed from outside! Any request directed to www.yourdomain.com/private/* will return a proper <strong>403 Unauthorized</strong> HTTP code to mark the resource as not accessible.</p><p><strong>STEP 6</strong></p><p>Modify the <em>index.php</em> file (it is located in your root) and replace ‘..’ (double dot) with <em>private. </em>See the following example (please adapt it to your case, if needed):</p><pre>&lt;?php</pre><pre>/**<br> * Laravel - A PHP Framework For Web Artisans<br> *<br> * <a href="http://twitter.com/package">@package</a>  Laravel<br> * <a href="http://twitter.com/author">@author</a>   Taylor Otwell &lt;<a href="/service/mailto:taylor@laravel.com">taylor@laravel.com</a>&gt;<br> */</pre><pre>define(&#39;LARAVEL_START&#39;, microtime(true));</pre><pre>/*<br>|--------------------------------------------------------------------------<br>| Register The Auto Loader<br>|--------------------------------------------------------------------------<br>|<br>| Composer provides a convenient, automatically generated class loader for<br>| our application. We just need to utilize it! We&#39;ll simply require it<br>| into the script here so that we don&#39;t have to worry about manual<br>| loading any of our classes later on. It feels great to relax.<br>|<br>*/</pre><pre>require __DIR__.&#39;/private/vendor/autoload.php&#39;;</pre><pre>/*<br>|--------------------------------------------------------------------------<br>| Turn On The Lights<br>|--------------------------------------------------------------------------<br>|<br>| We need to illuminate PHP development, so let us turn on the lights.<br>| This bootstraps the framework and gets it ready for use, then it<br>| will load up this application so that we can run it and send<br>| the responses back to the browser and delight our users.<br>|<br>*/</pre><pre>$app = require_once __DIR__.&#39;/private/bootstrap/app.php&#39;;</pre><pre>/*<br>|--------------------------------------------------------------------------<br>| Run The Application<br>|--------------------------------------------------------------------------<br>|<br>| Once we have the application, we can handle the incoming request<br>| through the kernel, and send the associated response back to<br>| the client&#39;s browser allowing them to enjoy the creative<br>| and wonderful application we have prepared for them.<br>|<br>*/</pre><pre>$kernel = $app-&gt;make(Illuminate\Contracts\Http\Kernel::class);</pre><pre>$response = $kernel-&gt;handle(<br>    $request = Illuminate\Http\Request::capture()<br>);</pre><pre>$response-&gt;send();</pre><pre>$kernel-&gt;terminate($request, $response);</pre><p><strong>STEP 7</strong></p><p>Modify your <em>server.php</em> file (at this point it should be located inside the <em>private</em> folder) so that it looks like the following (please adapt it if needed):</p><pre>&lt;?php</pre><pre>/**<br> * Laravel - A PHP Framework For Web Artisans<br> *<br> * <a href="http://twitter.com/package">@package</a>  Laravel<br> * <a href="http://twitter.com/author">@author</a>   Taylor Otwell &lt;<a href="/service/mailto:taylor@laravel.com">taylor@laravel.com</a>&gt;<br> */</pre><pre>$uri = urldecode(<br>    parse_url(https://medium.com/$_SERVER[&#39;REQUEST_URI&#39;],%20PHP_URL_PATH)<br>);</pre><pre>// This file allows us to emulate Apache&#39;s &quot;mod_rewrite&quot; functionality from the<br>// built-in PHP web server. This provides a convenient way to test a Laravel<br>// application without having installed a &quot;real&quot; web server software here.<br>if ($uri !== &#39;/&#39; &amp;&amp; file_exists(__DIR__.&#39;/..&#39;.$uri)) {<br>    return false;<br>}</pre><pre>require_once __DIR__.&#39;/../index.php&#39;;</pre><p>You should end up with a folder tree similar to the following one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*r1yY0EhHPNZZKWHIQNVdKQ.png" /><figcaption>Resulting folder tree</figcaption></figure><p>where <em>private</em> contains everything that should <strong>not</strong> be accessed from outside, while in the root you can put all the public folders and assets (images, static files, scripts, etc…).</p><p>Finally point your browser to <a href="http://www.yourdomain.com/"><em>www.yourdomain.com</em></a> and observe your web application up and running as usual, hopefully :)</p><p>Hope this helps you ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8e2e5b9b25f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>