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.
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.
I use the global symfony command to create a project under my ~/tmp/ directory, and aliased it to my /Application/MAMP/htdoc/ Apache Server's webroot.
Surprise, the project was in prod mode. I know it because the underline debug tool known as the "profiler" is missing and all my bugs was non visible, and when I search in app/logs/dev.log, the file is missing too, but there is a app/logs/prod.log.
If I run app/console server:run, the project is in dev mode.
How is that possible ? Maybe all the software installed by MAMP?
open_ssl, mod_fastcgi, mod_perl, mod_ssl, mod_wsgi?
I usually only use the build-in server of PHP to run the project and I never set the prod mode before.
I don't recommend you to change the value of the second argument of AppKernel in web/app.php.
Instead I recommend you to configure in your local MAMP setup to use app_dev.php as the PHP index file, which is what the server:run command does too.
It's due to the .htaccess of the project's webdirectory.
When you browse a Symfony application through Apache, you are in production environment by default, no matter the OS used.
To go in dev mode, open the file web/app.php , find the following line :
$kernel = new AppKernel('prod', false); // Prod env, debug disabled
And change it to :
$kernel = new AppKernel('dev', true); // Dev env, debug enabled
It's the quicker way I know.
Otherwise, I made an override of the default a .htaccess adapted for the dev environment.
It rewrite URLs to the app_dev.php front-controller rather than app.php.
Update
You need to add the following in your apache configuration :
<Directory "path/to/your/project">
DirectoryIndex app_dev.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app_dev.php [QSA,L]
</IfModule>
</Directory>
You should create a vhost to make this configuration specific to your project, not your whole localhost.
I have a legacy PHP application. The root directory looks like this:
.htaccess
index.php
composer.json
composer.lock
Procfile
In my procfile I have this:
web: vendor/bin/heroku-php-apache2 /
And in .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
And in composer.json this:
{
"require" : {
"silex/silex": "~1.1",
"monolog/monolog": "~1.7"
},
"require-dev": {
"heroku/heroku-buildpack-php": "*"
}
}
When I deploy to heroku I get no errors, just a blank screen. I am unable to run the app locally with foreman due to it throwing this error:
This program requires Apache 2.4.10 or newer with mod_proxy
and mod_proxy_fcgi enabled; check your 'httpd' command.
Additionally, I'm getting a 500 server error on the Heroku site.
I'm wondering if I am doing anything that is obviously wrong here. Not very experienced with deploying PHP applications on Heroku so I'm not sure exactly what the deal is. Thanks in advance for the help!
I've just as of right now started to learn Laravel and Composer and I've been following the Basic Routing example I found in Code Bright. I've cloned the Laravel repo, and installed it using Composer as mentioned in the previous Installation section of Code Bright, and am using the Apache config suggested, which is fairly similar to what I would normally use in my other apps using XAMPP, but when I enter in the url to see the route output I get "Whoops, looks like something went wrong".
Step 1
git clone https://github.com/laravel/laravel.git laravel
Step 2
composer install
Step 3
<VirtualHost *:80>
# Host that will serve this project.
ServerName laravel.dev
ServerAlias laravel.dev
# The location of our projects public directory.
DocumentRoot "D:/htdocs/laravel/public"
# Useful logs for debug.
ErrorLog "logs/laravel.dev-error.log"
CustomLog "logs/laravel-access.log" common
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory "D:/htdocs/laravel/public">
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
</VirtualHost>
Step 4
Route::get( 'my/page', function() {
return 'Hello World!';
});
Step 5
http://laravel.dev/my/page
I'm running off of Windows, with PHP version 5.5.11 via XAMPP, most recent Composer is installed via Windows installer so on PATH, and Laravel is installed globally.
Got it! I had to turn on debug in app/config/app.php, which popped up the issue in an amazingly descriptive debug screen, and then run key generate since the error was the absence of the encryption key
php artisan key:generate