I'm trying to use laravel storage API. I can make directory and save files on storage/app/users/user_id/filename but when i want to use files on web page i get forbidden 403. I made a symbolic link:
ln -s storage/app/users public/users
I checked all permissions and they are fine. I changed all permissions to 777 but nothing changed. Here is my apache configuration for this virtual server:
<VirtualHost *:80>
ServerName kamel.dev
DocumentRoot "/home/morteza/development/repo/kamel/public"
<Directory /home/morteza/development/repo/kamel/public>
AllowOverride All
Options FollowSymlinks
Order allow,deny
Require all granted
Allow from all
</Directory>
</VirtualHost>
Chrome error message when i use files:
GET http://kamel.dev/users/2/phpDiLp1O.jpg 403 (Forbidden)
And this is apache response for calling url directly:
Forbidden
You don't have permission to access /users/2/phpDiLp1O.jpg on this
server.
The problem was in how i made symbol link. Here is create symbolic link command:
cd public
after going to public directory use this:
ln -s ../storage/app/users users
Related
I have a very strange permission problem with my Apache. Let's me explain what happened. We bought AWS EC2 instance and installed there AMI Centos 7 with Webmin image. Our Root path is /home/centos/public_html but unfortunately, we got information on the web 'You don't have permission to access / on this server'. Of course, I change access to the folder and all files, even on 777 and owner 'centos' user. Apache user is part of centos group. When I checked log file I got
[core:error] [pid 3872] (13)Permission denied: [client X.X.X.X:60088] AH00035:
access to / denied (filesystem path '/home/centos/public_html')
because search permissions are missing on a component of the path
On the public_html folder, we have default index.php to show us configuration of PHP and is not working.
<?php
phpinfo();
?>
Our http.conf looks like that:
User apache
Group apache
<VirtualHost *:80>
DocumentRoot /home/centos/public_html
ServerName our_domain
ServerAlias *.our_domain
<Directory /home/centos/public_html>
Options Indexes FollowSymLinks
DirectoryIndex index.php index.html welcome.php
allow from all
AllowOverride All
Require all granted
AddType application/x-httpd-php .php
</Directory>
</VirtualHost>
Following this suggestion Apache - Permissions are missing on a component of the path
I had run command:
sudo chcon -R --type=httpd_sys_rw_content_t /home/centos/public_html/
and nothing, any ideas, thank you in advance for any suggestions.
I have installed Apache version 2.4.29-1 in Manjaro Linux. The document root is /srv/http where apache properly displays files. But I don't like the idea of coding into the root user's directory of my system, so I want to keep the code in /home/aditya/Prog/PHP
I have set apache to access the directory by adding following lines into /etc/httpd/conf/httpd.conf
<Directory /home/aditya/Prog/PHP>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all
</Directory>
Also, I have added a link to this directory in /srv/http
sudo ln -s /home/aditya/Prog/PHP/ PHP #in /srv/http
But when I try to access localhost/PHP, I get
Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
localhost
Apache/2.4.29 (Unix) PHP/7.2.3
The permissions of /home/aditya/Prog/PHP and the test file inside are
drwxrwxrwx PHP
-rwxrwxrwx test.php
What else do I need to do?
You also need to change the DocumentRoot setting in your httpd.conf file.
Look for DocumentRoot and set the path to /your/path/to/project.
Apache2 site specific config files are kept in /etc/apache2/sites-available/. If you only want to apply config settings for a specific site.
I am pretty new in PHP and moreover in Laravel and I am pretty desperate trying to deploy a Laravel 5.4 application that works fine on my local environment on my Linux remote server.
So I think that it is something related to virtual host configuration or something like this (maybe also something related to the .htaccess file)
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
All works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I have not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
So I think that it depend by the fact that in this remote server I can't use a virtual host that simulate a domain (as I have on my local environment), but I am not sure about it.
What can I do to solve the situation? Do you think that using a effective domain (something like: www.myregistration.com) that points to this directory of my remote server http://89.36.211.48/HotelRegistration/public/ I can solve this problem?
You need to configure your domain in your server and need to reconfigure the apache. I'm considering you are having apache2 server so here you can do:
Step 1 Go to the apache2 folder cd /etc/apache2
Step 2 You can see sites-available folder go inside it cd sites-available
Step 3 Make a new file name it laravel.dev.conf
Step 4 Write down the following sudo nano laravel.dev.conf
Step 5 Write down the following option:
<VirtualHost *:80>
ServerAdmin webmaster#laravel.dev
ServerName laravel.dev
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/laravel.dev/public/
ErrorLog /var/www/html/laravel.dev/logs/error.log
CustomLog /var/www/html/laravel.dev/logs/access.log combined
<Directory /var/www/html/laravel.dev/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Step 6 Now go to this folder/create a new one cd /var/www/html/laravel.dev
Step 7 Copy/Install your laravel application here.
Step 8 Now you can enable your site by typing sudo a2ensite laravel.dev.conf
Step 9 Now restart the apache2 sudo service apache2 restart
Now you can have proper access to your domain. Hope this helps.
Since you are using XAMPP
Add the following into your VirtualHost Directive:
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
Your final VirtualHost Directive should look like:
<VirtualHost *:80>
DocumentRoot "LINUX PATH TO /HotelRegistration/public"
ServerName 89.36.211.48
<Directory "LINUX PATH TO /HotelRegistration/public">
AllowOverride All
</Directory>
</VirtualHost>
After the configuration changes, restart Apache then you are good to go.
I have Laravel project and can run it with
php artisan serve
I am executing this command inside D:\Users\Dims\Design\MyApplication directory. After that I can see site on http://localhost:8000 and can navigate it, although slow.
Now I am configuring the same place to serve by apache:
<VirtualHost *:80>
ServerAdmin webmaster#myapplication.app
DocumentRoot "D:\Users\Dims\Design\MyApplication\public"
ServerName myapplication.app
ErrorLog "logs/myapplication-error.log"
CustomLog "logs/myapplication-access.log" common
<Directory />
AllowOverride none
Require all granted
DirectoryIndex index.php
</Directory>
</VirtualHost>
Not, that I pointed application not to the root of the project, but to the public directory. This makes me able to open home page of the site, but clicking any links causes error 404.
If I serve
DocumentRoot "D:\Users\Dims\Design\MyApplication"
with Apache, I am unable to see home page at all, saying 403 forbidden. This probably because this directory has no index.php.
So, is it possible to serve Laravel project with Apache?
Yes, it's absolutely possible to serve Laravel applications with Apache. To debug why your links are producing 404 errors, you'll have to provide more information about the URLs these links point to. It's best to always use Laravel's url(), secure_url() or route() helper functions when printing URLs. Also confirm that the Apache module mod_rewrite is enabled (Laravel Installation: Web Server Configuration)
Set up the apache server host file as shown below:
<VirtualHost *:80>
ServerAdmin user#email.com
DocumentRoot D:\Users\Dims\Design\MyApplication\public
ServerName exampledomain.com
ServerAlias www.exampledomain.com
ErrorLog "C:/some_dir/example.error.log"
CustomLog "C:/some_dir/example.access.log" combined
<Directory "D:\Users\Dims\Design\MyApplication\public">
Options -Indexes
DirectoryIndex index.php index.html
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Now that you have set the server name to exampledomain.com you also need to set up the hosts(DNS) file in windows so that you can type in exampledomain.com in your browser and access your laravel project.
Editing the hosts file:
Please follow the steps below:
Press the Windows key.
Type Notepad in the search field.
In the search results, right-click Notepad and select Run as
administrator.
From Notepad, open the following file:
c:\Windows\System32\Drivers\etc\hosts
Make the following changes to the file.
At the end of the file add the following line:
127.0.0.1 exampledomain.com www.exampledomain.com
Click File > Save to save your changes.
What we did here was to tell windows that when we try to access exampledomain.com or www.exampledomain.com do not try to find the server over the internet but take the request to the local machine itself(127.0.0.1) which will in return serve your laravel project.
You can also find one another method here at wikihow -> http://www.wikihow.com/Install-Laravel-Framework-in-Windows
If after configuring the virtualhost you're still unable visit your laravel app, but it works fine with artisan serve, check your apache php version:
Check /etc/apache2/mods-enabled and if the php module is lower than the one required in laravel specifications, update it. In my case:
$ a2dismod php7.0
$ a2enmod php7.2
$ service apache2 reload
Solution found at: https://laracasts.com/discuss/channels/laravel/unexpected-illuminatesupportarrphp-on-line-388
I have a PHP project into a local directory (/home/user/myproject) outside /var/www/html (I'm using Apache2 within Ubuntu). To add that directory as another web root I added:
Alias /myproject /home/user/myproject
<Directory /project>
Order allow,deny
Allow from all
</Directory>
into the apache2.conf file and restarted the server. However, when I try to access the project from the browser with localhost/project I get the 403 Forbidden error.
Am I missing something with the apache configuration?