I developped a site with sympfony/phpp i want to deploy on a local server.
After the development on my own computer (where it works well), I put the project on a local server with apache, php 7.3.x, composer 2.0.0 under a debian 10 OS
All the transfer of the project from my computer to the server and the setting are well finished.
The project folder name is si2a. It is in the directory /var/www
I set the permissions access on this directory with ACL following a symfony doc guideline.
I set the site configuration file those the name is si2afama.conf. This last is in the directory /etc/apache2/sites-available. After setting, I activate the site, reload apache and clear the cache. Here is the si2afama.conf's contain :
<VirtualHost *:80>
ServerName si2afama
# ServerAlias www.si2afama.com
DocumentRoot /var/www/si2a/public
DirectoryIndex /index.php
<Directory /var/www/si2a/public>
AllowOverride All
Require all granted
Allow from All
FallbackResource /index.php
</Directory>
<Directory /var/www/si2a/public/bundles>
FallbackResource disabled
</Directory>
ErrorLog /var/log/apache2/si2a_error.log
CustomLog /var/log/apache2/si2a_access.log combined
</VirtualHost>
When i try to access the site, i found this error :
No route found for "GET /si2afama"
Since, it is a Routing issus, here are some files's contain :
si2a/config/packages/routing.yaml
framework:
router:
utf8: true
si2a/config.routes.yaml
index:
path: /
controller: App\Controller\DefaultController::index
si2a/public/index.php.
<?php
use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I don't really know what to do in order to fix the issus.
May someone help me, please. Thank you.
Your vhost is related to your domain name and directory of source code,
if you want a route name like si2afama for your application, you have to add it to symfony routes.
# si2a/config.routes.yaml
index:
path: /
controller: App\Controller\DefaultController::index
si2afama:
path: /si2afama
controller: App\Controller\DefaultController::nameActionFromController
try to install this package composer require symfony/apache-pack it will create a .htaccess file that'll fix your problem
Related
I just started learning Symfony and try create 1th application by article https://symfony.com/doc/current/page_creation.html
WebServer: Apache 2.4.41
Server: Ubuntu 20
PHP: 7.4.3
I created domain on server symfony.
Installed in /var/www/html/symfony/ by command symfony new --full ./
Add required files (controller and write route to config/routes.yaml). Installed composer require symfony/apache-pack.
Execute $ php bin/console debug:router:
Name
Method
Scheme
Host
Path
...
app_lucky_number
ANY
ANY
ANY
/lucky/number
Opened in browser http://server.ip/symfony/lucky/number and get 404 Apache error.
Opened in browser http://server.ip/symfony/public/ and OK.
Opened in browser http://server.ip/symfony/public/index.php/lucky/number and OK.
Apache config in /etc/apache2/.../symfony.conf:
<VirtualHost *:80>
ServerName symfony
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/symfony/public
<Directory /var/www/html/symfony/public>
Options FollowSymlinks
Require all granted
#AllowOverride All
Order Allow,Deny
Allow from All
#FallbackResource /index.php
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
mod_rewrite is enable.
Anybody have any ideas how to fix it?
You need to add .htaccess in your project.
If you will use only apache configuration, you will be enabled FallbackResource index.php in your Directory
Following this configuration : https://symfony.com/doc/current/setup/web_server_configuration.html
See section : Use the following optimized configuration to disable .htaccess support and increase web server performance:
I'm new to the symfony framework and not good at php, and I've come to task of running an existing backup of project.
To get in touch with it, I've run a debian 8 server on virtual machine locally.
To make sure I know how symfony works I decided to run the symfony demo.
The problem is I'm not sure if I'm configuring it well with apache2, as I've followed the guide on symfony's site.
I've installed the symfony demo under /var/www/html/symfony_demo
This is my sites-avaliable
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/symfony_demo/web
<Directory /var/www/symfony_demo/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I've executed php bin/console server:start from the symfony_demo directory.
Web server is up and running on the default 127.0.0.1:8000.
When trying to access the apache2 default index.html before the changes to sites-avaliable, under :80 it was all okay. My 192.168.0.100 was accessible just okay from the browser. But after changing the configuration, and trying to get to 192.168.0.100:8000 I get unable to connect.
I need help troubleshooting this because I dont know where to seek for problem. Ask anything.
See your .htaccess config in the /var/www/symfony_demo/web directory and look if app.php is config as DirectoryIndex. Maybe you need to add DirectoyIndex to your config because Apache is searching for index.html or index.php but not for app.php:
DocumentRoot /var/www/symfony_demo/web
<Directory /var/www/symfony_demo/web>
DirectoryIndex app.php
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
What to do from this point?
edit app_dev.php ( as mentionned is your error )
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
add your ip to
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
or comment th whole block
I need host a laravel app in http://example.com/laraproject , i cant use the simple domain example.com , i try to setup my virtualhost on apache, .env file but :
Examples:
VirtualHost apache
ServerName example.com
ServerAlias example.com
ServerPath /larapoject
DocumentRoot /var/www/laraproject/public
DirectoryIndex index.php
<Directory "/var/www/laraproject/public">
Options -Indexes
AllowOverride All
Require all granted
</Directory>
.env file :
APP_ENV=dev
APP_DEBUG=true
APP_DOMAIN=example.com/laraproject/
APP_HOME=http://example.com/laraproject/
APP_STATIC=http://example.com/laraproject/
The default route works fine, but, the problem is when i try to redirect to others routes, for example.
For
example.com/laraproject load the home page .
For
example.com/laraproject/section1 not load the page, because not resolve the route for some reason.
Laravel version 5.1
Apache 2.4
PHP 5.5.3
Any idea ? I tried everything to resolve this problem but i cant .
Thanks at all .
I have deployed my application on my website and it works finally just fine.
However, I've made a second deployment with the multistage option of capifony, this one is called development as opposed to production.
Inside my development.rb file, I have set :
set :clear_controllers, false
so that the file app_dev.php does not get removed. Indeed it is available but it does not launch by default despite the following virtual host config:
<VirtualHost *:80>
ServerName test.sebastienvassaux.com
DocumentRoot /var/www/mysite.com/development/current/web
DocumentRoot /var/www/mysite.com/development/current/web
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mysite.com/development/current/web>
DirectoryIndex app_dev.php
Options -Indexes
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
So first question: how do I do for the mysite.com to load app_dev.php and not app.php ?
Then, if I manually enter the address mysite.com/app_dev.php, I get the following error :
ClassNotFoundException in AppKernel.php line 42: Attempted to load
class "SensioGeneratorBundle" from namespace
"Sensio\Bundle\GeneratorBundle". Did you forget a "use" statement for
another namespace?
Well, this error is not raised when I work locally in dev mode, why is it raised here? What can I do to further understand the issue?
Thanks a lot!
The problem is that composer has a section require-dev that is not gathered or added to the autoloader.
You can configure capifony to include the require-dev, prefrabily in you development.rb:
set :composer_options, "--dev --verbose --prefer-dist --optimize-autoloader --no-progress"
In conjuntion with set :clear_controllers, false you should be able to run app_dev.php
Hope that it helps
Following the documentation, Silex allows "slugs" to be passed in via the URL for use within your code.
The following example works:
$app = new Silex\Application();
$app->get('/', function () {
return 'HAI';
});
However, the following gives a 404 Not Found:
$app = new Silex\Application();
$app->get('/{slug}', function ($slug) {
return 'HAI' . $slug;
});
How can I fix this 404?
In case it's of any relevance, here's my Apache Vhost:
<VirtualHost 127.0.0.1:80>
DocumentRoot "/var/www/Silex/web"
DirectoryIndex index.php
<Directory "/var/www/Silex/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
...and my directory structure:
/src
|-- bootstrap.php
/tests
/vendor
/web
|-- index.php
It turns out that this was an Apache issue. It was assumed that you could either use a .htaccess file, or a vhost. You actually need to use both.
.htaccess:
FallbackResource /index.php
Note: You can only use FallbackResource if using Apache 2.2.16 or higher.
vhost
<VirtualHost 127.0.0.1:80>
DocumentRoot "/var/www/Silex/web"
DirectoryIndex index.php
<Directory "/var/www/Silex/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
An alternative is to place the contents of the .htaccess file (the FallbackResource directive) within the vhost itself, and get rid of the htaccess.
As soon as I added the .htaccess, the slug in my second example worked.