Search code examples
phplaravel.htaccessnginxcentos-web-panel

how can i use laravel website in CWP (Centos-Web-Panel). without public folder in url?


hi, I want to change the root directory of my website which the server panel is CWP centos-web-panel. i find a solution that says change DocumentRootand directory in httpd.conf but I can't change that because a lot of my website using this server. I want to change the root folder in one of my websites. also, I find another solution which said edit the file.

# nano /etc/httpd/conf.d/your_site.conf

and add this code to the file

<VirtualHost *:80>
DocumentRoot /var/www/html/your_site/public
ServerName your_domain

<Directory /var/www/html/your_site/>
AllowOverride All
</Directory>
</VirtualHost>

but not working. how I can do that? are any solution for that or with .htaccess or own laravel template?

so i want to change /public_html/ to /public_html/public/ in centos-web-panel i using Nginx


Solution

  • I prefer this answer. which is more secure. and no need to redirect. create a folder in the public_html maybe foldername then move all of files and folders from the public_html to the foldername after that move all files and folders from public laravel folder to public_html open index.php and edit that like this.

    require __DIR__.'/../vendor/autoload.php';
    $app = require_once __DIR__.'/../bootstrap/app.php';
    

    to

    require __DIR__.'/foldername/vendor/autoload.php';
    $app = require_once __DIR__.'/foldername/bootstrap/app.php';
    

    then hide .env file with .htaccess

    Finish