Configure symfony not to consider subfolder as part of the route - php

I have an apache server and my projects are inside /var/www/html/
Inside there I created a new project using composer like composer create-project symfony/website-skeleton myproject.
Then inside my project I ran the command composer require symfony/apache-pack which added an .htaccess file inside public folder containing the default .htaccess of symfony.
When I accessed my server like http://192.168.0.2/myproject I got the folder list that apache serves if it doesn't find an index.php file because it accessed the default symfony folder in /var/www/html/myproject and not the public folder.
So inside the folder /var/www/html/myproject which is a symfony project I added the following .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /myproject/
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
No I when I visit http://192.168.0.2/myproject I get an error that No route found for "GET /myproject/" which means that symfony now considers /myproject as part of a route.
Is there a solution for this. I suggested solution that I got from symfony slack would be to have the project inside another folder and symlink only the public folder.
Something like:
lrwxrwxrwx 1 root root 59 gmponos 9 19:26 myproject -> /home/gmponos/Projects/myproject/public/
This is a solution but I really need to have the whole project under /var/www/html/ and not symlink the public folder.
Also another solution according to the official documentation is editing the apache config and change the document root from /var/www/html/myproject to /var/www/html/myproject/public but I need the configuration to stay inside the project and not change the apache config.
Is there any solution?

Is there any solution?
No Solution for what you are requesting :
You must have the rights to configure Apache to adjust the document root to either :
/var/www/html/myproject,
or /var/www/html/myproject/public
and set according access permissions in apache config file
Putting whole code in code in /var/www/html directory, and give free remote access through Web (Apache) is very risky, for production environments.

Related

laravel New project - getting Index of /name instead of welcome page

I just created a new laravel project on XAMPP using the "composer create-project --prefer-dist laravel/laravel name 5.2.29".
I get a list of files (Index of/) instead of laravel welcome page.
How I can fix this?
XAMPP can't find your index.php file which is inside your public/ directory try to set /public directory as your root directory to do so create a .htaccess in your root folder and add these lines
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Now your web directory points to public
there is 2 options for you to see the wolcome page.
Copy all the files (not folders) from public folder to index folder.
open terminal on this specific folder and write php artisan serve , in this terminal will provide you the link for welcome page.
NB: make sure you'r using latest version of XAMPP
Normal, because the one only directory who should be accessible via url in laravel is public/, so the below url will show laravel's homepage
http://localhost:3000/Application/public
But with Xampp, you can use apache virtualhost's feature to point your-local-domain.dev to C:\Xampp\htdocs\Application\public
Or of course you can use this commande
php artisan serve
So if you are using laragon just like me and you just added the project. What worked for me was simply restarting the laragon server.
If the above doesnt work, just simply switch the root directory settings and switch it back. It should work now
Locate your .conf file inside your /etc/apach2/sites-enabled directory (for example: auto.myapp.test.conf ), open it. Add "/public" at the end of: DocumentRoot and Directory:
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/myapp/public"
ServerName foco.test
ServerAlias *.foco.test
<Directory "C:/laragon/www/myapp/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Finally, restart apache server.

Laravel 5.4 on Heroku. Forbidden You don't have permission to access / on this server

I have deployed my laravel 5.4 app on Heroku. The problem is, I am getting this error message:
Forbidden
You don't have permission to access / on this server
My Procfile:
web: vendor/bin/heroku-php-apache2 public/
Looking into the log, I find that it has been trying 'app/' instead of '/'.
My log, snipped for readability.
2017-12-03T14:18:45.747195+00:00 app[web.1]: [Sun Dec 03 14:18:45.746749 2017] [autoindex:error] [pid 122:tid 140692458305280] [client 10.140.221.43:41026] AH01276: Cannot serve directory /app/: No matching DirectoryIndex (index.php,index.html,index.htm) found, and server-generated directory index forbidden by Options directive
My .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
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]
# Handle Authorization Header
RewriteC
I can't figure out where i might be saying it to look into 'app/' instead of '/'. If that is the cause for this error.
I don't know why the server thinks your root is at /app but this error occurs because of the permission of the public/ directory from which Heroku is supposed to serve your application.
To resolve this issue, simply add the following to the script section of your composer.json
"post-install-cmd": [
"php artisan clear-compiled",
"chmod -R 777 public/"
]
Note the change in permission of the public/ directory.
EDIT:
While you are at it, check your Procfile make sure it is spelled correctly and starts with an uppercase P.
PS: I know some people are really nitpicky and would say the permission is too lax. Yes, I agree with you. You can change it to something else like 775 let's just get the juice flowing.
Inside the Laravel Root folder, make a file called Procfile.
Write the following line inside the Procfile.
web: vendor/bin/heroku-php-nginx public/
Then deploy it again!
Src and more here https://appdividend.com/2018/04/17/how-to-deploy-laravel-project-on-heroku/
Hope this was helpful =)
SOLUTION STEPS:
Clone your project to your PC:
heroku git:clone -a your-app-name
Create a file name: Procfile
Then save following lin of code in this Procfile: web: vendor/bin/heroku-php-apache2 public/
Deploy your project back to heroku using commed:
$ git add .
$ git commit -am "make it better"
$ git push heroku master
I hope now no problem run your Laravel App!
/app is the absolute path on the file system, where you app resides. The error indicates that your Procfile does not actually contain what you claim it does. You probably haven't added and committed it to Git. Apache is trying to serve from the "root" right now, not from the public/ subdirectory.
Create and put this .htaccess file in your laravel installation folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
solution is Here:enter link description here
I was having the same issue today, and have found an easy solution to it. I'm running a Laravel 6 app on Heroku.
The issue started after I setup an HTTPS redirect, by adding an apache configuration file, and loading it using the -C option in the Heroku Procfile:
web: vendor/bin/heroku-php-apache2 -C apache.conf public/
The error I was receiving:
2020-01-13T03:55:29.272349+00:00 app[web.1]: [Mon Jan 13 03:55:29.271704 2020] [autoindex:error] [pid 127:tid 140227477751552] [client 10.213.231.122:26179] AH01276: Cannot serve directory /app/public/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive
So the same issue as you were having. What I found was that when you start apache with a custom configuration on Heroku, it starts looking for an index.html file, instead of an index.php file.
To fix this, I added the following line to my apache configuration file:
DirectoryIndex index.php
This directs apache to look for index.php, and fixes the issue.
I removed the quotation mark that surrounded the text of the procfile file and it works
Edit the Procfile
from
"web: vendor/bin/heroku-php-apache2 public/"
to
web: vendor/bin/heroku-php-apache2 public/
This error persist even though i have followed the answer which is marked correct
(even i have run heroku run bash to ls -l to see the file permission)
but i was still getting this error and may be this is because i was using different local branch rather than the local master branch so my advice is to always deploy from your local master branch and also when i deploy from another branch i get this log when pushing the code to heroku
NOTICE: No Procfile, using 'web: heroku-php-apache2'
I faced the same problem when deploying my Laravel app on Heroku. I tried to change permissions in/of my composer file, but that didn't help. Instead, I added this to my htaccess file:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Pushing this to Heroku fixed the problem.
I created Procfile using echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile command just like the docs told me to, but then it generated the Procfile command inside a quotation mark. That's why, I still get the 403 forbidden error even though I've modified my composer.json file just like the other user suggested to.
So guys, make sure the command inside your Procfile isn't surrounded by quotation mark. Then, modify the composer.json just like the approved answer suggested to and re-deploy your site.
If anyone is still having this issue, ensure that the procfile is named Procfile with the capital P.

Laravel remove public from url

This is my folder structure for Laravel 5.2
-laravel
--app
--bootstrap
--config
...
Under the laravel folder that is root of Laravel, I added an .htaccess file with following code:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Now when I open project in browser I get the error:
Sorry, the page you are looking for could not be found. "NotFoundHttpException in RouteCollection.php line 161:"
I am using XAMPP. Why I am getting this error? How can I remove public from the URL using this method?
You need to point your web server to a public directory instead of project root directory. Use original .htaccess and these Apache settings:
DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">
Restart Apache to make it work.
The best way is to create a virtual host in xampp and set its DocumentRoot to laravel public folder.
Here is a nice tutorial on how to create vhosts in xampp
https://delanomaloney.com/2013/07/10/how-to-set-up-virtual-hosts-using-xampp/
create a folder and name as you want, move all the files inside that folder except public, move the content of public folder to root. After you must edit index.php and change [newFolder] by your news folders name
require __DIR__.'/[newFolder]/bootstrap/autoload.php';
$app = require_once __DIR__.'/[newFolder]/bootstrap/app.php';
•Go to mainproject/public>>
a. .htacess
b. favicon.ico
c. index.php
d. robots.txt
e. web.config
1.cut these 5 files from public folder,and then paste on the main project folder that’s means out side of public folder… mainproject/files
2.Next after paste ,open index.php ,modify
•require __DIR__.'/…/bootstrap/autoload.php'; to
•require __DIR__.'/bootstrap/autoload.php';
modify
$app = require_once DIR.'/../bootstrap/app.php'; to
$app = require_once DIR.'/bootstrap/app.php';
Change your httpd.conf file from
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
to
DocumentRoot "C:/xampp/htdocs/{projectname}/public"
<Directory "C:/xampp/htdocs/{projectname}/public">
restart apache. then you can now access your project in url localhost/

How to run Laravel without Artisan?

I have PHP with Apache2 and I want to run Laravel Framework without Artisan but I can't! Does anyone know how to run Laravel without Artisan?
I've solved the problem. The problem was in my htaccess and in mod_rewrite (Apache2). Now I can connect to my application only by typing localhost/public..
If anyone wants to make the application public, the more easy and fastest way is:
Rename the "server.php" file in root directory, in "index.php"
Move your .htaccess from public folder to root directory
Make your directory accessible to Apache2 (set correct file/folder permissions).
Thanks to all users for help! :)
Important Edit
Consider using Apache Virtual Hosts (pointing the virtual host to the /public Laravel folder) instead of renaming server.php to index.php because by doing this you will need to prefix "public/" when you use the Laravel's asset() function in your views.
When working with other devs, who are using a different configuration, this might be a big problem because they will be able to see the assets while you will not (or viceversa).
I am using xampp in mac
inside htdocs / run following command:
$ laravel new myblog
After successfully creation run following and do following:
sudo chmod -R o+w storage/
Change server.php to index.php (# root directory)
copy .htaccess from public to root directory
(optional) in resources / app.blade.php → Change to
<link href="{{ asset('public/css/app.css') }}" rel="stylesheet">
run following
http://localhost/myblog/
Easy solution without any code alterations
Point your domain to public/ folder of laravel project.
Enjoy!
~OR~
Create .htaccess in project folder and add below code. This code will rewrite domain to public/ folder of your laravel project
RewriteEngine on
RewriteRule ^(.*)?$ ./public/$1
Hope this is helpful.
Laravel framework is such a pain in the ass for startup PHP guys who are not much oriented about what the hell composer is, and where .phar files are coming from and what are they, and why "Artisan" is trying to ruin your PHP life.
Most people are looking for a PHP framework where all you have to do is download, extract and code.
Nevertheless to make things work, you just need to install Laravel through Composer:
composer global require "laravel/installer=~1.1"
Anyway, you can download Composer from http://getcomposer.org/
After you install Laravel through Composer, navigate to your local server's directory. You might want to use "CD" (Change directory) to do this. (I'm speaking of CLI, whether you're in BASH(Linux) or CMD(Windows))
Then create your very first Laravel project by typing this in command line:
laravel new mywebsite1
Replace "mywebsite1" with your first project name.
And there you go, you're ready to hit the Laravel road.
In my case, I'm still using Windows XP in such development and shifts back to Ubuntu Trusty whenever I feel like I want to smell Linux scent.
So Composer installs "Laravel installer" in:
%userprofile%\Application Data\Composer\vendor\bin
So I make a backup copy of this directory so the next time I use Laravel on other unit with no internet connection, I just have to extract it, and run:
laravel new [myprojectname]
within the same directory and copies the resulting folder to my XAMPP's htdocs or WAMP's www folder.
Anyway I'm just sharing my approach for those with no 24/7 internet connection at home :p
After all it's still best for everyone to read the documentation on how to properly install Laravel: http://laravel.com/docs/5.0/installation
For Windows Users Its very easy to change and run laravel projects on your normal project urls :
1. "server.php" to "index.php" .
2. copy ".htaccess" from public to root directory.
there you go with your normal URL .
localhost/project_name
Artisan is simply a command line interface. It is made to do things like create and run migrations and automate building certain objects within your Application, etc. Essentially, it's only made to help facilitate creating and working on your Application, not run it.
If you are having issues actually getting the Application to run, it is likely a problem with either your PHP or Apache, not Artisan.
Just Follow 3 Step ;
Change File Name : change serve.php to index.php inside your Project name folder.
Move .htaccess file Bring ".htaccess" file to main root [inside your Project name folder ].
Restart your local server. Your are just 1 click away . Restart all services of xampp or wamp
Enjoy
For an aternative maybe you can run it under a virtual host. All you need is just create a new virtual host with your project/public directory as a DocumentRoot.
In my case, I am using XAMPP under Mac OS. These are the steps on how to achieve that:
Enable virtual host config
Ensure virtual host config was enabled, else you can enable it through this file: /Applications/XAMPP/xamppfiles/etc/httpd.conf
$ sudo nano /Applications/XAMPP/xamppfiles/etc/httpd.conf
Remove the hash "#" of this following line
# Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
Add a new virtual host
$ sudo nano /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
The add a new virtual host (e.g: newproject.dev)
# Virtual host of newproject.dev
<VirtualHost *:80>
ServerName newproject.dev
DocumentRoot "/Users/your-username/newproject/public"
<Directory "/Users/your-username/newproject/public">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Note: /Users/your-username/newproject/public is the location of your project.
Update your hosts
$ sudo nano /etc/hosts
Add this following setting:
# Host of newproject.dev
127.0.0.1 newproject.dev
Restart your Apache, go to your browser and your project should be available on http://newproject.dev
I got mine to work by adding the following block to my apache vhost conf file
<VirtualHost *:8003>
ServerName myproject
DocumentRoot "/path/to/myproject/public"
</VirtualHost>
and running sudo chown -R daemon storage from my project root
Well , the easy way is
1) create a new folder"Project" and copy all files except public folder content to project folder
2) copy all files of public folder to root
and you can run laravel without artisan.If you rename server.php and copy .htaccess , it may make trigger some error when you try to run auth artisan command.I experienced problem with auth command.
Laravel with Vue.JS
If you are using vue.js with Laravel and your app is not working without php artisan serve, you need to create a virtual host. This is a simple two-step process for windows.
Step 1: Update you hosts file at C:\Windows\System32\drivers\etc with,
127.0.0.1 dev.example #You can rename according to your app
Step 2: Update you vhosts file with,
I am using Apache which is installed in D:\ so my path for vhosts file is at
D:\xampp\apache\conf\extra
<VirtualHost *>
DocumentRoot "D:\xampp\htdocs\example\public" ##Your path
ServerName dev.example ##Your URL according to what you set in hosts file in step 1
<Directory "D:\xampp\htdocs\example\public"> ##Your path
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
That's it, now you can just visit your app at http://dev.example/
Install and setup Laravel on your local (meaning your local machine).
Once done, copy all files to your hosting.
Create a .htaccess file on your Laravel's root directory. This is to access it without the "public" on the URL.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Can't make Laravel 4 to work on localhost

I'm trying Laravel for the first time after reading an announcement of the Laravel4 beta releasing.
I followed these steps I installed composer and laravel with all the dependencies it needed. I put the laravel inside my ~/public_html directory - as I'm used to do it with Codeigniter, but I think something's wrong here.
If I point to the browser to http://localhost/~carlo/laravel-develop/, it just displays the content of the directory.
Then, while on the filesystem I had a laravel-develop/public folder, it didn't appear on the browser.
I've found that changing the .htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
resulted in an error when I try to access the public folder.
The error:
ErrorException: Warning: file_put_contents(/home/carlo/public_html/laravel-develop/app/config/../storage/meta/services.json): failed to open stream: Permission denied in /home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
another one:
/home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
then a long list of errors. The last one is:
require_once('/home/carlo/public_html/laravel-develop/start.php') in /home/carlo/public_html/laravel-develop/public/index.php line 53
Try to change the folder permissions for the storage folder using the terminal:
chmod -R 777 storage
More info on this matter can be found here.
Your errors resulted because laravel couldn't write to the app/storage folder. The rest was just a stack trace. In order to make the storage folder writable, cd into your app folder and then run:
chmod -R 777 storage
Production way, moderate complexity for people not familiar with Unix, but more secure:
Go in super user mode (sudo -s or su).
Create group web (groupadd web)
Add you main user to group web (suppose your user is cool_user, so run usermod -a -G web cool_user)
Add php-fpm or web server user (if php is used as a SAPI module) to web group (for example, on CentOS php-fpm utilize apache user name, so in most cases this will work: usermod -a -G web apache)
Change your project root directory group owner to web recursively (chgrp -R web /path/to/project/root/)
Grant recursively write permission for group (chmod -R g+w /path/to/project/root/
Optionally To allow all newly created by apache (or some other) user files and folders be accessible from your user, make them receive group ownership same as their parent folder by setting groupid bit recursively on your project root directory (chmod -R g+s /path/to/project/root/).
Voila!.
Fast and dirty way, for those who doesn't care about security and want make it works at any cost, not secure:
Go in super user mode (sudo -s or su).
Grant recursively full permission (read, write, execute) for all users (chmod -R o=rwx /path/to/project/root/
In my case I resolved this error by modifying in file /app/config/app.php the default setting:
'url' => 'http://localhost',
to my local custom virtualhost host url:
'url' => 'http://mydomain.local',
This seemed to be THE essential change that resolved the issue (I also chmod'ed the storage folder, as suggested here)
hope this helps some of you..
further to above, if you're using a virtualbox/vagrant VM type environment, then on my Mac I needed to issue the chmod on the host (mac) system but on my Windows box, it was fine issuing the chmod direcly on the VM.
You need to add: Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You need to read the installation documentation:
http://laravel.com/docs/installation#configuration
Pay attention to the bit here:
Laravel requires one set of permissions to be configured - folders within app/storage require write access by the web server.
There is also other stuff thats useful in that document, so make sure you read it all.
I had the same problem, here is how I solve it:
In your httpd-vhosts.conf files you need to add the configurations to your folders, this is what I have in mine
<VirtualHost *:80>
ServerAdmin your#mail.com
DocumentRoot "/home/carlospublic_html"
ServerName carlos.local
<Directory "/home/carlos/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>>
The webroot of your server should point to the /public folder of your Laravel installation. This is where the index.html file recides from where Laravel is initialized.
First, this answer here will help you with permissions. Second, you may need to add RewriteBase ~/carlo/public_html/laravel-develop to your .htaccess since you're running it out of a home directory.
Hey I got this error too and changing the write permissions didn't seem to work either. It turned out I needed to change the User and Group settings in apache's httpd.conf file. Here's a good tutorial for it: Enable Write Permissions for the Native Built-In Apache in Mac OS X Lion
Checking on the Requirement for the LR4, your local server must have these:
PHP >= 5.3.7
MCrypt PHP Extension
Otherwise, will fail. I am facing this trouble also and now looking for an updated PHP and its extension for my XAMPP.
I like this method better than changing permissions to 777.
Set Apache to run as you.
In terminal type id to get uid=123(Myname).
Open /etc/apache2/httpd.conf and edit it to use your username.
<IfModule unixd_module>
User Myname
Group staff
</IfModule>
Back to terminal: sudo apachectl restart
I ran into this problem a few minutes back and using sudo chmod -R 777 storage seemed to help make the storage/meta/services.json writable. Just to add to what everyone has been saying. This worked for me.

Categories