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

5.3k Views Asked by At

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

5

There are 5 best solutions below

0
On BEST ANSWER

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

1
On

Go to :

WebServer Settings -> Conf Editor -> Apache -> /usr/local/apache/conf.d/vhosts/

Search for mydomain.ssl.conf & mydomain.conf and click edit

Search for DocumentRoot and change it

From:

DocumentRoot /home/username/public_html

To:

DocumentRoot /home/username/public_html/public

Don't forget to restart Apache after that.

Done

0
On

if you have access ssh remove public_html folder

rm -rf public_html/

create short cut to public folder (laravel) , we will put laravel in same level public_html

ln -s laravel/public public_html

now its done

0
On

Add this code in .htaccess

RewriteEngine On

RewriteRule ^(.*)$ public/$1 [L]

and copy index.php file to root folder and follow steps https://hellocoding.wordpress.com/2014/05/17/how-to-remove-public-from-url-in-laravel/ https://hdtuto.com/article/laravel-remove-public-from-url-using-htaccess

1
On

You need to do the following thing to point your application without public in the URL:

Rename your server.php to index.php and copy your .htaccess file from public folder and paste it parallel to index.php (which is previously server.php)

And to hide your .env a file you need do add following lines in your .htaccess file

# Disable index view
Options -Indexes

# Hide a specific file
<Files .env>
    Order allow,deny
    Deny from all
</Files>