Deploy symfony2 into a folder - symfony

As a symfony1.4 developer, I'm trying to learn Symfony2.
Now, instead of trying on my local machine, where all works fine, today I want to make my test site available on my server. But I don't want to deploy it on a real site or on a real subdomain.
And that's my question: how can I deploy this test on a subfolder without modify virtualhost?!
Lets say I have an available site, www.example.com, but I'd like to have my symfony test available (and working correctly) here www.exaple.com/mysymfonytest
Did somone already do that?
Thanks...

In my opinion that is not really a symfony related question.
Depending on your webserver you could configure an alias where which url should point.
In Apache you specify your document root, where you put your sf2 installation, and then define an alias which would be /mysymfonytest pointing to that document root.
Alternatively you could specify your document root, leave the url be and define a prefix for all routes in symfony, which you would do in your routing configuration.
I strongly recommend configuring your webserver though.
For example in apache:
<VirtualHost *:80>
DocumentRoot /var/www/mysymfonytest
Alias /mysymfonytest /var/www/mysymfonytest
<Directory /var/www/mysymfonytest/web>
AllowOverride None
Order allow,deny
Allow from all
#Allow from <SUPPORT>
RewriteEngine On
RewriteBase /mysymfonytest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</Directory>
</VirtualHost>
Alternatively, if you cannot add the VHost:
How to add a prefix to all my routes

make a sub-directory under / (root directory) and call it mysymfonytest then put your symfony2 project in mysymfonytest.
add a .htaccess file to mysymfonytest folder and put in it :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ web [L]
</IfModule>
or you can just make a file named index.html and make it point to app.php

If your only running on a shared hosting. You could use override configurations using .htaccess. Ask your provide if they allow overrides and then provide them the script or tell them what you want. Hope that's covered on your hosting support.

Related

Remove index.php from Wordpress URLs

I am new to Wordpress but tried all documentation and Stack Overflow posts for possible solutions but none of them have worked so far.
I have verified that mod rewrite is enabled and working as expected. Followed all steps mentioned here. https://wordpress.stackexchange.com/questions/105795/remove-index-php-from-permalinks
Also restarted Apache couple of times but still getting 404 errors when I remove index.php path from Permalink Settings.
Renamed the wordpress directory to blog to access the site at www.xyz.com/blog. Now the requirement is to access any blog posts with
www.xyz.com/blog/2018/02/09/my-wp-post without index.php in the URLs.
We don't have any other CMS content other than WP for the blog site.
Permalink settings(Custom Structure):
/index.php/%year%/%monthnum%/%day%/%postname%/
.htaccess file contents:
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I spent ton of time trying many different approaches answered here or elsewhere but none of them fixed my issue.
This is what I did and it has fixed my issue.
Change permalink settings to remove index.php
Update/Save .htaccess content that's at the root of the WP installation if it's not allowed to be updated automatically when we change permalink settings in WP admin panel.
This is the important step since not many Q & A mentioned this in detail, other than wordpress documentation here. Specifically check AllowOverride settings and change it to All, Apache httpd.conf will not load the .htaccess contents without this change. Of course mod_rewrite must be enabled in the server if it's not already done. In our case it's enabled by default, so didn't have to mess with this step.
Also make sure FollowSymLinks option enabled as mentioned in the WP documentation.
Last but not least, make sure you restart the Apache service/server for the changes to take effect.
Entry in httpd.conf file:
<Directory "/var/www/html/blog">
Options FollowSymLinks
AllowOverride All
Assuming Ubuntu 16.04 & Apache2
1) Activate mod_rewrite. It's available but not enabled with a clean Apache 2 installation.
sudo a2enmod rewrite
2) Restart Apache
sudo systemctl restart apache2.service
3) Setup .htaccess
(Note: Apache reccomends using a server configuration file over inserting rules into .htaccess, however, for this example, inserting rules into .htaccess is sufficient because of the negligible performance hit.)
sudo nano /etc/apache2/sites-available/000-default.conf
Insert the following in 000-default.conf
<VirtualHost *:80>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
4) Restart Apache
Repeat step 2
5) Create .htaccess in the web root.
touch /var/www/html/.htaccess
Insert the following into .htaccess
RewriteEngine On
6 Configure the URL Rewrite (Note: Assuming index.php)
sudo nano /var/www/html/.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
mod_rewrite is a useful Apache module that can be used effectively to ensure human-readable URLs and good SEO results. If you'd like to learn more about mod_rewrite, take a look at Apache's mod_rewrite Introduction and Apache's official documentation for mod_rewrite.
In a nutshell, as #Cnu as mentionned, the problem very few resources on the internet touch on is the fact that your apache configuration must contain an AllowOverride FileInfo directive for wordpress rewrites to work without /index.php/.
Since Apache 2.4, AllowOverride default setting is "None", which is often a roadblock in making "pretty urls" work (in this case ditching the index.php). As #cnu mentionned, you should read carefully this resource : https://wordpress.org/support/article/using-permalinks/.
Make sure to have mod_rewrite enabled
-> (to be sure create an info.php you will remove later containing the line <?php phpinfo();?>) at the root of your blog and call https://domainofyourb.log/info.php)
Make sure your .htaccess is writable by wordpress. (permission and ownership should be allowing your webserver (often with the username "apache") to edit the file.
Change your wordpress permalinks settings, and check that .htaccess file is correctly written.
Check that your apache configuration (etc/httpd/conf/httpd.conf in some linux distros) contains the directive AllowOverride FileInfo within your blog's <Directory></Directory> section
Options directive to FollowSymLinks should be the default, but if Options directive is mentionned, add FollowSymLinks for good measure.
when all that is done, don't forget to restart your Apache server. (sudo service httpd restart in my case, ymmv).
P.S : wrote this answer because I can't comment (don't have rep) on cnu's answer, and wanted to correct 1. allowoverride doesn't need to be set to ALL, it can be set to simply "FileInfo", 2. update the link to wordpress doc, and 3. provide background on the change in apache 2.4 that causes this issue.
Go to admin page, Dashboard -> Settings -> Permalink Settings -> Custom Structure, select /%postname%/ or, /%year%/%monthnum%/%day%/%postname%/ up to you.

Solving the WordPress permalink issue on a virtual server

I have a variation on the old WordPress problem regarding permalinks failing (404 errors) when permalinks are set to anything other than 'plain' (where plain = http://example.com/?p=123 and a 'pretty' URL = http://example.com/sample-post/ - taking the URL content from the article title, for example).
For the first time I am starting a site on a virtual rather than dedicated server (Hetzner hosted), where I at least was able to easily read the httpd.conf settings and other server configurations.
To recap here, the problem is that neither WordPress nor the default server settings are usually ready for the URL rewriting that allows 'pretty' URLs out of the box. When confronted with this problem before, on dedicated servers, I would ensure that AllowOverride was set to 'all' or '[directory]' and then would put in an .htaccess file into the web's document root with this traditional solver:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However this does not work on my Hetzner server. I put in the above code to an .htaccess file, set the permissions correctly and restarted. But the front page still shows links to the article lists, but the articles themselves all still throw that old 404 error.
The only access I have to the core server directives is drip-fed out in sections and radio-buttons etc via Plesk. I can't even open up the httpd settings read only to see how AllowOverride is set. Hetzner consider this a 'software problem', and therefore unsupported.
There is a section in Plesk where you can add additional Apache and Nginx directives (with duplicate boxes for http and https for Apache). I tried this in the Apache boxes and rebooted, but it didn't help (obviously this is not the actual URL I wrote):
<Directory "/var/www/vhosts/example.com/httpdocs/">
AllowOverride All
</Directory>
If anyone has any suggestions as to how I can get the usual rewrite fix in, in these circumstances, it would be much appreciated.
Okay, the problem was an obscure one, as it turned out. The virtual server was running Nginx on top of Apache, and I needed to install a plugin via Plesk which provides an 'ht access translator' for Nginx in Plesk. I pasted the rewrite directives there, they were 'translated' to Nginx-understandable commands, and the problem is solved.

Links not working in Wordpress 4.1

I have Wordpress 4.1 application on DigitalOcean.
After installation I found that any other link besides root/home link don't work.
I looked into similair questions and tried:
1) Change permalinks to default settings.
Now links partialy work. I mean they are ugly :http://104.131.95.146/?post_type=product instead of http://104.131.95.146/products
As suggested I did some troubleshooting from this link :
Pretty permalinks are available under:
Apache web server with the mod_rewrite module
But my server is Apache and I checked if mod_rewrite is aviable with:
apache2ctl -M | grep rewrite
got this message :
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
rewrite_module (shared)
Tried to restart apache and my droplet but still the same problem.
My htacces file inside var/www/html/.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help would be great.
Thanks in advance.
Once again fixed by myself.
I skipped important part of Wordpress installation.
What I did:
By default, this is 000-default.conf, but your file might be different if you created another configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Inside of this file, we want to set up a few things. We should set the ServerName and create a directory section where we allow overrides. This should look something like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName server_domain_name_or_IP
<Directory /var/www/html/>
AllowOverride All
</Directory>
. . .
When you are finished, save and close the file.
Next, we need to enable the rewrite module, which allows you to modify URLs. You can do this by typing:
sudo a2enmod rewrite
After you have made these changes, restart Apache:
sudo service apache2 restart

Set up CakePHP in a subdirectory; Wordpress is installed in the root

I have been searching for a solution for 2 hours but nothing seems to work... here is my problem:
I have WordPress installed in the root (var/www). So by going to http://www.geekderek.com, I see my wordpress site.
I put CakePHP in a subdirectory var/www/cakephp. I want to be able to see my CakePHP app by going to: www.geekderek.com/cakephp.
However, currently this url just returns a Wordpress page saying "Content not found."
I believe this problem can be solved by modifying .htaccess in my root directory. So here is my .htaccess: http://pastebin.com/sXJTRstB
As you can see, I added this line to the default WP .htaccess file:
RewriteRule ^cakephp(/(.*))?$ cakephp/app/webroot/$1 [QSA,L]
However, for some reason this doesn't seem to work.
Could anyone please tell me what is wrong?? Thank you so much!
I have simmilar setup, that my cake app is in subdirectory, my root .htaccess has this rewrite rule:
RewriteRule ^cakephp/(.*)$ /cakephp/$1 [L,QSA]
All the rest is handled with the regular cakephp setup.
my /cakephp/app/webroot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
hope this works for you too :)
thanat's answer almost worked for me. i just had to edit the RewriteBase to read
RewriteBase /cakephp
and make sure apache conf allowed my root directory to override its previous options
<Directory "/my/root/dir">
AllowOverride All
</Directory>
but then again, my app dir lies outside the DocumentRoot set by apache. and the cakephp dir is actually the webroot itself. so my dir structure is as follows
/my/root
/my/root/app #cake's app dir without webroot
/my/root/dir #apache DocumentRoot (your wordpress is here)
/my/root/dir/cakephp #cake's webroot
also make sure to edit /my/root/dir/cakephp/index.php so it knows where the app and cake's library dirs are.
This is my case, with laravel but they are the same.
https://community.bitnami.com/t/laravel-application-in-subdirectory-of-wordpress-website/79535/2
Just need to change
AllowOverride None => AllowOverride All

How to remove /drupal from URL in Drupal 7 when installation is in the associated sub-directory

In Drupal 6 I was able to successful install Drupal in a subdirectory called drupal and then reference the site without having to use example.com/drupal.
In Drupal 6 to get this to work I did the following:
- Created an .htaccess file in the root directory where /drupal was created. The file contents was:
Options -Indexes
RewriteEngine On
RewriteRule ^$ drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1
Updated the drupal/sites/default/settings.php file to have the $base_url defined as:
$base_url = 'http://example.com';
When I try and do the same thing for Drupal 7, only the front page can be displayed, all the pages fail quite horribly (or only display the front page). I have also tried uncommenting the RewriteBase lines in /drupal/.htaccess. First I tried RewriteBase /drupal and then tried RewriteBase /. But both attempts failed. I never needed to do this with D6, but I thought I would rule out this possible fix.
I am currently testing the new Drupal 7 install using xampp (version 1.7.4) with the example.com site under htdocs (i.e. xampp/htdocs/example.com/drupal). The Drupal 6 site is within the same xampp installation, but of course with a different directory path (e.g. xampp/htdocs/d6example.com/drupal). Note that I also have the Drupal 6 installation running on a production server with only the $base_url variable value changed.
So, how can you install Drupal 7 in a subdirectory and then run it from that directory without having the directory name in the URL?
Note I am installing Drupal 7 in a subdirectory as it allows for easier upgrading between new releases of the Drupal 7 core.
Try with this :
RewriteEngine On
RewriteBase /example.com
RewriteRule ^$ drupal/ [L]
# rewrite rules for drupal files
RewriteCond %{DOCUMENT_ROOT}/example.com/drupal/$1 -f
RewriteRule ^(.*)$ drupal/$1 [L,QSA]
# rewrite rules for drupal paths
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/index.php?q=$1 [L,QSA]
Put this .htaccess file in example.com directory.
You don't have to modify drupal7 .htaccess
On Apache server, add this to the root .htaccess file.
RewriteEngine on
RewriteRule (.*) drupal/$1 [L]
Update the drupal settings.php file (in /drupal/site/default/ directory) so that the $base_url line reads:
$base_url = 'http://www.example.com';
I answered a very similar question on this here:
Two Drupal installation on the same server
My answer to your question is the same, I recommend eschewing the rewrite method in favor of the virtual host method as described below (which is just an excerpt of what I answered in the link above):
...
To do this correctly you must first enter the following line (or un-comment the line if >it already exists):
NameVirtualHost *:80
Next you must create the two virtual host entries. One will be similar to the following:
<VirtualHost *:80>
ServerName your.url.fortheroot
ServerAlias alternate.url.fortheroot
DocumentRoot "/path/to/webroot"
</VirtualHost>
The next entry would be similar to the following
<VirtualHost *:80>
ServerName your.url.forthesubfoldertest
ServerAlias alternate.url.forthesubfolder
DocumentRoot "/path/to/webroot/test"
</VirtualHost>
...
In your case, however, you would only require one virtual host entry & not two.
Additionally, it should be noted that, should you desire to serve a site from a location NOT in your webroot then you would also need a
<Directory></Directory>
entry to tell Apache what access to give to visitors (NOTE: in Linux the Apache user should be made owner of the files [or permissions should be set in a method that still allows the apache user rights to serve the files if you want to avoid giving it ownership])

Resources