Problems when moving Symfony3 app from dev to production server - php

I've created a web application using Symfony 3. In the development environment, I always use Symfony's built-in server and just use the command "php bin/console server:run". The app can then be accessed via "localhost:8000".
I've also defined routes using annotations in Controllers such as "/", "/about" etc. These pages can be accessed via "localhost:8000/" and "localhost:8000/about". Other links on the page that point to routes like "/contact" or "/users/1" also work perfectly. They will link to "localhost:8000/contact" and "localhost:8000/users/1".
Now, I move my application to the production server. On the production server, Apache2 is installed and some other people have developed Symfony applications on it. Their apps can be accessed via url like "example.com/apps/app1/web/app_dev.php" and the links on their apps have been pre-appended with "example.com/apps/app1/web/app_dev.php" automatically. So when the user clicks a button that links to "/contact", the link will direct to "example.com/apps/app1/web/app_dev.php/contact".
Now, when I move my application named "app2" under the "example.com/apps/" directory, I can visit "example.com/apps/app2/web/app_dev.php" without any configuration and see my homepage perfectly. Apache can automatically pick up my code. However all the links on the homepage will direct to "example.com/contact" instead of "example.com/apps/app2/web/app_dev.php/contact".
Can anyone help me with this? I'm pretty new with Symfony and Apache.
Or perhaps I've done the migration from dev to production environment in a totally wrong way? Any new ideas or proper way to move Symfony3 application to production server?
Thanks a lot!

Do you have apache configured correctly? You may need to have a virtualhost configuration added to the server. You can find out about it on the Symfony site for the specifics.

I finally solved the issue. I should use href="{{ path('about') }}" instead of href="/about" in all twig templates. Thanks everybody!

Related

Having trouble configuring Laravel

I'm using Laravel with intellij and whenever I run my project this is what it looks like in the web browser
I'm not sure if I set up Laravel correctly on intellij. I set it up for XAMPP because I thought that was the problem however my pages are still looking like the image above.
probably it's not laravel problem. Maybe is better to setup local server in right way. You can try:
php artisan serve
under laravel root dir and then open in http://localhost:8000 in browser
Those icons are trying to use php built in server and may not be configured to match your laravel project. I get the same thing as you with localhost:63342 when clicking web browser preview icons in my Symfony project. I just configured phpStorm preview icons to load based on my web server root.
When using laravel, trying to load your blade views directly will most likely run into issues. Your request is not being mapped to a route/controller for it to be properly handled. For my symfony project and after configuring phpStorm, i get sent to app.dev/app/Resources/views/test.php, which is not a valid route (proves point of previous sentence). You will most likely get the same issue in your laravel project.
You can configure your phpStorm preview icons to load to your localhost:8000 / app.dev or whatever you may have set your app host to.
Follow the below phpStorm articles if you want to mess with this some more.
https://www.jetbrains.com/help/phpstorm/2016.3/working-with-web-servers-copying-files.html
https://www.jetbrains.com/help/phpstorm/2016.3/creating-a-local-server-configuration.html

Using laravel in a subdirectory, without root access

A year ago, I decided to go with codeigniter instead of laravel, because codeigniter prooved to be easier to setup. I am now preparing for my next project and it seems as if codeigniter is now obsolete (at least most of the people seem to recommend laravel over codeigniter).
Now to my problem: I use a virtual ubuntu machine for developing web apps so I have a dev environment similar to the production environment (this helps me to avoid some problems (especially case-sensitivity...;)))
I installed composer and laravel and created a new laravel project named "quickstart" in /var/www/quickstart. I then followed their "getting started guide" (here: Guide). So far everything worked.
But here come the problems:
I have two other web applications in /var/www, so when I enter the ip of the machine I see the 3 directories.
Issue 1:
Normaly I'd expect that as soon as if I click on the "quickstart"-Directory in my browser, the webapp would get displayed, but I have to click a second time on "public", and then the webapp is displayed.
Issue 2: Of course, the links on the page are wrong too, because they reeer to (for example) "/task", which can't be found on the server.
The problem is that I'm not really experienced with apache configuration. I suspect it has something to do with VirtualHosts, but AFAIK you need to have root access to configure virtual hosts, and I do not have root rights on the dev environment.
Could you point out a way to me how I can make laravel work in a subdirectory in a way that I can just move the files and folders to my hoster as soon as I have finished the project? I'd like to then change only one file, and not all paths and URLs in all files ;)
Regards,
Christian
Thanks to Bogdan, I was able to figure it out. My hoster allows symlinks, so I did it like so:
I put the laravel installation in
/srv/web/quickstart
(quickstart is the name of the project). I then created the following symlink:
ln -s /srv/web/quickstart/public /srv/web/www/public
The document root of the apache is configured to
/srv/web/www/public
After that I just got a blank page. That was because I forgot to set the correct permissions on the storage-folder. So I set the following permissions
chmod -R 777 /srv/web/quickstart/storage
This is fine for a development environment. For production I'd recommend to only allow the webserver-user to write into that directory.
And voilĂ : Everything works!
Thank you for your help bogdan.
Christian

Laravel and Angular url prefix issue with apache

I created an app with Laravel and angular. On development The app works good in php artisan serve in localhost:8000.
if i copied the project folder and paste in www of lamp or wamp then i need to use localhost/projectname/public. To load the css and js i use <base href="/projectname/public/"> in my main html.
But my urls and angular templates still miss the projectname/public. if I click a url it goes to localhost\url. How to prefix url in angular? or is there another way to work this out?
There are 2 ways to fix this.
First is laravel homestead. This is perfect for laravel projects. for more information about homestead go here
The other option is to setup a virtual host on your wamp server. For more info about this go here

Deploy CodeIgniter Php app on heroku

I am trying to deploy a php application having CodeIgniter as a framework in heroku.
I followed the steps here until the "Process and dyno tuning" part and managed to deploy my application. The first page works fine, but that's all. For any other page with codeigniter links(/index.php/home/link/ for the home controller, link action) I try to access, the server renders me the same first page. I thought that CI requires some of heroku extensions but here it says it only needs php. Do you happen to know what extensions do i have to provide?
The link to the website is this, and a test url should be this
This is defiantly a URI issue, Please try switching $config['uri_protocol']
from AUTO to any of the available modes until you get it fixed.
If you need a fast fix for this, just add ? for your index.php urls so it will be like this
index.php?/locations/get
but fixing this through the 'uri_protocol' thing is better.

Problems while Developing MVC Projects using WAMP server

I am trying to develop websites using Zend Framework. But I came to a strange problem, the public folder is not showing up. I was suppose to change the apache's configuration to redirect http://localhost/ to http://localhost/public, but there are many projects inside the WWW folder, which has to be accesed.
I can enable the mod_rewrite to bring out the public folder, but I am not allowed to change it while I upload it to the actual web server. Is there anyway to solve this problem?
May be a .htaccess file to change the site root folder would be of help.
This answer is a detailed description of manually setting up your virtual host and configuring a basic ZF app to run. Hopefully it will help.
Update: Given your edited question, perhaps my blog post discussing one approach to deploying a ZF app on shared hosting might be helpful.

Categories