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!
Related
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 created a PHP website on azure using app services. I use continuous deployment through bitbucket. I need to point the website to public folder in my code to run the app as it is built with zend framework.
After some search, was not able to find how to change the folder where the server points for default directory.
Go to Azure Web apps settings -> Application Settings -> Virtual Applications and directories and setup the physical path of the new folder. Also check the Application checkbox.
Restart the web app once.
There are a few scenarios possible:
You run a Windows App Service
You run a Linux App Service with PHP 7.4 or less
You run a Linux App Service with PHP 8
In the first scenario (Windows App Service) you can go to the App Service > Settings > Configuration blade you need to select the tab "Path Mappings" where you can set the Virtual Applications paths as follows: "/" maps to "site\wwwroot\public".
In the second scenario you can use the .htaccess solution described by #Ed Greenberg, even though for Zend Framework I suggest to use the following settings:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
For the third scenario you have a bit more of a challenge since Apache was replaced by Nginx and the rewrite rules no longer apply. Please see my detailed blog article "PHP 8 on Azure App Service" on how to solve this and other challenges with the new Azure App Service for PHP 8.
Good luck and let me know if it solved your problem.
For PHP 8.0 with nginx I use startup.sh script placed in the root directory of the project. startup.sh contains the following line:
sed -i 's/\/home\/site\/wwwroot/\/home\/site\/wwwroot\/public/g' /etc/nginx/sites-available/default && service nginx reload
You need to add "startup.sh" as Startup Command in General Settings. Now "public" dir is your root directory.
The correct answer in 2021 (for Laravel, and probably other frameworks with a /public directory) is to put an extra .htaccess in the webroot directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Credit to Azure Web App - Linux/Laravel : Point domain to folder
Finally I've found Laravel documentation how to make it work with Azure. To be more precise - PHP8 + NGINX. Here is the article link - https://azureossd.github.io/2022/04/22/PHP-Laravel-deploy-on-App-Service-Linux-copy/index.html
Hope it will be useful :-)
PHP 8 (NGINX)
PHP 8 on Azure App Service Linux use NGINX as the Web Server. To have NGINX route requests to /public we’ll have to configure a custom startup script. We can grab the existing default.conf under /etc/nginx/sites-available/default.conf and run cp /etc/nginx/sites-available/default.conf /home. This will copy the default.conf we need into /home so we can download it with an FTP client or any other tool that allows this.
This default.conf has the following line:
root /home/site/wwwroot;
We need to change it to the following:
root /home/site/wwwroot/public;
Next, under the location block we need to change it from:
location / {
index index.php index.html index.htm hostingstart.html;
}
to the following:
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /index.php?$args;
}
Now configure your actual startup.sh bash script. Note, the file name is arbitrary as long as it is a Bash (.sh) script. Configure the file along the lines of the below:
#!/bin/bash
echo "Copying custom default.conf over to /etc/nginx/sites-available/default.conf"
NGINX_CONF=/home/default.conf
if [ -f "$NGINX_CONF" ]; then
cp /home/default.conf /etc/nginx/sites-available/default
service nginx reload
else
echo "File does not exist, skipping cp."
fi
NOTE: $query_string can be used as well. See the official documentation here.
Our custom default.conf should look like the below:
server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /index.php?$args;
}
........
.....
...all the other default directives that were in this file originally...
}
Use an FTP client to upload both your startup.sh script and your custom default.sh to the /home directory for your PHP App Service.
Next, under ‘Configuration’ in the portal target /home/startup.sh (or whatever the startup script file name is).
Laravel App
Lastly, restart the App Service. This should now be using our custom startup script. Use LogStream or the Diagnose and Solve -> Application Logs detector, or other methods, to see the stdout from the script.
Laravel 5 deployment getting :
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request
My file structure:
|
|-pub -> from laravel folder public
|-my_apps
|- my_first_app -> all other files from laravel project
|- app
|- bootstrap
|- config
|- database
|- resources
|- storage
|- ...
I have set storage folder permission to be:
user::rwx
group::rwx
other::rwx
This is my .htaccess file in directory /pub
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase / <-------- I added this line
# 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]
</IfModule>
I also change path in \pub\index.php
<?php
//updated path
require __DIR__.'/../my_apps/my_first_app/bootstrap/autoload.php';
//updated path
$app = require_once __DIR__.'/../my_apps/my_first_app/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
PHP on my local machine is PHP 5.6, it is PHP 5.5. I tried to add
AddHandler application/x-httpd-php55 .php
in .htaccess after RewriteEngine On line.
update
The server runs PHP 5.5.0, so I downgraded my Laravel 5.1 to 5.0, and it works on homestead now.
And I'm following https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.50q2s8wer for deployment at this moment. Downgrade actually failed when I check version of laravel
Laravel 5.1 requires PHP 5.5.9, per packagist.
Laravel 5.0 has no bound PHP version requirement, per packagist, however anything less than PHP 5.5 is Not A Good Idea.
Since your server runs 5.5.0 (per comment), then I'm guessing you installed this outside of composer. Downgrade your Laravel environment or upgrade your PHP environment. Upgrading PHP is A Good Idea.
"Internal Server Errors" maybe caused by many reason. Library is not installed, misconfiguration, version conflicted.
So please check the apache errors in /var/log/apache or /var/log/httpd, Laravel errors for more detail about the error. If you cannot see error, be sure that you turned on php display error in php.ini file.
If you could check the logs in /var/log/apache2 or /var/log/httpd for errors, it would be much helpful. But, since you said that your server is running PHP 5.5.0 and
Downgrade actually failed when I check version of laravel
so, clearly the most probable reason is that your server is trying to run laravel 5.1 with PHP 5.5.0 which is not supported. The solution for you now is to create a fresh project with laravel 5.0 and then copy code files you have created from current project to the new project and update them accordingly so that they work with laravel 5.0.
In my case it was as simple as a case-sensitivity typo in one of my includes. I develop on a Windows machine, which doesn't care about case-sensitivity in file paths. After deploying to a Linux server however I got the infamous Internal Server error.
Checking laravels php_errors.log quickly made it clear what was wrong.