I created Common Helper for Image Upload & Common Trait Function for get Images Full URL from Storage & I tested it in Laravel's default inbuilt server it's 1005 perfectly works.
but after Deployment I can't Display Images. it's show 404 error to me
I shared my Common function of Get Full URL path of Image from storage.
app/Traits>HasProfilePhoto.php file
public function getProfilePhotoUrlAttribute()
{
return $this->profile_photo_path
? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path)
: \URL::to('/').'/adminLTE/dist/img/user-img.png';
}
above function will returns Image's Full URL Path Like."test.com/storage/users/user.png"
using Laravel's Default Inbuilt server it returns Full URL like this. http://localhost:8000/storage/users/user.png & using that path image display perfectly
but after the deployment in local Windows using XAMPP Server, it returns Full URL like this. http://localhost/ProjectFolderName/storage/users/user.png & it's show 404 Not Found
NOTE:- If I use FULL Url like this:- http://localhost/ProjectFolderName/public/storage/users/user.png then image displayed
Please Help me what's my mistake there?
*
**How I deployed my Laravel Project see below:- **
*
root/server.php file renamed with index.php
& root/public/.htaccess file copied at root directory
Rename the server.php file to index.php is not good practice for security reasons as well. So if you need to hide the public path from the URL then create a .htaccess at root level:
<ifmodule mod_rewrite.c>
<ifmodule mod_negotiation.c>
Options -MultiViews
</ifmodule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</ifmodule>
Updated by Harsh Patel:- 8th September 2021
Actually Problem is about defining Virtual Host in Server... I was defined DocumentRoot path & Directory path as like "C:/xampp/htdocs/projectFolderName/ this.
I was identified my mistake in deployment from here medium's Blog
but as per Laravel Documentation , we need to direct all requests to public/index.php in other words Laravel's Public Folder is an Our Server's Root (public_html) folder that's why I need to define DocumentRoot & Directory up to public folder like this C:/xampp/htdocs/projectFolderName/public
We need to define our Laravel Web in Apache Server's Virtual Host Config.
for XAMPP Server
step 1: open C:\xampp\apache\conf\extra path location in XAMPP Server
step 2: Open httpd-vhosts.conf File
step 3: define virtual host rule as like below
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:/xampp/htdocs/projectFolderName/public"
<Directory "C:/xampp/htdocs/projectFolderName/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
IF you faced any problem to define Virtual Host in XAMPP then you can see Full detailed answer about How to define Virtual Host in XAMPP
& If you Use WAMPP Server then you can see Full detailed answers about How to define Virtual Host in WAMPP
Maybe you just need to set your projects URL inside .env to start with http://
APP_URL=http://your-project-url
Without this, images will not have proper URL but when you copy image path and open it inside new tab, image will be available anyway.
Related
Hi I am trying to host bookstack application which is basically a larvel application on a shared hosting, After uploading database dump from local and uploading all the files to public_html/bookstack folder.
Now I am able to visit the webapp at https://example.com/bookstack/public , but I want to host the site at example.com/bookstack only and don't want the "public" in url.
I have two questions,
1) How to achieve it using .htaccess file?
2) Inside the .env file there is an option
# Application URL
# Remove the hash below and set a URL if using BookStack behind
# a proxy, if using a third-party authentication option.
# This must be the root URL that you want to host BookStack on.
# All URL's in BookStack will be generated using this value.
#APP_URL=https://example.com
So if here I put APP_URL as https://example.com/bookstack , and remove the comment, its first giving "403 Forbidden - You don't have permission to access this resource." error and if I visit to https://example.com/bookstack/public it works fine.
Update : So I found this subdirectory setup page in bookstack documentation but it only describe how to setup if I have access of apache, which is not possible in case of shared hosting
Move the .htaccess file in /public to root.
Rename server.php file in root to index.php.
you can dos this
<VirtualHost *:80>
...
# BookStack Configuration
Alias "/bookstack" "/var/www/bookstack/public"
<Directory "/var/www/bookstack/public">
Options FollowSymlinks
AllowOverride None
Require all granted
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
<Directory "/var/www/bookstack">
AllowOverride None
Require all denied
</Directory>
# End BookStack Configuration
...
for more deatail you can see this reference.
Setup Sub Path in BookStack
Thanks
Installed LAMP stack. Right now I've extracted codeigniter files to /var/www/ci
but while running on browser http://localhost/ci/ the welcome page doesn't display.
Finally found the answer. Have to enable the site.
In /etc/apache2/sites-available/000-default.conf file shud modified as follows:
<VirtualHost *:80>
DocumentRoot /var/www/
ServerAdmin webmaster#localhost
<Directory /var/www/ci/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And this worked for me! Thanks all.
If you are using ubuntu 14.04 the web server inside var/www/html, so move your folder into var/www/html/ci.
And open .htaccess file inside ci folder.paste the following code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You can set the base url in /application/config/config.php on line 26.
$config['base_url'] = 'http://localhost/ci/';
If that doesn't solve the problem you have to post more informations.
Fresh codeigniter install?
No third party plugins?
No changes to routes? (in /application/config/routes.php)
No changes to the controller?
No changes to the view?
Do you get errors?
If not check if error reporting is on in the index.php (set it hard to development for testing)
Do you use Rewrite rules in an .htaccess in the /var/www/ci/ folder?
Do you autoload anything? libraries, models, languages, helpers ?
If you can't find anything, set this to 4:
$config['log_threshold'] = 4;
in /application/config/config.php on line 216.
The log file is written to /application/logs/.
Post that log, probably it helps.
I've VPS in OVH and i developped website with j2ee and i associate apache with tomcat using mod_jk.
when i enter url http://ip_of_vps/myapp, i enter to website.
until now it's ok
now i add rewrite for access to website using only ip_of_vps without context (myapp), for this i'm using Rewrite in apache2.config like this :
<virtualhost *:80>
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteRule ^/$ http://ip_of_vps/myapp/ [P,L]
</virtualhost>
And i change All AllowOverride in directory from none to All
when i try to access to http://ip_of_vps, i've apache2 home page.
what i've forgot ?
I'm using ubuntu 14.04 server, apache2, tomcat7.
Off the top of my head, typically you would write
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
ReWriteRule your rule
</IfModule>
so, is mod_rewrite actually loaded?
do you need your RewriteBase to be /myapp/ ?
my suggestion would be to put a .htaccess in your html root directory
with a rule like
RewriteRule ^myapp/(.*)$ $1 [L]
this way you wont need mod_proxy at all
hope this helps
Help please, i am using Laravel4 but for some reason i can not get it to work on my mac at home,i have no problems with the mac at work, either i am missing something obvious or my mac is set up different.
the problem i am having is that i can only get the HomeController To Work if i try to use the Test Controller i get Controller method not found. the whooops error gives Controller Method Not Found
REDIRECT_URL /test
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING
REQUEST_URI /test
SCRIPT_NAME /index.php
PATH_INFO /test
PATH_TRANSLATED redirect
my routes
Route::controller('test', 'TestController');
and my Test Controller
class TestController extends BaseController {
public function getIndex()
{
return View::make('test.index');
}
}
my htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
rewrites are enabled
am i missing the obvious?
thanks for any help
I had a similar situation in my local development environment. The Laravel 4 app that was deployed on my remote server was working perfectly, however I couldn't get it to work on my local machine. The problem was that only the root folder of the app (/public - Home Controller) was accessible and none of my routes were working.
The problem was in the configuration of Apache which was not allowing loading of .htaccess files. My solution was to define a new Directory statement for my sites path as follows:
<Directory "/path/to/your/sites">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
You may insert this in httpd.conf or in any configuration file that is being loaded. If there is already a definition for that path, you should update it accordingly. In my case I added the code above to my httpd-vhosts.conf file along with the virtual host definition:
<VirtualHost *:80>
ServerAdmin your#email.com
DocumentRoot "/path/to/your/sites/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Finally add this line to your /etc/hosts
127.0.0.1 laravel.dev
In this way, you can reach your local environment via this URI: http://laravel.dev
Im having an issue with Laravel's htaccess file on my OSX setup.
I have been running the applications perfectly on WAMP, but when i transferred to my Mac i started to get issues.
the htaccess is default
# Apache configuration file
# http://httpd.apache.org/docs/2.2/mod/quickreference.html
# Note: ".htaccess" files are an overhead for each request. This logic should
# be placed in your Apache config whenever possible.
# http://httpd.apache.org/docs/2.2/howto/htaccess.html
# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I am using V-Hosts to have a XXXXXXX.laravel URL.
Ive added the URL to my config file and left the index blank.
Everytime i visit the homepage XXXXXXX.laravel i get the homepage, but when i navigate to XXXXXXX.laravel/test i get a 404.
If i try XXXXXXX.laravel/index.php/test it works ok.
If i add index.php to the index in the config file, it just appends the index.php to my links.
Any ideas??
Thanks
Adam,
Open Apache httpd.conf and check if you have mod_rewrite turned on
LoadModule rewrite_module modules/mod_rewrite.so
and not turned off like this
#LoadModule rewrite_module modules/mod_rewrite.so
I had the same problem, and solved it by putting rewrite conf in the <Directory /> block of my apache conf file for the virtual host.
I am using Laravel 4.