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

久未见 提交于 2019-12-24 07:56:39

问题


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


回答1:


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




回答2:


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>



回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/55037835/how-can-i-use-laravel-website-in-cwp-centos-web-panel-without-public-folder-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!