This has been doing my head in. Hope you guys can help. I can't find out where the error lies.
httpd-vhosts.conf
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot /opt/lampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot /home/tilman/Sites/mysite/www
ServerName mysite.lo
</VirtualHost>
/etc/hosts
127.0.0.1 localhost
127.0.0.1 mysite.lo
config.php
$config['base_url'] = "http://mysite.lo";
$config['index_page'] = "";
www/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
Now http://mysite.lo shows me the default controller. http://mysite.lo/index.php as well. So does http://mysite.lo/index.php/welcome.
But http://mysite.lo/welcome doesn't.
http://localhost/mysite/www/welcome works as expected.
edit:
I want to move system and application out of the web root.
So my file structure looks like this:
application/
system/
www/
'- index.php
In index.php I changed the paths to system and application folder, of course.
Sounds like you're having rewritemod/htaccess issues rather than VirtualHost issues. Have you made sure that you've got a block such as
<VirtualHost *:80>
ServerName mysite.lo
<Directory /home/tilman/Sites/mysite>
AllowOverride All
</Directory>
</VirtualHost>
somewhere within your config files? The fact that /index.php and /index.php/welcome work, tell me that it's the rewrite mod that's not functioning...
In your virtual host, do you not need this?
<VirtualHost 127.0.0.1>
DocumentRoot /home/tilman/Sites/mysite
ServerName mysite.lo
</VirtualHost>
I'm not sure you needed the www portion.
Related
I am having issues redirecting to index.php in my slim app with .htaccess file.
Routes work if I add the index.php at the end of the URL
So slimapp.dev/hello/myname gets error
Not Found The requested URL /hello/myname was not found on this server.
while slimapp.dev/index.php/hello/myname works
Here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php [QSA,L]
I am using Apache 2 on Ubuntu 18.04
File structure
public_html
|_index.php
|_ vendor
|_.htaccess
virtualHost 000-default.conf
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If I use the php -S localhost:3000 it works as expected but if I use the Apache web server, I most add the index.php to the end of the URL to make it work. Thanks
You are doing wrong.This is quite simple with just two lines of code:
RewriteEngine On
RewriteRule ^myname/(.*)$ /$1 [L]
This is my Virtual Host:
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.localhost:8080
DocumentRoot "D:/test/testpage/"
ServerName testpage
ServerAlias testpage.localhost
ErrorLog "logs/testpage-error.log"
CustomLog "logs/testpage-access.log" common
</VirtualHost>
system/host
127.0.0.1 testpage.localhost
httpd.conf in xampp/apache/conf/
Listen 8080
ServerName localhost:8080
LoadModule rewrite_module modules/mod_rewrite.so
<Directory />
AllowOverride All
Require all granted
</Directory>
my .htaccess file inside testpage folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and in my application/config/config.php
$config['base_url'] = 'http://testpage.localhost:8080';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
the only issue am facing is that index.php, i can access my other pages but it have index.php between base_url() and view.
I suggest trying the following VirtualHost (vhost) directives.
It defines D:/test/testpage/testpage as the pubic root of the site. Both .htaccess and CodeIgniter's index.php should be in this directory.
I've removed the ServerAlias - you don't need it.
I've added explicit directives for the vhost directory
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host.localhost:8080
DocumentRoot D:/test/testpage
ServerName testpage
ErrorLog "logs/testpage-error.log"
CustomLog "logs/testpage-access.log" common
<Directory D:/test/testpage>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
system/host should be
127.0.0.1 testpage
Because you have named the virtual host "testpage" the following should work.
$config['base_url'] = 'http://testpage/';
I am trying to make a virtual host for a codeigniter project. I have done this in httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login">
Require all granted
</Directory>
</VirtualHost>
and in application/config/config.php,
$config['base_url'] = 'http://dev.facebook-login.com';
and
$config['index_page'] = '';
the browser opens the landing page. but when transiting from any other uri it says object not found.
And when i configure httpd-vhosts.conf like this:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\CI_projects\facebook-login\index.php"
ServerName dev.facebook-login.com
<Directory "C:\xampp\htdocs\CI_projects\facebook-login\index.php">
Require all granted
</Directory>
</VirtualHost>
It arises problem with assets things, i,e images and some css doesnt loads. How can I solve it?
I am on windows 10 and I use xampp with virtual host this is way I set up.
Put forward slash at end of base url
$config['base_url'] = 'http://dev.facebook-login.com/';
First go to
Windows > System32 > drivers > etc > host
You may need to open as administrator to be able to save it
You might see some thing like
127.0.0.1 localhost
Below that create another one for dev.facebook-login.com like example:
127.0.0.1 localhost
127.0.0.1 dev.facebook-login.com
Save it
Then go to the
xampp > apache > conf > extra > httpd-vhosts.conf
open it as administrator so you can save it.
No need for the index.php on DocumentRoot
<VirtualHost *:80>
##ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:/xampp/htdocs/CI_projects/facebook-login"
ServerName dev.facebook-login.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
Save it and restart the severs.
I use this for my htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
httpd-vhosts.conf
Listen 1122
<VirtualHost *:1122>
DocumentRoot "D:\laragon_server\www\hugpong_production"
<Directory "D:\laragon_server\www\hugpong_production">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
https://www.namecheap.com/support/knowledgebase/article.aspx/10026/33/installing-an-ssl-certificate-on-xampp/
php 8 is not ready for CI4 as of jan 2021!
XAMPP has preloaded ssl certificate in php 7 packages
consider uncommon vhosts extra and place this in it
my only persistent issues is codeigniter 4 routes, have to turn on php spark serve to get XAMPP to route pages outside of default index, nothing else works, its garbage to that extent, will try with composer next....a whole book needs
to be wrote about codeigniter 4 routes and why they don't work, 200 pages plus
<VirtualHost localhost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
<VirtualHost example.com *:8080>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
//my project folder is codeignite4 without using composer this time
//i added listen 8080 under listen 80 in htppd.conf
ServerName example.com
<VirtualHost truservex.com *:443>
DocumentRoot "C:\xampp\htdocs\codeignite4\public"
ServerName example.com
SSLEngine On
SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
// you can verifiy these file locations, certificate data
SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
// going without the Directory tag can be helpful to drop in vhosts
<Directory "C:\xampp\htdocs\codeignite4\public">
Require all granted
doing this i was able to replicate the original install, create site access
using http://localhost:8080 or http://example.com/ as my base url
in my example index.php is removed, set to ''
when using command prompt to get into codeignite4 project folder i can
launch php spark serve and routes will work that were previously 404
Using Xampp 7.3.25 Dec 2020 because php 8 will not run error
free with codeigniter 4 as of this date, this worked for me as
my first codeigniter 4 virtual host setup, my install had
difficulty initially with using port 80, seems to want to for
port 443 if it can..I'm not a server pro but i wanted to
leave this for the next guy....This is strictly name based
virtual hosts for develop, ip based would have obvious
advantages. Because i had trouble in initial CI4 testing with
port 80 the (*) in virtual hosts vs (*:80) seemed to solve one
hurdle in searching for more ports, now i can finally begin my
first project ...my default URL was also changed to example.com
in appstarter/apps/config file. Carefully reread <tags> for
typos, its easy to shut server down!
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/"
ServerName localhost
<Directory "C:/Xampp/htdocs/">
Require all granted
<VirtualHost *>
DocumentRoot "C:/Xampp/htdocs/appstarter/public/"
ServerName example.com
ServerAlias www.example.com
# maybe don't attempt to use dir tag, shuts down server
# the directives at httpd.conf appear to suffice
I have added a htaccess file in the appstarter/public
I assume this is primitive, can get far more advanced
The Apache help pages helped me focus a bit more on
what i must accomplish, name based virtual hosts this case
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
2.2 Apache configuration: :Apache server context important!
Order allow,deny :The hackers are winning.....
Allow from all
2.4 Apache configuration:
Require all granted
My previous folder tree was (with portable xampp): (for example working on D: drive root)
/xampp/htdocs/application
/xampp/htdocs/system
/xampp/htdocs/themes
/xampp/htdocs/index.php etc..
Now I am trying to shift into a structure which I can work with multiple projects so new tree:
/xampp/htdocs
/web_projects/project-name/codeigniter/application
/web_projects/project-name/codeigniter/system
/web_projects/project-name/htdocs/themes
/web_projects/project-name/htdocs/index.php
My htaccess file in htdocs:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
# if Serves works on Linux OS
RewriteRule ^(.*)$ index.php/$1
# if Server works on Windows OS
# RewriteRule ^(.*)$ index.php?/$1
RewriteCond %{REQUEST_FILENAME} !-f
# if Serves works on Linux OS
RewriteRule ^(application|modules|plugins|system|themes|library|files) index.php/$1 [L]
# if Server works on Windows OS
# RewriteRule ^(application|modules|plugins|system|themes|library|files) index.php?/$1 [L]
And httpd-vhosts.conf:
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "/xampp/htdocs"
ServerName localhost
<Directory "/xampp/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/web_projects"
ServerName welcome.localhost
<Directory "/web_projects">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/web_projects/test/htdocs"
ServerName test.localhost
<Directory "/web_projects/test/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Finally etc/host:
127.0.0.1 localhost
127.0.0.1 welcome.localhost
127.0.0.1 test.localhost
127.0.0.1 vstart # Alias for test
All virtual hosts are working, i.e. http://vstart:8080/ is working but codeigniter not operates without index.php in address line, so routes are not working in accordance.
My config/config.php file is:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['index_page'] = '';
This set was working smoothly in my previous folder tree now is not working. I digged internet to find a solution with failure.
Any outer eyes to catch where I am doing wrong?
Found the solution:
All I need to do is add "AllowOverride All" to respected vhost.
Hope helps someone in the future.
New projects should be place inside the folder of "htdocs"
example:
xampp/htdocs/new_project1/index.htm
xampp/htdocs/new_project1/css
xampp/htdocs/new_project1/images
xampp/htdocs/new_project2/index.htm
xampp/htdocs/new_project2/css
xampp/htdocs/new_project2/images
I read about Zend_Controller_Router_Route_Hostname, but i havent idea how.
i try to use it, zend documentation. But when i try to open someoneusername.localhost/ my browser dont found nothing.( Oops! Google Chrome could not find ... ).
i verified my .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
and vhost config
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName localhost
DocumentRoot "/var/www/zendtest/public"
<Directory "/var/www/zendtest/public">
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error-localhost.log
CustomLog ${APACHE_LOG_DIR}/access-localhost.log combined
</VirtualHost>
hosts file
127.0.0.1 localhost
please someone help me.
Assuming everything else has been configured correctly, you'll want to change your VirtualHost Directive:
ServerName localhost
to
ServerName localhost
ServerAlias *.localhost
and then restart apache.
I'm afraid you're out of luck with the hosts file (wildcards unsupported)
See the link for alternatives.