Symfony with buggy routing on apache - symfony

I installed Symfony on a fresh Debian 9 server.
I created a project:
composer create-project symfony/website-skeleton symfony
(masch3 is the name of my development machine)
When opening http://masch3/symfony/public/
I get the well known Symfony welcome page.
When I create the most simple Controller named "home"
class HomeController extends AbstractController
{
#[Route('/home', name: 'home')]
public function index(): Response
{
return $this->render('home/index.html.twig', [
'controller_name' => 'HomeController',
]);
}
}
http://masch3/symfony/public/home -> 404 not found
http://masch3/symfony/public/index.php/home -> OK
As recommended in other answers, I installed Apache pack with
composer require symfony/apache-pack
But this still does not do.
php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_preview_error ANY ANY ANY /_error/{code}.{_format}
home ANY ANY ANY /home
-------------------------- -------- -------- ------ -----------------------------------
php bin/console about
-------------------- -------------------------------------------
Symfony
-------------------- -------------------------------------------
Version 6.0.2
Long-Term Support No
End of maintenance 07/2022 (in +194 days)
End of life 07/2022 (in +194 days)
-------------------- -------------------------------------------
Kernel
-------------------- -------------------------------------------
Type App\Kernel
Environment dev
Debug true
Charset UTF-8
Cache directory ./var/cache/dev (6.8 MiB)
Build directory ./var/cache/dev (6.8 MiB)
Log directory ./var/log (19 KiB)
-------------------- -------------------------------------------
PHP
-------------------- -------------------------------------------
Version 8.0.14
Architecture 64 bits
Intl locale de_DE
Timezone Europe/Berlin (2022-01-18T13:45:22+01:00)
OPcache true
APCu false
Xdebug false
-------------------- -------------------------------------------

Edit the main Apache config file:
sudo nano /etc/apache2/apache2.conf
look for this section:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Replace AllowOverride None with AllowOverride All
Activate apache’s rewrite module.
sudo a2enmod rewrite
sudo systemctl restart apache2
Go to your Symfony project's folder and install Apache pack
cd /var/www/html/symfony
composer require symfony/apache-pack
Now:
http://masch3/symfony/public/home -> ok

Related

Installation EasyAdmin on Symfony4

I try to install EasyAdminBundle on fresh install of Symfony4 from this doc https://symfony.com/doc/current/bundles/EasyAdminBundle/index.html
But I can't access to the back-end, I'm getting 404...
I just type composer require easycorp/easyadmin-bundle, and add my entity(Command) to framework.yaml
framework:
secret: '%env(APP_SECRET)%'
#default_locale: en
#csrf_protection: true
#http_method_override: true
# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: ~
#esi: true
#fragments: true
php_errors:
log: true
cache:
# Put the unique name of your app here: the prefix seed
# is used to compute stable namespaces for cache keys.
#prefix_seed: your_vendor_name/app_name
# The app cache caches to the filesystem by default.
# Other options include:
# Redis
#app: cache.adapter.redis
#default_redis_provider: redis://localhost
# APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
#app: cache.adapter.apcu
easy_admin:
entities:
# change the following to the namespaces of your own entities
- App\Entity\Command
When I check my routes with php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
easyadmin ANY ANY ANY /admin/
admin ANY ANY ANY /admin/
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
-------------------------- -------- -------- ------ -----------------------------------
Could some one enlighten me ?
Be wrong on the first line of configuration is so frustrating...
Maybe it help someone. I have same problem in symfony 4, check your /public directory, if missed .htaccess install composer require symfony/apache-pack and try again /admin
https://symfony.com/doc/current/setup/web_server_configuration.html
Well, I've installed without problem easy-admin in one SF4 proyect. Try those steps:
In config/routes/easy_admin.yaml:
easy_admin_bundle:
resource: '#EasyAdminBundle/Controller/AdminController.php'
prefix: /admin
type: annotation
In config/packages/easy_admin.yaml write (and delete it from framework.yaml):
easy_admin:
entities:
- App\Entity\Command
When you install easy-admin you must have this line in your bundles.php file:
EasyCorp\Bundle\EasyAdminBundle\EasyAdminBundle::class => ['all' => true],
On the other hand you have some yaml syntax error in your framework.yaml file.

VVV, custom site url redirecting to dashboard

I've just installed and setup VVV with Vagrant and Virtual Box, everything at the base level is working perfectly.
I've tried adding a custom site, as per their example, but when I navigate to the custom sites' URL(vvvtest.dev) I get sent to the VVV dashboard instead of the WP install process for the new site.
I'm using vagrant-hostsupdater so the hosts file is getting populated for me as well as vagrant-triggers.
Any help would be greatly appreciated!
EDIT: I've noticed in my hosts file that vvvtest.dev is pointing to the same location(sim link?) as vvv and vvv.dev, see screenshot. Where have I gone wrong during config ?
My vvv-custom.yml file stored in the main folder (vagrant-local):
sites:
# The wordpress-default configuration provides a default installation of the
# latest version of WordPress.
wordpress-default:
repo: https://github.com/Varying-Vagrant-Vagrants/vvv-wordpress-default.git
hosts:
- local.wordpress.dev
# The wordpress-develop configuration is useful for contributing to WordPress.
wordpress-develop:
repo: https://github.com/Varying-Vagrant-Vagrants/vvv-wordpress-develop.git
hosts:
- src.wordpress-develop.dev
- build.wordpress-develop.dev
# Custom Install Test
vvvtest:
hosts:
- vvvtest.dev
# The following commented out site configuration will create a standard WordPress
# site in www/example-site/ available at http://my-example-site.dev.
#example-site:
# repo: https://github.com/Varying-Vagrant-Vagrants/custom-site-template.git
# hosts:
# - my-example-site.dev
# The following commented out site configuration will create a environment useful
# for contributions to the WordPress meta team:
#wordpress-meta-environment:
# repo: https://github.com/WordPress/meta-environment.git
utilities:
core:
- memcached-admin
- opcache-status
- phpmyadmin
- webgrind
My nginx.conf file stored in www/vvvtest/provision:
server {
listen 80;
listen 443 ssl;
server_name vvvtest.dev;
root {vvv_path_to_site};
error_log {vvv_path_to_site}/log/error.log;
access_log {vvv_path_to_site}/log/access.log;
set $upstream {upstream};
include /etc/nginx/nginx-wp-common.conf;
}
My vvv-init.sh file, stored in www/vvvtest/provision
#!/usr/bin/env bash
# Add the site name to the hosts file
echo "127.0.0.1 ${VVV_SITE_NAME}.local # vvv-auto" >> "/etc/hosts"
# Make a database, if we don't already have one
echo -e "\nCreating database '${VVV_SITE_NAME}' (if it's not already there)"
mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS ${VVV_SITE_NAME}"
mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON ${VVV_SITE_NAME}.* TO wp#localhost IDENTIFIED BY 'wp';"
echo -e "\n DB operations done.\n\n"
# Nginx Logs
mkdir -p ${VVV_PATH_TO_SITE}/log
touch ${VVV_PATH_TO_SITE}/log/error.log
touch ${VVV_PATH_TO_SITE}/log/access.log
# Install and configure the latest stable version of WordPress
cd ${VVV_PATH_TO_SITE}
if ! $(wp core is-installed --allow-root); then
wp core download --path="${VVV_PATH_TO_SITE}" --allow-root
wp core config --dbname="${VVV_SITE_NAME}" --dbuser=wp --dbpass=wp --quiet --allow-root
wp core multisite-install --url="${VVV_SITE_NAME}.local" --quiet --title="${VVV_SITE_NAME}" --admin_name=admin --admin_email="admin#${VVV_SITE_NAME}.local" --admin_password="password" --allow-root
else
wp core update --allow-root
fi
Hosts File:
In your www/vvvtest/provision/nginx.conf file, maybe you can try to revise the directory of root to:
root {vvv_path_to_site}/public_html;
Hope it helps.

Gitlab on an OpenVZ Server with nginx - Authentication Required popup

I am experiencing an issue where trying to access GitLab through my browser is providing me with a popup for Authentication. It looks like a .htaccess authentication popup, but I have not configured htaccess authentication with my nginx configuration.
Authentication Required
The server at http://git.servername.com:80 requires a username and password.
The server says: Password Protected.
Username:
Password:
I have tried troubleshooting this issue for a couple of days now, but I am running into some dead ends, since I see no information in my nginx error logs, or my GitLab production.log.
I recently performed an installation of GitLab on Ubuntu 12.04 (following this guide: https://www.digitalocean.com/community/articles/how-to-set-up-gitlab-as-your-very-own-private-github-clone), and ran into some issues with not having enough memory on OpenVZ. I created some fake swap to get over this hurdle, and I have verified that the GitLab server is running. My verification and configuration information is as follows:
GitLab Verification
user#server:/home/git/gitlab$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
Checking Environment ...
Git configured for git user? ... yes
Has python2? ... yes
python2 is supported version? ... yes
Checking Environment ... Finished
Checking GitLab Shell ...
GitLab Shell version >= 1.7.0 ? ... OK (1.7.0)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
post-receive hook up-to-date? ... yes
post-receive hooks in repos are links: ... can't check, you have no projects
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Checking Sidekiq ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
Projects have satellites? ... can't check, you have no projects
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/bin/git"
Git version >= 1.7.10 ? ... yes (1.9.1)
Checking GitLab ... Finished
Environment Info
user#server:/home/git/gitlab$ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System: Ubuntu 12.04
Current User: git
Using RVM: no
Ruby Version: 2.0.0p247
Gem Version: 2.0.3
Bundler Version:1.6.0
Rake Version: 10.1.0
GitLab information
Version: 6.0.2
Revision: 10b0b8f
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://git.servername.com
HTTP Clone URL: http://git.servername.com/some-project.git
SSH Clone URL: git#git.servername.com:some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 1.7.0
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
Nginx Configuration
In my default.conf file:
server {
listen 80;
server_name git.servername.com;
location / {
proxy_pass http://git.servername.com:80;
}
}
Hosts file on my personal machine (not my VPS)
<IP Address of VPS> git.servername.com

Symfony2 Extension - Behat Mink

I installed a Symfony2 extension for Behat Mink from here
When I run test, an error occurs
[ReflectionException] Class AppKernel does not exist.
What am I doing wrong?
behat.yml
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://localhost/behat
goutte: ~
selenium2: ~
Behat\Symfony2Extension\Extension: ~
First run these commands to install the dependencies:
composer require behat/behat
composer require behat/symfony2-extension
composer require behat/mink
composer require behat/mink-browserkit-driver
composer require behat/mink-extension
composer require behat/mink-goutte-driver
composer require behat/mink-selenium2-driver
composer require emuse/behat-html-formatter
composer require coduo/php-matcher
Now say your symfony applcation you want to host as localhost.behat, then add the vhost configuration to httpd_vhost.conf:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/behat/web"
ServerName lochost.behat
DirectoryIndex app_dev.php
<Directory "C:/xampp/htdocs/behat/web">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Now your behat.yml file should be at app/config/behat.yml with belo content :
default:
formatters:
html:
output_path: web/behat
extensions:
Behat\Symfony2Extension: ~
# Irs\BehatPopupExtension\Extension: ~
Behat\MinkExtension:
base_url: http://lochost.behat/app_dev.php/
javascript_session: selenium2
sessions:
symfony2:
symfony2: ~
selenium2:
selenium2:
browser: chrome
emuse\BehatHTMLFormatter\BehatHTMLFormatterExtension:
name: html
renderer: Twig,Behat2
file_name: index
print_args: true
print_outp: true
loop_break: true
suites:
api:
type: symfony_bundle
bundle: NameSpaceYourBundle
#mink_session: symfony2
mink_session: selenium2
contexts:
- NameSpace\YourBundle\Features\Context\FeatureContext:
baseUrl: http://lochost.behat/app_dev.php/
screenCapturePath: web/behat
# Add "-p firefox" parameter to behat command to run tests with Firefox browser
firefox:
extensions:
Behat\MinkExtension\Extension:
browser_name: firefox
# Add "-p chrome" parameter to behat command to run tests with Chrome browser
chrome:
extensions:
#Behat\MinkExtension\Extension:
Behat\MinkExtension:
browser_name: chrome
# Add "-p safari" parameter to behat command to run tests with Safari browser
safari:
extensions:
Behat\MinkExtension\Extension:
browser_name: safari
All you go, now add your feature and context file at namespace : NameSpace\YourBundle\Features\Context\FeatureContext
and run the below commands from command prompt/git bash(preferrable):
bin/behat -v --suite=api #NameSpaceYourBundle/your.feature --config=app/config/behat.yml -f pretty
or if you want to save the output as html at web/behat directory then:
bin/behat -v --suite=api #NameSpaceYourBundle/your.feature --config=app/config/behat.yml
Let me know if it works
Note:
I am not sure if you are running selenium server or standalone server, hence adding the step to run selenium standalone server:
Download selenium and chromedriver and place the selenium server .exe and chromedriver.exe in same folder
check with "java -version" and it should not be < 1.6.x
you may need to download compatible selenium server and chrome driver
open command prompt and run the below commands:
cd C:\<folder contains selenium server .exe and chromedriver.exe>
java -Dwebdriver.chrome.driver="chromedriver.exe" -jar selenium-server-standalone-x.xx.0.jar

Rails production - all pictures are broken after new deploy

I followed the Ryan's screencast and deployed to VPS. So i use Unicorn + nginx + github + Ubuntu 12.04 LTS + capistrano. Also i use i18n to translate application.
I also would like to notice that i use Carriarewave for picture uploading. Carriarewave keeps pictures on VPS locally. When i upload images it works great and uploaded pictures appear.
But each time when i deploy new changes to the server then ALL my pictures become broken. It's really awfull. I tried manually to restart nginx:
sudo service nginx restart
And i tried to restart Unicorn:
/etc/init.d/unicorn_Chirch_app restart
It doesn't help too.
When i try to open my broken page manually it says:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
When i try to find pictures in console:
> Photo.all
> => [#<Photo id: 3, description: nil, created_at: "2013-01-21 11:14:01", updated_at: "2013-01-21 11:14:01", image: "1320700703588.jpg">, #<Photo id: 4, description: nil, created_at: "2013-01-21 11:14:01", updated_at: "2013-01-21 11:14:01", image: "Seasonscape_by_alexiuss.jpg">, #<Photo id: 5, description: nil, created_at: "2013-01-21 11:30:30", updated_at: "2013-01-21 11:30:30", image: "Seasonscape_by_alexiuss.jpg">]
As i understand they should exist.
Error from logs:
Started GET "/ru/uploads%2Fphoto%2Fimage%2F4%2FSeasonscape_by_alexiuss" for 89.178.205.47 at 2013-01-21 11:31:17 +0000
ActionController::RoutingError (No route matches [GET] "/ru/uploads%2Fphoto%2Fimage%2F4%2FSeasonscape_by_alexiuss"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.4) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.4) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
railties (3.2.8) lib/rails/railtie/configurable.rb:30:in `method_missing'
unicorn (4.5.0) lib/unicorn/http_server.rb:552:in `process_client'
unicorn (4.5.0) lib/unicorn/http_server.rb:628:in `worker_loop'
unicorn (4.5.0) lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
unicorn (4.5.0) lib/unicorn/http_server.rb:511:in `maintain_worker_count'
unicorn (4.5.0) lib/unicorn/http_server.rb:277:in `join'
unicorn (4.5.0) bin/unicorn:121:in `<top (required)>'
/home/deployer/apps/My_app/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load'
/home/deployer/apps/My_app/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>'
My config/deploy.rb
require "bundler/capistrano"
server "my_ip_here", :web, :app, :db, primary: true
set :application, "My_app"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#github.com:MyName/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
Ok, I found the solution. The problem appeared because I didn't change the default folder to keep images. You can find your default folder in public/uploads. That means that each cap deploy will create a new empty folder which doesn't contain your older files.
To fix this you should create another folder which doesn't live in your application. I choose the easiest way. I created symlinlk.
My steps:
1) On your server go to your app's shared folder (it generated automatically via capistrano). And then create your folder to keep new images:
$ mkdir uploads
2) Give necessary rights for a created folder:
$ sudo chmod 775 uploads
3) On your local machine in config/deploy.rb add:
task :symlink_config, roles: :app do
...
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
4) Then push git and deploy:
$ git push
$ cap deploy:symlink
$ cap deploy
Now everything works fine.
Good one! I've extended your capistrano recipe.
# config/recipes/carrierwave.rb
namespace :carrierwave do
task :uploads_folder do
run "mkdir -p #{shared_path}/uploads"
run "#{sudo} chmod 775 #{shared_path}/uploads"
end
after 'deploy:setup', 'carrierwave:uploads_folder'
task :symlink do
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
after 'deploy', 'carrierwave:symlink'
end
#ExiRe & #Charlie answer works on Capistrano 2.x. In Capistrano 3.x, command run replaced with command execute.
So, I solved this with the following steps:
Create a rake file in the directory lib/capistrano/tasks/carrierwave.rake with the content:
namespace :carrierwave do
task :uploads_folder do
on roles(:app) do
execute "mkdir -p #{shared_path}/uploads"
execute "#{sudo} chmod 775 #{shared_path}/uploads"
end
end
task :symlink do
on roles(:app) do
execute "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
end
end
Add the following line at the end of your Capfile if it's doesn't have it.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Add these tasks in config/deploy.rb with other tasks.
after 'deploy:publishing', 'carrierwave:uploads_folder'
after 'deploy:publishing', 'carrierwave:symlink'
namespace :deploy do
..
after 'deploy:publishing', 'carrierwave:uploads_folder'
after 'deploy:publishing', 'carrierwave:symlink'
..
end
Push git and deploy
Now your uploaded image will remain saved in shared/uploads folder after even new deploy.

Resources