Codeigniter vhost LAMP configuration troubleshoot - php

Running LAMP on UBUNTU 14LTS on virtualbox from win7 I found some hiccups.
I'm having trouble displaying my code igniter project in my machine. I have a followed some guides including this one:
tut 1 and tut 2
I can make the current configuration show a single HTML page, called example.com but it cannot show a complete code igniter project, I get this error when running it through the localhost:
NOT FOUND The requested URL /alpa_blog/en was not found on this server.
The project I'm working on is very big so bitnami is a bitslow so I'm planning to change to LAMP that is why I wanted to try and see a little blog on my localhost.
I have not used the LAMP on apache 2.4+ so I'm a little confuse about how to edit some files on vhost and tie them to the config.php inside code igniter.
I've tried a lot of different combination things but no success yet. Now I have my files #:
/etc/apache2/sites-available/alpa_blog.com.conf
/etc/apache2/sites-enabled/alpa_blog.com.conf
Looking like:
<VirtualHost *:80>
ServerName alpa_blog.com
ServerAlias www.alpa_blog.com
DocumentRoot /var/www/html/alpa_blog.com/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And # /etc/apache2/sites-available/000-default.conf
looks like:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
Plus my file alpa_blog.com/config/config.php code igniter's folder looks like:
$config['base_url'] = 'alpa_blog.com';
My etc/hosts folder looks like:
127.0.0.1 localhost
127.0.1.1 alpalamp-VirtualBox
127.0.1.1 example.com localhost
127.0.1.1 alpa_blog.com localhost
My var/www/html folder looks like:
alpa_blog.com ci example.com index.html phpinfo.php
Any pointers are much appreciated. Sorry for the your supposed to know that question, but it's driving me nuts.
EDIT:
I've tried several configurations on the .htaccess file.
This is my last version of the .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
And config.php is like:
$config['index_page'] = '';

So after a while I found the answer, I thought to post it here just in case.
Going in the log file located at var/log/apache2/error.log I found this message:
[core:alert] [...] /var/www/html/APP-NAME/www/.htaccess: RewriteRule: bad flag delimiters, turns out that a regex expression was not properly written.
I Ended up by rewriting the rule on the .htaccessfile like this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php/ [L]
Which solved the issue.
This post also helped out

Related

Symfony (3.4) app : cant redirect requests to /web dir via .htaccess

I've a website lets say website.fr ( on server : /web/website ) ;
I ve added a symfony blog app in /web/website/blog/.
I dont manage to access the blog via website.fr/blog/ (404 error)
There is a .htaccess file in /web/website/blog/ directory, and one in /web/website/blog/web directory.
I am used to deploy symfony apps 'alone' on a server, and make the domain point to the web dir of the app, and everything always works fine, but in this configuration, I cant get it to work.
I have tried to use the following .htaccess conf under /web/website/blog/ :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And I did not edit the default one under /web/website/blog/web/
Im not sure what Im doing wrong, so any help would be appreciated !
For me I use .. nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/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>
which is explained Here and restart Apache, but I do not know if I understand your problem
I couldn't get what I wanted, but here is the solution I implemented :
I created a .htaccess in /web/website dir, that rewrites all requests to /web/website/blog, with the root (/) excluded from this rewriting :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ blog/web/$1 [QSA,L]
</IfModule>
That's not the way I wanted to get my rewriting, but I have the result I expected ; note that it would not be a good solution for a website that would evolve with new modules, routes, folders...

Symfony 4 deployement's rooting on apache

So I have my symfony 4 app and I have to deploy it on a private server.
My private server (on debian) has already a website in var/www/html/ accessible by 'url.com' My etc/hosts file look like this:
127.0.0.1 localhost
xxx.xx.xx.xx url.com url
I would like my symfony app to be accessible whether by 'app.url.com' or url.com/app.
I tried setting up a vhost and adding my new url to the hosts file by adding a line like this one : xxx.xx.xx.xx app.url.com.
I also tried different VHost conf file but none worked, so I must miss something.
EDIT:
<VirtualHost *:80>
ServerName app.fr
ServerAlias www.app.fr
DocumentRoot "/var/www/html/app/public"
ErrorLog ${APACHE_LOG_DIR}/app-error.log
CustomLog ${APACHE_LOG_DIR}/app-access.log common
<Directory "/var/www/html/app/public">
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =app.fr
RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

WampServer Site URL not working without localhost prefix

I was using Wamp 2.4 but had to uninstall it and install 3.0.6 alongside the 3.0.8 update. Everything works fine by selecting the Add localhost option in the wamp tray setting and stating /mysitefolder/ in the .htaccess and http//localhost/mysitefolder in the config files of the application.
But I like the idea of using virtualhost especially with the GUI form provided to create VH via an interface. I created a VH of a project I was working on prior to version 3.0.6 installation. Now I edited the .htaccess and config file of codeigniter code I was working with so that rather than localhost/mysitefolder as default I can now navigate to http://mysitefolder.
The problem: pointing to http://mysitefolder displays rightly but clicking any of the links to subpages results in the same browser error:
"Not Found The requested URL /mysitefolder.txt/index.php was not found
on this server. Apache/2.4.23 (Win32) PHP/5.6.25 Server at
mysitefolder Port 80"
First I don't understand where the .txt extension is emanating from and I don't know how to go about fixing this.
Working with Windows 8.1, Apache 2.4.3 with mod rewrite selected.
Kindly advise.
APACH VHOST FILe
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName financejobs
ServerAlias financejobs
DocumentRoot "c:/wamp/www/financejobs"
<Directory "c:/wamp/www/financejobs">
AllowOverride All
Require local
</Directory>
</VirtualHost>
Codeigniter Application HTACCSS (for financejobs)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /financejobs/
RewriteCond %{REQUEST_URI} ^jp_sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^jp_app.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Options -Indexes
Here's the answer:
Try changing RewriteBase /financejobs/ to RewriteBase /

URL Rewriting and Laravel 4 Routes not working on server?

I bet this question has been asked time and time again, but I just can't seem to get an answer. Anyway, here is my situation. I have a domain, lets say example.com. Example.com works fine, everything works as it should. However, if I navigate to Example.com/about, which works on my local machine, I get a 404 error. However, if I go to example.com/index.php/about, the about page works fine. I know this must be a mod rewrite issue. I have enabled mod rewrite and restarted my server to no avail. Anyway, here is some code:
Virtual Host:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/example/public"
<Directory "/var/www/example/public">
AllowOverride all
Allow from All
</Directory>
</VirtualHost>
And here is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I'm using Ubuntu 14.04 on a Digital Ocean Droplet.
Thanks!
1)
go to /etc/apache2/sites-available and create file and add below
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#newyear
DocumentRoot /var/www/html/example/public
<Directory /var/www/html/example/public>
options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
2) Create Link of above created file and paste it into /etc/apache2/sites-enabled
3) Check /etc/apache2/mods-available for rewrite.load file
if it is not there create it and add below line & save
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
create link of rewrite.load file and paste it into etc/apache2/mods-enabled
4) open /etc/hosts
add below
127.0.0.1 example.com
5) sudo service apache2 restart
I figured out how to do this, I had to put my VirtualHost code in sites-enabled, not sites-available. Facepalm.
In ubuntu 14.04 with apache2 i was fall this problem.Then i solve this and wrote a blog,you can follow this
http://www.kingpabel.com/apache-mod_rewrite/

wamp local subdomains and htaccess rewrite rules

i recently fixed my site up with a bit up php mvc magic for which i use those settings in my .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9]*)/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&arg=$3 [NC,L]
it worked like a charm. the only problem i encountered was that when i reference files like css or images relatively, the browser assumed that we moved down the folder structure due to the dashes in the url
localhost/projectname/controllername/action/id
so the css/styles.css was requested at localhost/controllername/action/id/css/styles.css
having absolute paths fixed that problem but didnĀ“t work well with having a localtest server and a remote live and development server after there was no "projectname"- folder
i decided to configure my local wamp server so i can access my different project as a subdomain to my localhost like "http://projectname.localhost".
i activated the relevant apache modules, edited my hosts file and changed my httpd-vhosts.conf to
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost.com
ServerAlias www.localhost.com
DocumentRoot "C:\wamp\www"
ErrorLog "logs\errors.log"
<directory "C:\wamp\www">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost.com
ServerAlias *.localhost.com
VirtualDocumentRoot "C:\wamp\www\subdomains\%1"
ErrorLog "logs\errors.log"
<directory "C:\wamp\www\subdomains\%1">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
now when i call projectname.localhost.com/controllername/action/id it tells me
The requested URL /subdomains/projectname/index.php was not found on this server.
while projectname.localhost.com/index.php still supplies me with the right file.
i have heard that there might be a problem with the $_SERVER['DOCUMENT_ROOT'];. that doesn't get set properly but knowing that has not helped me fix that problem yet.
can someone point me into the right direction or suggest another environment configuration that makes testing under those circumstances possible?
changing my .htaccess to
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9]*)/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&arg=$3 [NC,L]
solved that issue.
the magic line is RewriteBase /
seems like the server was really looking for the index.php in the wrong place.
hope this helps other people having the same problem... :)

Categories