I've created a simple Zend Framework 1.12 test app via the zf.bat on my windows machine (xampp, php5.3): "zf create project testapp"
After that i've created an new controller called 'FoobarController' next to the 'IndexController'.
Now I can switch between these urls:
localhost/projects/testapp/public/
localhost/projects/testapp/public/index
localhost/projects/testapp/public/foobar
Now I have uploaded the whole testapp into the web server directory of my raspberry pi (192.168.1.100, Apache2, PHP5.3, ModRewite On, AllowOverride All).
This urls are working fine when I call the raspberry from the windows machine:
192.168.1.100/sites/testapp/public
192.168.1.100/sites/testapp/public/foobar
This one will display: "The requested URL /sites/testapp/public/index was not found on this server"
192.168.1.100/sites/testapp/public/index
Has someone an idea why the url to the "index" controller wont work properly on my raspberry? (I did nothing more than the explained steps)
/etc/apache2/sites-available/default:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/var/www/html"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess:
RewriteEngine On
RewriteBase /sites/testapp/public
# 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 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
Related
I need some help with configuring Symfony on apache2 web server.
My current project category structure is:
var/www/domain.com/public_html
Inside public_html is where my Symfony application is located.
I am stuck at figuring our what I am doing wrong in my either .htaccess or /etc/apache2/sites-available/domain.com.conf files.
I am using symfony/apache-pack. My .htaccess files live inside /public folder as per documentation. Here it is:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
And here is my /etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80>
ServerAdmin someemail#example.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/mydomain.com/public_html/public>
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I also read this and updated 000-default.conf as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/domain.com/public_html/public>
Options FollowSymlinks MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
</IfModule>
</VirtualHost>
For the moment I am still seeing symfony project folder structure.
I tried:
inside .htaccess changing DirectoryIndex to /public/index.php
inside .conf file changin DocumentRoot to /va/www/domain.com/public_html/public
tried clearing cache
SO far nothings seems to help.
Would be extremely helpful for any advice.
I see that you are editing vhost which begins with
<VirtualHost *:80>......
That mean your website should be reachable by 80 port or in other words by http protocol. But! If in reality you are accessing your website by https protocol then make sure you are editing right Apache2 .conf file.
If the website is reachable by https protocol (especially if you use LetEncrypt), then try locating /etc/apache2/sites-available/....-le-ssl.conf config file (or similar one with corresponding domain title and with ssl prefix or postfix in it's name).
After editing that file do not forget to restart Apache2 webserver with $sudo service apache2 restart and test website again.
I have a website made with Symfony 2.8.22 running with Apache 2.4.18. I have RewriteEngine activated in the virtualhost to not show the .php extension in the url. However I have 2 problems. The first one is I do get the .php extension via url. The second problem is I have a loop in the login page; once I input the credentials it reloads the same login page again, and again. That happens in Chrome and Firefox, however in Microsoft Edge that loop wont happen, it just follow to the next page.
Why is that?
Where's my virtualhost file:
<VirtualHost *:80>
ServerName ip.ip.ip.ip
DocumentRoot /var/www/html/website/web
<Directory /var/www/html/website/web>
AllowOverride All
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule (.*)\.php $1 [R=301,L]
</IfModule>
</Directory>
<Directory /var/www/project>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/error_website.log
CustomLog /var/log/apache2/access_website.log combined
</VirtualHost>
Thanks in advance.
Best regards.
I am not certain why you are trying to forcably remove .php from the web address bar. If you follow the Symfony Configuration guide it will give you an .htaccess file that works and will not display .php extensions:
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</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>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/project/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I have the following problem:
I want to remove .php and .html extention from url of my website.
The URL is localhost/MySiteDir/MySitePage.php and I want to obtain localhost/MySiteDir/MySitePage.
I am following this:
https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/
& this
How to remove file extension from website address? guides.
So I created a .htaccess file on my MySiteDir and I put this code on this file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
But it doesn't work.
I have changed etc/apache2/sites-enabled/000-default.conf file adding
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
in this way:
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
and in my .htaccess file I put:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
when I try to access my website I receive a 404 Error.
I was making a .htaccess file to run a framework that I was testing, but when I tried to access to my localhost, the folder where is located the framework's files didn't show up.
If I try to access, requesting the localhost/my_hidden_folder/ this fires a 500 error, internal server error.
This behaviour is result of some wrong configuration with my apache|.htaccess, I'm pretty sure because the same .htaccess in another server works fine.
Here is my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
And here is my default file from /etc/apache2/sites-available:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /var/www/entrega2>
AllowOverride All
</Directory>
<Directory /var/www/unlp>
AllowOverride All
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Both folders, /var/www/unlp and /var/www/entrega2 have the same .htaccess file, and both are hidden.
The most basic redirect in the .htacces file doesn't work, in my localhost, but in the server works. Maybe I have a module disabled?
Is there a +FollowSymlinks in .htaccess? This usually does the 500 error on Linux systems that have already activated the option or on Windows.
Try to run phpinfo() to make sure the mod-rewrite is activated.
Create simple php file in your web root folder, which contains:
<?php
phpinfo();
?>
i have the resources shared with another project. The pictures of the products i will show, are stored in a folder out of my new project for which im using symfony...
In my symfony project, in the /web/images folder, i created a symbolic link to the folder where my pictures are stored. im sure the permissions of every file and folder under the pictures folder pointed by the symlink are setted 777, anyone can access to them.
Everything worked fine until i enabled the mod rewrite of apache. Pictures on the /web/images folder were shown perfectly, buy anything accessible through the symlink wasn't shown. I immediately thought the symlink was the reason of this behavior, and i checked my apache configuration for the site. Also, reading on symfony, i examined the .htaccess file under the /web folder and added the line:
Options FollowSymLinks
This didn't work either.
Here's my site configuration:
#<VirtualHost mydomain.com>
<VirtualHost *:80>
#ServerAdmin webmaster#localhost
ServerAdmin admin#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
#DocumentRoot /var/www
DocumentRoot /srv/www/mydomain.com/public_html/
<Directory />
Options FollowSymLinks
#AllowOverride None
AllowOverride All
Order allow,deny
allow from all
</Directory>
#<Directory /var/www/>
<Directory /srv/www/mydomain.com/public_html/>
Options Indexes FollowSymLinks MultiViews
#AllowOverride None
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
#AllowOverride None
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
#Options +ExecCGI -MultiViews +FollowSymLinks
Order allow,deny
Allow from all
</Directory>
#ErrorLog ${APACHE_LOG_DIR}/error.log
ErrorLog /srv/www/mydomain.com/logs/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
#CustomLog ${APACHE_LOG_DIR}/access.log combined
CustomLog /srv/www/mydomain.com/logs/access.log combined
Alias /sf /home/victor/projects/vitoquen/tienda/lib/vendor/symfony/data/web/sf
<Directory "/home/victor/projects/vitoquen/tienda/lib/vendor/symfony/data/web/sf">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
#Alias /doc/ "/usr/share/doc/"
#<Directory "/usr/share/doc/">
# Options Indexes MultiViews FollowSymLinks
# #AllowOverride None
# AllowOverride All
# Order deny,allow
# Deny from all
# Allow from 127.0.0.0/255.0.0.0 ::1/128
#</Directory>
</VirtualHost>
And here's my .htaccess:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
Options FollowSymLinks
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Any suggestions?? thanks for taking the time of reading and answering!!!
EDIT:
I tried the Znarkus' solution, and didnt work! this, i think, can mean that the symlink was not the problem.
Files in the pictures folder are stored without extention. Because of than, i cant use the image_tag() helper of symfony, which appends .png by default to the file name if no extention is given... this is the way im displaying images in my template:
if (strcmp($producto->foto, "SI") == 0) {
echo '<img src="/images/productos/'.$producto->id.'_muestra" width="102" height="84" alt="Imagen de muestra"/>';
} else {
echo '<img src="/images/no_picture.jpg" width="102" height="84" alt="Imagen de muestra"/>';
}
The strange thing is that /images/no_picture.jpg is shown perfectly. Thanks again for any help you can give me!!!
Symfony problably doesn't support symlinks. Try doing mount --bind instead, which should be transparent to the application.
Your updated question: You must have an extension for the <img /> tag to work.