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:
Related
I have a Symfony project with the file index.php in /var/www/public.
I want to only allow access to the website using a virtual generate folder, so the site should always be accessed like this: http://localhost/generate.
http://localhost/ should just throw a 404.
I'm using the following Apache config, but the $_POST and $_GET globals are missing when I debug my script (I'm firing a POST request from Postman). It works when I reset my Apache config to just serve from the root without any alias..what is going on?
I'm not using any .htaccess files in my /var/www/public folder.
The Apache config:
<VirtualHost _default_:80>
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<FilesMatch ".+(\.php)$">
SetHandler "proxy:fcgi://127.0.0.1:9100/
</FilesMatch>
DocumentRoot "/var/www/public"
Alias /generate /var/www/public
<Location /generate>
AllowOverride All
</Location>
</VirtualHost>
Since you are using Symfony, you can simply define routes for /generate and nothing for /
routes.yaml
Generate:
path: /generate
controller: ControllerNamespaceAndName::MethodName
Because you don't use route definition for / when accessing http://localhost/, symfony's kernel will throw a 404
I try to run very basic php app using apache and docker compose and have a problem with apache settings. When I try to access any static file in subdirectory I get lack of permissions. PHP calls seem to work fine.
So:
when I try to request localhost/LICENSE.txt I get the license.
when I try to access localhost/test.php or localhost/app/test.php it works fine
when I try to access localhost/app/test.html I get Forbiddenin
the browser andclient denied by server configuration:
/var/www/localhost/htdocs/src/app/test.html` in error log
Of course files I try to request are in the right locations.
Here's apache version I am trying to run:
/var/www/localhost/htdocs # httpd -v
Server version: Apache/2.4.33 (Unix)
Server built: Mar 27 2018 11:32:10
Here's my host config:
<VirtualHost *:80>
ServerAdmin test#example.com
DocumentRoot /var/www/localhost/htdocs/src
ServerName schmidt.local
<Directory "/var/www/localhost/htdocs/src">
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
RewriteEngine On
</Directory>
<LocationMatch "^/(.*\.php(/.*)?)$">
ProxyPass fcgi://php-fpm:7000/var/www/localhost/htdocs/src/$1
</LocationMatch>
</VirtualHost>
So as you can see I already have request instead of allow as suggested here.
I have Laravel project and can run it with
php artisan serve
I am executing this command inside D:\Users\Dims\Design\MyApplication directory. After that I can see site on http://localhost:8000 and can navigate it, although slow.
Now I am configuring the same place to serve by apache:
<VirtualHost *:80>
ServerAdmin webmaster#myapplication.app
DocumentRoot "D:\Users\Dims\Design\MyApplication\public"
ServerName myapplication.app
ErrorLog "logs/myapplication-error.log"
CustomLog "logs/myapplication-access.log" common
<Directory />
AllowOverride none
Require all granted
DirectoryIndex index.php
</Directory>
</VirtualHost>
Not, that I pointed application not to the root of the project, but to the public directory. This makes me able to open home page of the site, but clicking any links causes error 404.
If I serve
DocumentRoot "D:\Users\Dims\Design\MyApplication"
with Apache, I am unable to see home page at all, saying 403 forbidden. This probably because this directory has no index.php.
So, is it possible to serve Laravel project with Apache?
Yes, it's absolutely possible to serve Laravel applications with Apache. To debug why your links are producing 404 errors, you'll have to provide more information about the URLs these links point to. It's best to always use Laravel's url(), secure_url() or route() helper functions when printing URLs. Also confirm that the Apache module mod_rewrite is enabled (Laravel Installation: Web Server Configuration)
Set up the apache server host file as shown below:
<VirtualHost *:80>
ServerAdmin user#email.com
DocumentRoot D:\Users\Dims\Design\MyApplication\public
ServerName exampledomain.com
ServerAlias www.exampledomain.com
ErrorLog "C:/some_dir/example.error.log"
CustomLog "C:/some_dir/example.access.log" combined
<Directory "D:\Users\Dims\Design\MyApplication\public">
Options -Indexes
DirectoryIndex index.php index.html
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Now that you have set the server name to exampledomain.com you also need to set up the hosts(DNS) file in windows so that you can type in exampledomain.com in your browser and access your laravel project.
Editing the hosts file:
Please follow the steps below:
Press the Windows key.
Type Notepad in the search field.
In the search results, right-click Notepad and select Run as
administrator.
From Notepad, open the following file:
c:\Windows\System32\Drivers\etc\hosts
Make the following changes to the file.
At the end of the file add the following line:
127.0.0.1 exampledomain.com www.exampledomain.com
Click File > Save to save your changes.
What we did here was to tell windows that when we try to access exampledomain.com or www.exampledomain.com do not try to find the server over the internet but take the request to the local machine itself(127.0.0.1) which will in return serve your laravel project.
You can also find one another method here at wikihow -> http://www.wikihow.com/Install-Laravel-Framework-in-Windows
If after configuring the virtualhost you're still unable visit your laravel app, but it works fine with artisan serve, check your apache php version:
Check /etc/apache2/mods-enabled and if the php module is lower than the one required in laravel specifications, update it. In my case:
$ a2dismod php7.0
$ a2enmod php7.2
$ service apache2 reload
Solution found at: https://laracasts.com/discuss/channels/laravel/unexpected-illuminatesupportarrphp-on-line-388
I have just gone through the Symblog tutorials on http://tutorial.symblog.co.uk/docs/customising-the-view-more-with-twig.html
In prod mode, if i access the url like so:
http://local.mysite.co.uk
I get the home page with links to all the blog posts.
However if i click one of the blog posts then I get a 404, in fact any of the links (to the about or contact) all return a 404, eg:
http://local.mysite.co.uk/12/a-day-with-symfony2
If I then access the prod mode via the app_dev.php all the links work again, ie:
http://local.mysite.co.uk/app.php/12/a-day-with-symfony2
I have run to ensure the mod rewrites should be working and restarted apache but no joy.
sudo a2enmod actions
Does anyone know why this might be happening?
Thanks,
John
PS: This is the current vhost file for the dev site i am learning with (Ubuntu lts, apache 2.4, php 5.4ish)
<virtualhost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster#domain.com
ServerName mysite.co.uk
ServerAlias www.mysite.co.uk
ServerAlias local.mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex app.php
DocumentRoot /var/webroot/www/vhosts/mysite.co.uk/htdocs/Symfony/web/
# Custom log file locations
LogLevel warn
ErrorLog /var/webroot/www/vhosts/mysite.co.uk/log/error.log
CustomLog /var/webroot/www/vhosts/mysite.co.uk/log/access.log combined
</virtualhost>
When I add an AllowOverride All to the vhost file and restart apache I get the follwoing error:
* Starting web server apache2
*
* The apache2 configtest failed.
Output of config test was:
AH00526: Syntax error on line 15 of /etc/apache2/sites-enabled/mysite.co.uk.conf:
AllowOverride not allowed here
Action 'configtest' failed.
The Apache error log may have more information.
Altering the vhost worked (thanks to https://stackoverflow.com/users/308825/maerlyn).
Placing a directory tag with the Allowoverride All fixed the issue. Seems that the rewrites are specific to each vhost.
Here is my config for the symfony tutorial which is now functioning in prod mode:
<directory /var/webroot/www/vhosts/mysite.co.uk/htdocs/Symfony/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</directory>
<virtualhost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster#domain.com
ServerName mysite.co.uk
ServerAlias www.mysite.co.uk
ServerAlias local.mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex app.php
DocumentRoot /var/webroot/www/vhosts/mysite.co.uk/htdocs/Symfony/web/
# Custom log file locations
LogLevel warn
ErrorLog /var/webroot/www/vhosts/mysite.co.uk/log/error.log
CustomLog /var/webroot/www/vhosts/mysite.co.uk/log/access.log combined
</virtualhost>
Greetings experts and gurus, I am looking for some help with an apache php configuration problem.
I have been running several websites from an apache2 setup on an ubuntu server for some time now without problems using the line NameVirtualHost * in my etc/apache2/conf.d/virtual.conf file. I recently updated the server version to the latest lts version and I am now unable to run php files.
I am running all my sites for the location "/home/www/[site-name]/htdocs" and I have setup and enabled all my sites in /etc/apache2/sites-available. I have also disabled the default site.
for each sites file I have specified the following:
# Indexes + Directory Root.
# DirectoryIndex index.html index.htm index.php
DocumentRoot /home/www/[site-name]/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ /home/www/[site-name]/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog /home/www/[site-name]/logs/error.log
CustomLog /home/www/[site-name]/logs/access.log combined
I restart apache and enter the url for a php test page on my server and I am met with an "Internal Server Error". When I check the error log I get:
Script "/home/www/[site-name]/htdocs/test.php" resolving to "/home/www/[site-name]/htdocs/test.php" not within configured docroot.
For some reason when looking into the error, suphp came up a lot. According to this link:
Don't be fooled into thiking this has anything to do with the Apche virtual host document root, this is actually another setting in the suphp config file. Including the paths which contained the RoundCube scripts fixed this one. For example:
docroot=/var/www:/usr/share/roundcube:/var/lib/roundcube:${HOME}/public_html
You need to edit your /etc/suphp/suphp.conf file and change the docroot to whatever is appropriate.
It looks you missed the virtual hosts configuration for every site name:
<VirtualHost IP:80>
ServerName yourdomainname
ServerAlias www.yourdomainname
DocumentRoot /home/www/[site-name]/htdocs/
ScriptAlias /cgi-bin/ /home/www/[site-name]/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
ErrorLog /home/www/[site-name]/logs/yourdomainname.ua-error.log
CustomLog /home/www/[site-name]/logs/yourdomainname-access.log combined
</VirtualHost>
<Directory "/home/www/[site-name]/htdocs/">
Options FollowSymLinks
AllowOverride None
Order allow,deny
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
Thanks for all the help, I got there in the end. It seems that upgrading to Ubuntu 10.04 turned on suPHP. It has ended up being a good thing as the reason why I was getting errors was down to file management in my htdocs getting sloppy.
To fix my issues I had to do several things:
First I turned on suphp error messages in /etc/apache2/sites-available/[site-name]. This gave me the true error, which told me that some of my pages had the wrong permissions. I then set all my folder permissions in www to 755 and the files to 644. I also had to lower the min_uid and min_gid fileds in suphp.conf to 33.