Symfony 5 deployment issues (showing empty page) - php

This is my first deployment in Symfony 5 and I've been struggling a couple days with deployment because my website is showing a blank page.
I'm using Infinity Free Web Hosting with:
PHP Version 7.3.6
Apache
My website doesn't have a db.
So before I start to upload files with FileZilla, I run this commands:
SET APP_ENV=prod
composer install --no-dev --optimize-autoloader
composer dump-autoload --optimize --no-dev --classmap-authoritative
My folder structure goes like this
htdocs
\css
\downloads
\images
\scripts
.env.local
.htaccess
index.php
\symfony
\bin
\config
\src
\templates
\translations
\vendor
\var
composer.json
And modified index.php with new path:
require dirname(__DIR__).'symfony/vendor/autoload.php';
The issue is that the page is showing completely blank (not even an error). What is my mistake?
I've been following instructions with this tutorial, create a "symfony" folder with bin, config, src, templates and vendor, and I copied my "public" folder content to /htdocs folder.
Hosting provider doesn't allow me to upload content at the server root folder.
Thanks in advance.

You missing a / on your require :
require dirname(__DIR__).'/symfony/vendor/autoload.php';
Maybe use dev environment for debugging your application.
You have a .env.local : are you sure is necessary and correctly read ? (symfony/dotenv is a devDependency by default)
And I think is not a good practice to have your symfony folder and index.php on same directory because it can expose your source code and sensitive data. Maybe use htaccess to expose only symfony public directory.

Related

PHPUnit + Composer folder structure git vs server deploy

I try to add PHPUnit tests to my existing php project.
Applying the recomended folder structure for phpunit (https://phpunit.readthedocs.io/en/9.5/organizing-tests.html), I encounter the following problem deploying it to the server.
Current setup php+composer without phpunit
Checked out from git Git + composer install:
- my.php
- composer.json
- composer.lock
- vendor/
I copy php files and vendor folder to a path on the server
Server:
- path/my.php
- path/vendor/
So the URL is https://server/path/my.php
In my.php I include the composer dependencies like this
require_once 'vendor/autoload.php';
New setup with phpunit included
With recomended folder structure for phpunit (https://phpunit.readthedocs.io/en/9.5/organizing-tests.html)
Checked out from git Git + composer install:
- src/my.php
- tests/mytest.php
- composer.json
- composer.lock
- vendor/
In my.php I now include the composer dependencies like this
require_once '../vendor/autoload.php';
Problems with new setup
If I copy src+vendor/ to path/ the server the URL would be different (https://server/path/src/my.php).
If I copy src/*.php and vendor/ to path/ I would have to change the require_once upon deployment for it to work.
Desired result
tests seperated from src
accessible via the same URL
not having to change php file content uppon deployment (CD)
The closest solution I came up with
Is to not implement recomended directory structure, leave my old structure, and just create a tests/ directory.
My question
Is there a best practice solution keeping the src+tests directory structure while keeping the same URL and not having to modify src files upon deployment?

How to install composer dependencies when the root folder of the Google App Engine project is outside the composer.json directory?

I'm using Google App engine to deploy a PHP project.
I'm using the following file structure.
public/project_files_here_composer.json_here_too
private/some_private_files
app.yaml
In app.yaml I set the public folder to be the web root directory that contains the index.php .
When I deploy this with google app deploy , my composer dependencies are not installed.
How to tell Google App Engine to install my dependencies inside the the public/ folder (using the composer.json in the public folder) ?
I've been searching on the documentation for the gcloud app deploy operation and the app.yaml file and I didn't manage to find any reference to what you intend to do. Trying to reproduce your scenario, what I did was to create a soft link in the app's root directory that pointed to the composer file in another folder, but it didn't work.
What did work was creating a hard link in the app's root folder with the following command:
ln public/composer.json composer.json
Regardless, when I made the gcloud app deploy command, it said that it was uploading 0 files (which is kinda true), but when I looked on the source from the Console, the file was there and the dependencies were installed, so it works.
If you don't want to create a hard link, you should just create a script that copies the file, deploys and removes it. Something in the lines of:
#!/bin/bash
cp public/composer.json .
gcloud app deploy
rm composer.json
If none of these works for you, you should just move the composer.json to the app's root directory.

CodeIgniter Composer "package.json" locations shluld be in application or root folder?

I working with code igniter v3.x and I would like to add some composer packages.
looking at application/config/config.php file, it says that will load packages inside application folder
| package auto-loader script in application/vendor/autoload.php.
However in the codeigniter package it already has a package.json that installs packages on root folder.
I suspect that the package.json on the root must hold only information about CodeIgniter it self. But I'm not sure.
So I have three options:
Create a new package.json inside the application folder and install packages inside application.
Modify the package.json on the root folder by adding new package and change autoload.php location
What is expected from a CodeIgniter Application?
Well, if you take a look at the Codeigniter Documentation you can see there is a Configuration setting called composer_autoload. This information can be found here.
If you set this true, Codeigniter tries to load Composer's autoload.php in the APPLICATION.'vendor' folder. If you take a closer look at the Codeigniter.php file, you'll see that you can define a directory for this setting too.
So in your case you don't have to change the package.json in the root folder because you need one in the application folder, in case you set composer_autoload to true, which i would recommend.
By the way if you try to install a package via composer in your application directory, composer asks you if you want to use the one it found on the root folder - just decline that and press n.
As you can see in the picture below (i just tried to install the mpdf package).

laravel installation on shared hosting with composer

I'm trying to learn Laravel and follow the instructions in their tutorial to install the framework on my shared hosting. I've disabled the secure-http option in composer but it still won't download the framework.
Called:
composer global require "laravel/installer"
Response:
Changed current directory to /home/sledzko/.composer
Warning: Accessing packagist.org over http which is an insecure protocol.
[LogicException]
Composer repositories that have providers can not load the complete list of packages, use getProviderNames instead.
What can I do to download the framework using composer?
Most of the shared hosting is not supported terminal/command access, that why it is not possible to install Laravel using composer on shared hosting.
But there is a way to use Laravel in shared hosting, you can install/setup Laravel project on a local machine and after that upload project (all directory structure and files) on your shared hosting. Only need to adjust public directory and bootstrap path in the index.php file.
Upload all files is in public folder in your shared hosting www/public_html folder, and all other folder structure in the separate folder. After that go to your index.php file in www/public_html folder and update below two linew with your path laravel folder path.
require DIR.'/../bootstrap/autoload.php';
$app = require_once DIR.'/../bootstrap/app.php';
Install package locally using Composer. The package folder will be created in the vendor path.
Copy vendor/packagename folder and paste it into your host's vendor path.
Replace your host vendor/composer folder with your local vendor/composer folder.
Replace your host composer.json with your local composer.json
please try:
composer create-project laravel/laravel --prefer-dist YOUR_PROJECT_NAME
This will help you to download the stable version on your machine!
If you use SiteGround you will be a lucky man, just must request access do ssh (over cpanel), and then run your composer command on terminal.
SiteGround servers already have composer globally installed.
BUT... you you want to do it on hard way, access you shell on Siteground and run:
wget https://getcomposer.org/composer.phar -O ${HOME}/composer.phar
echo "alias composer=\"/usr/local/php72/bin/php-cli ${HOME}/composer.phar \"" >> ${HOME}/.bashrc
source ${HOME}/.bashrc
composer --version
Just pay attention on php72 version, it's uses PHP 7.2. If you want or need another one do a ls /usr/local/ to see all versions.

Laravel 4: Running composer when deploying to Heroku

I've been searching everywhere for an answer to this.
I built an app in Laravel - I chose Heroku for deployment, I included a custom Procfile and httpd.conf to rewrite the document root to public. That all works great.
However my app shows an internal 500 error upon loading because it hasn't loaded any dependencies i.e. not run composer upon deployment.
My question is: how do I make composer run upon deployment?
p.s. I'm a total noob with this kind of stuff so please provide as much detail as possible.
The only possible solution I've seen is here: http://bergie.iki.fi/blog/using_composer_to_manage_dependencies_in_heroku_php_apps/
But I'm convinced there is better way than this.
Try the following
Composer Fix
You need to generate and include composer.lock in the repo, but Laravel's default .gitignore ignores composer.lock
Remove composer.lock from .gitignore
$ composer install
Add your Procfile
Heroku knows which processes to run for your app based on a configuration file called a Procfile. The default apache2 process (if you don't use a Procfile) points to the web root, not to /public, so we need to create a custom Procfile to serve the site from /public.
Add a file with the name Procfile that contains this line:
web: vendor/bin/heroku-php-apache2 public
Deploy your code to the Heroku app
$ git push heroku master
Another possible cause is that Heroku doesn't recognize your app as a PHP app, for example because of the presence of package.json in the root. And so it doesn't do composer install for you.
Solution is to specify a buildpack, and do a push again.
heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php
See also:
Heroku doesn't recognize my Laravel app as PHP app, and does not do composer install

Categories