I need to access a web app via below URL:
https://www.localhost/index.php
Below is my Apache configuration:
ScriptAlias /www.localhost/ "/var/www/siva/scripts/"
Alias /pages/ "/var/www/siva/wpages/"
ServerName www.localhost
<Directory "/var/www/siva/scripts">
AllowOverride None
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Options None
</Directory>
<Directory "/var/www/siva/wpages">
AllowOverride None
Options None
</Directory>
/var/www/siva/scripts/index.php
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
If I access my page in a browser as URL:
http://localhost/www.localhost/index.php
it works fine but the same does not if I access as
http://www.localhost/index.php
What changes should I make to achieve the same and how can I make it available at "https" protocol only?
Prakash, you need to add ServerAlias to make it work as localhost as well, and add HTTPS redirect, RewriteRule, as I understood, it's what you want, for example:
ScriptAlias /www.localhost/ "/var/www/siva/scripts/"
Alias /pages/ "/var/www/siva/wpages/"
ServerName www.localhost
ServerAlias localhost
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
httpd ServerAlias Directive:
The ServerAlias directive sets the alternate names for a host, for use with name-based virtual hosts. The ServerAlias may include wildcards, if appropriate.
EDIT 1:
At first, after you edit httpd's .conf files restart your httpd, e.g: service httpd restart. You can create VirtualHost to workaround your problem:
<VirtualHost 127.0.0.1:80>
ServerName localhost
ServerAlias www.localhost
DocumentRoot /path/to/your/site/root
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
Then do the same for SSL site:
<VirtualHost 127.0.0.1:443>
ServerName localhost
ServerAlias www.localhost
DocumentRoot /home/localhost #path to your localhost root directory
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] #rewrite all www to non-www
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
SSLEngine on
SSLCertificateFile /home/localhost/ssl.cert
SSLCertificateKeyFile /home/localhost/ssl.key
SSLCertificateChainFile /home/localhost/ssl.bundle
</VirtualHost>
EDIT 2:
For SSL site you can change /etc/httpd/conf.d/ssl.conf (it could depend on your Linux distribution) but at the same time, there is no real need for that and you could just place your directives in httpd.conf.
Related
My domain originally had a www (https://www.my-domain.com) i changed it recently to redirect to non www.
Now when i go to my-domain.com on my browser, it goes to my localhost XAMPP dashboard (https://localhost/dashboard/). and when i turn xampp off, i get a "Unable to connect" on firefox.
I've tried the site on my mobile and my mac, it works fine and points to the server. I've also reinstall xampp on my PC, and still get the same result.
Not sure if this is the issue, but my current .htaccess is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
and my virtual host on my ubuntu server is
<IfModule mod_ssl.c>
<VirtualHost *:433>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/frontend/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName my-domain.com
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.my-domain.com
SSLCertificateFile /etc/letsencrypt/live/my-domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my-domain.com/privkey.pem
</VirtualHost>
<Directory /var/www/html/frontend/www>
Options Indexes FollowSymLinks MultiViews
AllowOvereride All
Order allow,deny
allow from all
Require all granted
</Directory>
</IfModule>
Any idea what's going on?
My server is running ubuntu 18 on AWS.
The usual problem here is that you have no matching virtualhost set up to handle your new servername.
When that happens on a server, it "redirects" you to first matching virtualhost (which is probably xampp dashboard).
You have probably changed the application and it's .htaccess, but you didn't modify your virtualhost for the domain.
if you DID modify yourvirtualhost, please make sure to restart xampp, otherwise xampp won't consider changes made.
I am trying to configure a Wordpress project on my localhost, but when I open the browser on localhost I only see the files in the root of my wordpress project.
If I click on index.php or access localhost/index.php it executes the PHP as expected.
I have installed apache 2.4, php 7.2 and php-apache 7.2.
My project is in /srv/http/mysite:
The relevant lines in /etc/httpd/conf/httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Note: Since httpd.conf is very big I showed only the lines I know to be relevant. If this is not enough I can upload the entire file on pastebin.
The file /etc/httpd/conf/extra/httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin webmaster#test.localhost
DocumentRoot "/srv/http/mysite/"
ServerName test.localhost
ServerAlias test.localhost
ErrorLog "/var/log/httpd/test.localhost-error_log"
CustomLog "/var/log/httpd/test.localhost-access_log" common
<Directory "/srv/http/mysite/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The file /srv/http/mysite/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My /etc/hosts file:
127.0.0.1 localhost
127.0.1.1 mycomputer_name
127.0.2.1 test.localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
About this last file I noticed that if I remove the <IfModule ...> and </IfModule> site it works and redirects to index.php, but I would prefer not to change this file since it works the way it is on the remote server that uses ubuntu.
The main question is why this is not working but I would be also happy to know what the <IfModule mod_rewrite.c> is doing and why it is being ignored even though LoadModule rewrite_module modules/mod_rewrite.so is enabled.
I know this is not an easy question but I have not found anyone with this same problem on the web. I will be very grateful for any help.
Apache needs to be setup to recognize your index files (in this case index.php)
Do you have the following in your Directory
DirectoryIndex index.php
So
<Directory "/srv/http/mysite/">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
In httpd.conf you should have something like...
<IfModule dir_module>
DirectoryIndex index.php index.htm index.html
</IfModule>
This would be your catch-all fall-back.
And then in your httpd-vhosts.conf one of many site descriptions might look something like...
<VirtualHost *:8080>
ServerAdmin admin#siteName.com
DocumentRoot "e:/Stack/Sites/siteName/web"
ServerName siteName
ServerAlias siteNameUser
<Directory "e:/Stack/Sites/SiteName/web">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/siteName.error.log"
CustomLog "logs/siteName.access.log" common
</VirtualHost>
Note: The DirectoryIndex index.php in httpd-vhosts.conf site declaration is unnecessary if you included the fall-back defaults in httpd.conf
If you are not wanting to use default port 80 then in either file have something like: Listen 8080
For localhost I use: in httpd.conf... Listen 127.0.0.1:8080 and in httpd-vhosts.conf Listen 8080
In your hosts file you will need to define something like...
127.0.0.1 siteName siteNameUser www.siteName.com
Currently using: Apache/2.4.33 (Win64) PHP/7.2.4 ~ MySql 5.7.22 homebrew stack.
The httpd-vhosts.conf example portion is for Drupal 8.x - For WP your DocumentRoot and Directory will differ.
You can listen on multiple ports such as 8080 for dev, 8081 for test, 8082 for prod. Also you can have many different site definitions in your httpd-vhosts.conf file.
I prefer to define all sites in httpd-vhosts.conf, but you could just place them in httpd.conf
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 server was recently compromised. I moved everything to a new server, but for some reason the permalinks for the Wordpress site are not working properly. I've looked everything over and it all appears to be correct, but I can't see why the links won't work when the settings were all copied over from the old server where they all worked.
Server .conf:
<VirtualHost *:80>
ServerName www.XXX.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/XXX.com/
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>
<VirtualHost *:80>
ServerAlias XXX.com
ServerAdmin XXX
DocumentRoot /var/www/html/XXX.com/
ServerName www.XXX.com
DirectoryIndex index.html index.php
<Directory "/var/www/html/www.XXX.com/">
allow from all
Options -Indexes
AllowOverride All
</Directory>
CustomLog ${APACHELOGDIR}/XXX.log common
ErrorLog ${APACHELOGDIR}/XXX-error.log
</VirtualHost>
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUESTFILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Make sure .htaccess has right permissions so that wordpress can change it on its own.
I am trying to integrate my portal with my website.
My website :
http://example.com
and My portal :
http://portal.com
Now I want to see my portal from :
http://example.com/portal
Part of my core apache config file (sites-enabled/website):
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName example.com
DocumentRoot /home/example/WebSite2.0/WebContent
DirectoryIndex index.php index.html
<Directory /home/example/WebSite2.0/WebContent>
Options +IncludesNOEXEC
AllowOverride None
Order allow,deny
allow from all
XBitHack On
AddType text/html .html
AddHandler server-parsed .html
</Directory>
Alias /portal /home/example/portal/CodeIgniter_2.1.0
<Directory /home/example/portal/CodeIgniter_2.1.0>
DirectoryIndex "index.php"
allow from all
Options +Indexes
#Options FollowSymLinks MultiViews
Order allow,deny
RewriteEngine On
RewriteBase /portal
#RewriteRule ^test\.html$ test.php
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond $1 ^(css|images|js)
RewriteRule ^(.*)$ $1
</Directory>
</VirtualHost>
As you see my portal functions on top of CodeIgniter; Hence -
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Part of my core apache config file (sites-enabled/portal) :
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName portal.com
ServerAlias www.portal.com
DocumentRoot /home/example/portal/CodeIgniter_2.1.0
DirectoryIndex "index.php"
SSLEngine On
SSLCertificateFile "ssl/portal.com.crt"
SSLCertificateKeyFile "ssl/portal.com.key"
<Directory /home/example/portal/CodeIgniter_2.1.0>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Header unset Server
ServerSignature Off
</Directory>
</VirtualHost>
Now the real problem is when I open http://example.com/portal the browser is looking for the images in the DocumentRoot and not in Alias.
e.g. for image from portal,
<img src="/images/example.png" style="margin-left:30px;height:50px;">
apache error log says -
File does not exist: /home/example/WebSite2.0/WebContent/images/example.png
I would hate to make changes to my code. I just want to get this thing working from the apache config file itself. Please help me do this.
RewriteBase /portal require that the url should begin with /portal. So:
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
will not be hit.
<img src="/images/example.png" style="margin-left:30px;height:50px;">
will try to search file from DocumentRoot.
update1
For there is RewriteBase /portal, example.com/portal/images will hit the Rewrite rule, but example.com/images will not, so:
<img src="/images/example.png" style="margin-left:30px;height:50px;">
should be:
<img src="/portal/images/example.png" style="margin-left:30px;height:50px;">
update2
It is the answer given by #Hussain Tamboli himself, with:
RewriteRule /(images|js|css)/(.+)\.(.+)$ /portal/$1/$2.$3 [PT].
/images/Invoice.png will rewrite to /portal/images/Invoice.png