Failing to deploy a Laravel app to EC2 - php

I have my Laravel project all working on my localhost.
I deployed it to EC2, but nothing comes up.
All I see in the dev console is internal error (500).
What am I missing? What do I need to change before deploying to AWS? Here is the URL:
http://ec2-52-88-99-75.us-west-2.compute.amazonaws.com
Here is the httpd.conf file:
http://collabedit.com/sdcxm

After installing Laravel, you may need to configure some permissions.
Directories within the storage and the bootstrap/cache directories
should be writable by your web server. - http://laravel.com/docs/master#configuration
Laravel "Storage" folder and the "bootstrap/cache" folder needs access from both the command line user (the one that runs composer update etc) and the default web server user (www-data) in case you are using ubuntu on your EC2 instance.
The following three commands will ensure that both of them have the rights to do that. Run them at the root of your project
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX storage bootstrap/cache
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX storage bootstrap/cache
This should start displaying you specific errors that you can debug. Also make sure that you have the debug option set as true in app.php
yourproject/config/app.php
'debug' => true,
Also make sure you have a default .env file that specifies the environment at the project root.
yourproject/.env
//should have this
APP_ENV = dev
Also if you are using sessions etc make sure you have a generated a key by
using this command and doesn't have config/app.php set as
'key' => env('APP_KEY', 'SomeRandomString'),
yourproject/config/app.php
php artisan key:generate
One common pitfall for new Amazon EC2 instances is to assign a security group
to your instance that doesn't have port 80 and 443 allowed as inbound.
Please check your EC2 instance's security group and allow those ports in the group if not already.

This worked for me:
[root#example-laravel-server ~]# chown -R apache:apache /var/www/laravel/laravel/storage

Related

Error with Symfony's cache and permissions

I got this continuous error with cache. Something with permissions but I can't figure what's going on. In my local environment when I go a php bin/console cache:clear -e=dev it return me this
[Symfony\Component\Filesystem\Exception\IOException]
Failed to remove file "/project/var/cache/de~/pools/ORsqbHaOKl/L/K/iZULk48B-k00dzIKC2qg": unlink(/project/var/cache/de~/pools/ORsqbHaOKl/L/K/iZULk48B-k00dzIKC2qg): Permission denied.
So I need to make first a chmod -R 777 var/, then again the clear cache and it works. But when I run the website it return me
Failed to create "/project/var/cache/dev/tcpdf": mkdir(): Permission denied.
So I need again to make chmod -R 777 var/
In the production server without erasing anything sometimes i get this error
Warning: rename(C:\project\var\cache\prod/doctrine/orm/Proxies\__CG__AppBundleEntitySomeEntity.php.5a142ad84e8464.47105642,C:\project\var\cache\prod/doctrine/orm/Proxies\__CG__AppBundleEntitySomeEntity.php): Access is denied. (code: 5)
error in vendor\doctrine\common\lib\Doctrine\Common\Proxy\ProxyGenerator.php
(line 309 rename())
$tmpFileName = $fileName . '.' . uniqid('', true);
file_put_contents($tmpFileName, $proxyCode);
#chmod($tmpFileName, 0664);
rename($tmpFileName, $fileName);
}
Local environment: debian 9
Production environment: windows server 2008
You need to set the var folder permissions as suggested by this symfony article.
Run the following commands in your project directory and you will not come across any permission related issues on cache and logs
HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1)
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
I've just played around with it a bit and noticed that every time you call
bin/console cache:clear --env=prod
The user of the folder /prod will be changed to the user that is executing the call. The scripts deletes the folder and creates a new own, but that will be done be the current user set.
You can stop the script from creating a new folder by using the --no-warmup option. With that, I've fixed my problem.
bin/console cache:clear --env=prod --no-warmup
For that to work you need to fix the current situation once, at best by deleting all folders and files within the /var/cache directory.

Trouble installing Symfony3. Virtualbox - Ubuntu guest / Windows 10 host

I've been trying to install Symfony3 into Ubuntu 14.04 running in virtualbox and have been following this tutorial:
http://symfony.com/doc/current/setup.html
So far I can get the Symfony command installed. I try running the Symfony command to create an application under the /var/www/html/ folder - my Apache web directory - and the following error is thrown :
I want to set up my application in this folder as this is a shared folder to a Windows 10 host. I can install Symfony under my home directory and can access this from the host browser.
Personally I think it's a permissions issue. I did find this this page for help and did not get much success. Can someone enlighten me as to what's going on?
Did you run this command already:
HTTPDUSER=`ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX var
Run it under the /var/www/html/symfony_test directory and tell us the results.
You have no write permissions because /var/www folders are writable by apache user. In some case (often linux) apache user is wwwdata. In MacOs the user is _www.
You can also try with some trick. First one, is to avoid apache for your development: just install symfony in you ~/Development folder, and run ./bin/console server:run command. Symfony allow you to run the php builtin server.

Symfony2 NGINX Unable to create the cache directory

I know this may seem as a repeated question but so far I have 4 hours digging around unable to find a straight answer to this. I have setup a brand new CentOS 7 and I installed NGINX (https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7) + PHP 5.6 (https://webtatic.com/packages/php56/) and MariaDB.
Following the guides I was able to make the NGINX serve PHP files successfully.
I have a project in Symfony2 which I am trying to get in this server, my problem is when I try to open up http://server/web/app.php. I get the following error:
Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory (/usr/share/nginx/html/app/cache/prod) ' in ................
I read in the documentation (http://symfony.com/doc/current/book/installation.html) that I should work around my permissions so I was able to apply the following:
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
Since I have CentOS 7 from scratch that was the option that I was able to apply. However, I still have the same issue, after this approach these are the other options I've tried:
changed the owner for app/cache and app/logs to nginx:nginx
changed the permissions to 777 to the above folders
verified and re-verified that PHP is running under the nginx user, I had to change this in the www.conf
if I do ls -Al it shows that app/cache and app/logs are owned by nginx
restarted services after each single change
restarted the server completely
cleared the cache and performed warmup and still
Tried the umask option provided by symfony and still.
So after all these options I still get the same issue, to other people out there with this problem it's simply following the Symfony2 guidelines for applying the ACL and puff, done. But this is not the case.
What am I missing?
Ps: I double checked the permissions of the folder..and I am in the server as root.
Update 1
I re-installed CentOS 7 from scratch and followed https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7 and in combination with Symfony's suggestion for the configuration file and still I get the " Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory" error
You might be running into SELinux issues, since CentOS 7 ships with SELinux running by default.
You can test by executing setenforce 0 to see if that solves the problem. If that works, you need to configure SELinux to allow the nginx user to write to the cache directory, and then re-enable SELinux. SELinux does provide some good security, so it would be best to figure out how to configure it properly, as opposed to turning it off completely.
You need to add a local custom rule (policy module), suppose you have your application under the /usr/share/nginx/www directory:
semanage fcontext -a -t httpd_sys_rw_content_t '/usr/share/nginx/www/.+/app/(cache|logs)(/.*)?'
You need to restore the contexts for all the files in that dir:
restorecon -Rv /usr/share/nginx/www/your-app-dir
Change the group of the cache and logs directories and add permissions for the group:
chgrp -R apache /usr/share/nginx/www/your-app-dir/app/{cache,logs}
chmod -R 775 /usr/share/nginx/www/your-app-dir/app/{cache,logs}

Symfony2 Installation problems

I'm new to Symfony2 and I'm trying to create a new project in my local environment following the steps listed in the Symfony book:
Download
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
Create Project (path relative to /var/www/)
$ php composer.phar create-project symfony/framework-standard-edition grupo76/final/ Symfony 2.5.*
1st Problem: I have to add /web/ to paths
So, now I have to test the configuration by hitting
http://localhost/grupo_76/final/config.php
I get a 404, and have to change the address to
http://localhost/grupo_76/final/web/config.php
It complains about permissions on /app/logs and /app/cache but that's ok. I ran
HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
2nd Problem: app_dev.php is completely broken
Then, the book suggest I should hit
http://localhost/grupo_76/final/app_dev.php
but, again, I need to add /web/
http://localhost/grupo_76/final/web/app_dev.php
The page renders, but full of errors like this No route found for "GET /"
Please, see attachment.
I'm running:
Apache2
PHP 5.5.9-1ubuntu4
Ubuntu 14.04
1st Problem
You have to configure a web server. There is an official documentation for configuring web server for both Apache and Nginx. What you are doing is accessing app_dev.php or config.php from your localhost host relatively. See: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
2nd Problem
You have to define routing for your / path (homepage, in other words). See: http://symfony.com/doc/current/book/routing.html
A virtual-host won't help you, I already tried that, my working solution is:
1- Delete the old Symfony installation
2- Install a fresh one as root (sudo su)
3- Grant permissions to /var/www/html with chmod 777 -R /var/www/html"
Just take in count that you may want to readjust the folder's permissions when you get it working, to your specific scenario.

Symfony 2 : dev to pro = blank page

first I took you to excuse my English.
I made a website with Symfony which works fine locally. (dev and prod).
But as soon as I put online the dev version works but the prod version displays a blank page.
Lighttpd does not give me error.
PHP does not give me error.
Cache and log are writable.
I do not understand anything.
OK, this is highly undesirable situation as you need to squash bugs one-by-one. It could be as benign as missing php module or some major httpd misconfiguraion.
Some steps that should shed some light on the issue:
Fire up the Terminal (you do have ssh access, right?)
Check logs (both httpd and symfony)
httpd log:
tail -f /var/log/httpd/error_log
... and refresh your page
Symfony
tail -f /path-to-your-symfony-app/app/logs/prod.log
... again, refresh your page
In your comment, you said you encountered HTTP500 error. Is that Apache's or Symfony's HTTP500?
If you do not hape ssh access upload your app_dev.php and run it directly. Be sure to add your IP address to list of allowed (within the file)
Change your permission on cache and log folders in 777.
chmod 777 cache/ log/ -R
php symfony cc
As the documentation says:
Instead of the Welcome Page, you may see a blank page or an error page. This is caused by a directory permission misconfiguration. There are several possible solutions depending on your operating system. All of them are explained in the Setting up Permissions section.
And then you should follow these steps:
rm -rf app/cache/*
rm -rf app/logs/*
HTTPDUSER=' ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1'
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:'whoami':rwX app/cache app/logs
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:'whoami':rwX app/cache app/logs
I did the deployment as guided in this official docs
In my case the update of symfony before deploying was not BC with an old Bundle, so the clear:cache --env=prod was giving some error. So what I did was to manually delete the prod cache and then clear:cache with the prod environment and it worked: so to resume:
#rm -rf app/cache/prod/* #removes only production cache
rm -rf app/cache/ #removes prod and any other stage cache
php app/console cache:clear --env=prod

Categories