Symfony working with multiple bundle and uploading bundle to server - php

I have two problems with symfony. First one is, if I have two bundles created, only the first created bundle is shown when I go to localhost/symfony/web/app_dev.php/ As of now, I have the two bundles in my src/ both bundles are registered in the kernel, routes added and everything. But, I can only see the first created bundle, I don't know what to do, to see the second bundle in action.
Second problem is that, when I want to upload my finished symfony project, I can't see know how. Like, do I tell .htaccess to treat the app_dev.php files as index files, and to hide the folder name symfony from the URL, so that the mysite.com/symfony/web/app_dev.php to show as mysite.com/index.php because, I don't really get it.
Any help is much appreciated.

To "see second bundle in action", point your browser to some route of such bundle.
To be sure its routes have been registered, run:
$ php app/console router:debug
and see if they appear in the list.
Regarding deploying, you should read this topic.
Keep in mind that app_dev.php is meant for development environment, and should not be used for production; included .htaccess already routes all requests to app.php.
In order to make http://www.mysite.com/ your entry point, you should /yourproject/web be your webroot, or better use a symlink.

As the .htaccess part you way copy this into the .htaccess and put it in the root folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# DEV ENVIRONMENT #
RewriteRule ^$ symfony/web/app_dev.php [QSA]
RewriteRule ^(.*)$ symfony/web/app_dev.php/$1 [QSA,L]
# PROD ENVIRONMENT #
RewriteRule ^$ symfony/web/app.php [QSA]
RewriteRule ^(.*)$ symfony/web/app.php/$1 [QSA,L]
</IfModule>

Related

How to solve Laravel's Route 404 error on Login page?

A project, which is prepared with Laravel Framework, has handed over to me. Previous developer has not used git, some composer commands and Laravel's .gitignore file(also removed it). On the other hand he has prepared the project on the production server.
Anyway. Firstly I've found a gitignore for laravel and pushed the project to my repository. Then I wanted to pull it to my local. All folders and files pulled except of vendor folder.
Then I executed:
composer install
Gave me this error:
Class 'Maatwebsite\Excel\Excel' not found
Then I fixed it by the method here.
Then retried composer install, gave me this error:
Undefined index: name
Then fixed it by the method here.
Then retried composer install, and succeeded. Then I cleared cache with php artisan cache:clear
I've configured .env file and tried to enter to homepage. It redirected me to login page and gave 404. I've checked the .htaccess, there was redirection like that:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://example.com/app/$1 [R=301,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
<IfModule mime_module>
AddType application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Changed the example.com to my localhost. But still gives me 404.
Is there anything that I'm missing?
Note: Called the previous developer, and he said me "directly copy and paste the all folders". Hi from 90s :(
OP Said this worked for him so I'm moving it from comments to an answer:
Let's go over what should be there for the pages to return correctly: First you need a routes folder with with all the routes in files inside of it. Second you need the Controller folder (found in /app/Http). Third you need the resources folder with the actual views. Fourth you need the public folder with the CSS/JS, etc.
Since OP stated that all the views work except for the login view:
First find out what the login view page is called, then go to your routes and make sure there's a line such as
Route::get('/login', 'SomeController#somefunction')->name('login.path');
Then go to the controller that is referenced in that route, and make sure that the function returns the view of the login page
Have you tried to generate you laravel application key using php artisan key:generate.
If that also doesn't work then try to remove .htaccess temporary.
Try this command
composer require maatwebsite/excel:^3.0

ZF2 Apache install on VPS witout creating Virtual Host

I want to install my ZF2 application on a VPS server without support for Virtual Host. I´m using a simple application based on ZendApplicationSkeleton.
I´m using the default .htaccess:
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
All solution I´ve found in SO does not work for me. They may fit ZF1, but not ZF2:
Link 1
Link 2
Link 3
Link 4
My application is in a folder named /var/www/html/testapp.
The main page is loaded once I typelocalhost/testapp/public on the browser. Also my module is loaded if I type localhost/testapp/module, but navigation does not work.
Ie: in the main page, I´ve created a button like:
Go To Module
But if I click on it I navigate to localhost/login/index showing Not Found, not to the correct module/index.phtml page.
Help appreciated with that.
Your problem has nothing to do with server configuration. Since your app is in a sub-folder, the link is wrong. It would need to be something like
Go To Module
for it to work. However, public/ should never appear in you URLs. With things setup this way you are allowing users to view files outside your app's web root, which is a potential security risk (and results in ugly URLs).
The solution to this is to setup a separate vhost for your ZF2 app, which has a DOCUMENT ROOT pointing at the app's public folder. If you are having problems with this, post that as your question; or if you can explain why this isn't possible perhaps we can advise further.

Laravel 5.1 - Dreamhost VPS - Always getting 404 exception

I have been breaking my head for the last two days now and still don't have a solution. All routes in my Laravel 5.1 are throwing a NotFoundHttpException.
My folder structure looks like this:
Some additional info
Both example.com and abc.example.com have web directory set to
/home/username/example.com/myproject/public
I have a .htaccess file inside the public folder which looks like
Options -MultiViews
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]
As Image:
Debugbar is showing the following error:
Any help will be highly appreciated. I have tried almost all solutions found on Google. None worked.
So after fighting tooth and nail to resolve this, I decided to take a different approach and to my relief, IT WORKED!
Rather than deploying inside a "myproject" folder, I copied all Laravel files directly under example.com. So if you're cloning your repository (as I was), I manually copied files one level up.
Created the proper .env file
Ran the following commands in order:
composer dump-autoload
php artisan config:cache
and voila! things were up and running!
Now ... some other imporant things to note.
If you're using subdomain routing, you have to setup your domain such that it doesn't put the www. In my case, http://example.com was becoming http://www.example.com and my controller actions were failing. I am sure there is a work around for this. Will update this answer, if I find and answer.

Apache rewrite for Laravel /public

I am sorry about this, but my htdocs root is wrong and I can't change that. So I have to make it work in the /public folder.
I use the normal Laravel .htaccess file with the following rewrite:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If I open http://kemtime2_neu.pr.domain.de/public I get redirected to http://kemtime2_neu.pr.domain.de/public/http://kemtime2_neu.pr.domain.de/public/login
How can I fix this?
I would love to make it work from http://kemtime2_neu.pr.domain.de/ but getting it to work with http://kemtime2_neu.pr.domain.de/public/ would be fine.
I use the 3 solution of this post and works fine:
http://web.archive.org/web/20130320184846/http://forums.laravel.io/viewtopic.php?id=1258
Solution 1 - Alternate installation path with symlink.
This is the preferred solution and in general an all-around good idea. It's possible to install your application to a folder unrelated to public_html/ and then symlink the public folder to the public_html/ path.
For example:
Install your application to /home/applications/mysite.com
Imagine that your DocumentRoot points to /var/www/vhosts/mysite.com/httpdocs
Remove the httpdocs folder from the mysite.com vhosts folder then connect the two with a symlink: ln -s /home/applications/mysite.com/public /var/www/vhosts/mysite.com/httpdocs
Solution 2 - .htaccess with mod_rewrite
This solution enables you to drop Laravel into your public folder then use a .htaccess file to redirect requests to the public folder. This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Step 1. Place Laravel in your document root folder.
Step 2. Place the following .htaccess file in your document root folder.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Step 3. Make sure that you manually set your 'url' configuration in application/config/application.php otherwise Laravel will generate incorrect URLs. Make sure that each of your environments have the correct application.url configuration. For more information on environment-specific configurations see: http://laravel.com/docs/install#environments
Solution 3 - merge the public folder into the installation root
This solution places your application and core system code into a publicly accessible folder. This is not something that we encourage you to do with any PHP framework.
Copy the contents of the public/ folder into your Laravel installation folder then change this line in your index.php file from:
require '../paths.php';
to
require 'paths.php';
Keep in mind that any bundles, libraries, or other types of third-party code may not be designed to be publicly accessible.
Note: It's also important to note that your bundles/ and public/bundles/ directories will now conflict. When using this approach you may want to not use artisan's bundle:publish task without knowing exactly what your bundles want to publish.
I solved it partly. If I have a .htaccess in the root instead of /public with
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
I can open http://kemtime2_neu.pr.domain.de/login but the images and css is still wrong. I need to check first if the files exist in /public. I think this is a new question.

.htaccess for site in sub-directory using Yii framework

I have looked at several examples of htaccess configs for websites within sub-directories, and tried most of them without 100% success.
My setup is:
using Yii framework
htaccess at public_html/.htaccess
site located inside public_html/mysite directory
index handling all requests located at public_html/mysite/frontend/www/index.php
The status of the URLs:
www.mysite.com works fine [ok]
www.mysite.com/controller/action shows me the homepage [wrong]
www.mysite.com/mysite/frontend/www/controller/action works fine [wrong, the item above should work instead]
My .htaccess at the moment looks like this:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)?$ /mysite/frontend/www/index.php [L]
I have tried everything, but I have no idea why www.mysite.com/controller/action won't work :(
Any help would be really appreciated! Thanks!
I found the answer to this similar question to be helpful. Here is how my rewrite rules ended up:
#Forward all non-existent files/directories to Yii
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
This takes all non-existent files/folders and sends them to the yii script with initial url appended. QSA appends any query string that may be present in the initial url.
You didn't mention if you configured Yii's Url Manager for clean URLs. You need to, otherwise Yii expects the "route" to appear as a GET param named "r". If you didn't, consult this section of the definitive guide
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory
I also didn't update the .htaccess file, easier to modify the httpd.conf virtual host for the subdomain and change the DocumentRoot to point to your yii folder.

Categories