I have CodeIgniter 3 running locally on MAMP just fine. But, when I pull from my repo and try to set it up on an ec2 instance with LAMP installed, I get a 404. CodeIgniter is in the /var/www/html folder
My /etc/apache2/apache2.conf file contains the following:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
mod_rewrite is enabled. The file /etc/apache2/sites-available/000-default.conf is as follows:
<VirtualHost *:80>
AccessFileName .htaccess
ServerAdmin admin#yourdomain.com
DocumentRoot /var/www/html/
<Directory />
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The file /var/www/html/application/config/config.php has the following settings:
$config['index_page'] = '';
$config['base_url'] = 'http://baseurl.com';
My .htaccess file is as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
first you check the server configuration. you can use apache error log to find server related issue.
then check error log of application.
In database.php check the
'dbdriver' => 'mysqli',
because newest Lamp not supported
'dbdriver' => 'mysql',
Related
This question was migrated from Stack Overflow because it can be answered on Server Fault.
Migrated 2 days ago.
I've set up an Apache server on Ubuntu 20.04
The site loads fine when I load the home page first (https://leadzilla.ai) and after that when I click on the pricing button and it takes me to https://leadzilla.ai/pricing and the that page loads fine as well.
But when I go directly to https://leadzilla.ai/pricing in the browser, I get a 404
Here is what I have in /etc/apache2/sites-available/leadzilla.ai.conf
<VirtualHost *:80>
DocumentRoot /var/www/leadzilla.ai
ServerName leadzilla.ai
ServerAlias www.leadzilla.ai
<Directory /var/www/leadzilla.ai>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =leadzilla.ai [OR]
RewriteCond %{SERVER_NAME} =www.leadzilla.ai
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I have this config in /etc/apache2/sites-available/leadzilla.ai-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/www/leadzilla.ai
ServerName leadzilla.ai
ServerAlias www.leadzilla.ai
<Directory /var/www/leadzilla.ai>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
#Deny from all
#Allow from 127.0.0.1
#Allow from ::1
</Directory>
<Directory /var/www/leadzilla.ai/blog>
AllowOverride All
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/leadzilla.ai/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/leadzilla.ai/privkey.pem
</VirtualHost>
</IfModule>
I have Wordpress on https://leadzilla.ai/blog so that has to be taken care of as well.
Here is what I have tried:
RewriteRule ^pricing$ pricing.html [NC]
I added it before the other rewrite rule but that doesn't seem to be working. Any ideas?
[EDIT]
This is solved now. The issue was a Next.js config, not an Apache config.
I put in exportTrailingSlash: true in my module.exports and it worked
I find this to be curious behavior. But if you have a RewriteRule in the <VirtualHost *:443>, then you should also have RewriteEngine On.
Are there any symbolic links in your directory at all. Anything like foo -> foo.html?
Are there any directories like /var/www/html/pricing/ in your directory structure?
Also, remember, that all of your traffic ends up on HTTPS, which means that only the <VirtualHost *:443> is in play. The other virtual host entry only is used long enough to redirect from HTTP to HTTPS. Any rewrite rules for the :80 VirtualHost do not apply on HTTPS.
I recently created a virtual host with WampServer (Version 2.4) so I can access my local website with the url http://yannbergonzat.local :
<VirtualHost *>
ServerName yannbergonzat.local
DocumentRoot "F:\Projets\Web\yann"
DirectoryIndex index.php
</VirtualHost>
And here is the Directory tag from httpd.conf :
<Directory />
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
This website is made with Symfony2, so yannbergonzat.local leads to a folder. If you want to access the actual website, you have to go to yannbergonzat.local/web/app.php .
I created a .htaccess file so the website can be seen with yannbergonzat.local :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And now is the problem. Depending on the value of AllowOverride, there are errors.
When AllowOverride is set on "all"
The .htaccess file is read, the site can be accessed on yannbergonzat.local, but the resources (stylesheets, javascripts) which are in another folder cannot be accessed (error 403)
When AllowOverride is set on "none"
The .htaccess file is not read, the site can not be accessed on yannbergonzat.local (it shows the content of the folder), you have to write the entire url (yannbergonzat.local/web/app.php), but the resources (stylesheets, javascripts) which are in another folder can be accessed.
What should I do to have the website on yannbergonzat.local with the resources from other folders working fine ?
This change to httpd.conf is VERY DANGEROUS
<Directory />
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
as it allows all access to the whole of the drive you installed WampServer( Apache ) onto, if thats the C:\ drive you are making a hackers life very easy!
You should change httpd.conf that back to
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
And add the directory specification to your VHOST definition like this
<VirtualHost *:80>
ServerName yannbergonzat.local
DocumentRoot "F:\Projets\Web\yann"
DirectoryIndex index.php
<Directory "F:\Projets\Web\yann">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
AllowOverride none is an instruction to Apache to ignore any .htaccess files, so that explains what you have described.
When setting up a Symfony2 site this is the recommended config for a Virtual Host setup. You specify the /web folder as the DocumentRoot
See documentation
So I am assuming (you dont specify the actual folder structure) you would need something like this:
<VirtualHost *:80>
ServerName yannbergonzat.local
DocumentRoot "F:/Projets/Web/yann/web"
DirectoryIndex index.php
<Directory "F:/Projets/Web/yann/web">
# enable the .htaccess rewrites
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
This will almost definitely fix your 403 error as you are now granting access Require all granted to the folder that the site actually exists in.
This code worked for me:
sudo chmod -R 755 /var/www/***
Makes sure SELinux is not in not blocking access to your web directory:
chcon -R -u system_u -t httpd_sys_content_t /home/user/www
I have a URL rewrite setup to create nice URLs
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]
When I access the admin area with /admin the URL is rewritten as /admin/?rq=admin because I have a root level directory named "admin". It's probably pretty simple, but how can I edit (or add to) my .htaccess rules so that the url is written cleanly as /admin/
UPDATE:
To clarify, I want to access /admin using /index.php?rq=admin and not by calling the /admin/index.php
Here is my apache virtualhost config:
<VirtualHost *:80>
ServerAdmin alex
ServerName hub
ServerAlias hub
DocumentRoot /var/www/hub/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/hub>
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
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Just add the admin folder to the list of exceptions in your RewriteCond. Now, you have exception for admin/assets so you can delete the assets part and leave the exception for the whole admin folder like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin|site\/assets|robots.txt|sitemap.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]
It seems that added DirectorySlash Off in my .htaccess did the trick. Not sure if this is the correct workaround but it solved my particular problem. I had to make sure to clear my cache fully to prevent cached redirects (thanks Kamil)
In Chrome: Chrome-> Tools -> Clear Browsing Data -> Empty the Cache
I have a copy of my website at localhost at:
/var/www/vhosts/mysite.com/httpdocs
This is my /etc/apache2/sites-available/mysite
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhosts/mysite.com/httpdocs
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
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
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I've copied htaccess.txt to .htaccess. When I activate friendly URL and URL rewriting, I get 404 errors.
I've uncommented this lines in .htaccess, but still does not work:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
I also tried to change rewritebase to
RewriteBase /mysite
with no luck.
What I'm doing wrong?
No sure if this is the issue you are experiencing, but I have experienced that rewriting does not work well on "localhost". Try and change your hosts file to say
127.0.0.1 mysite.local
And then access it on that url.
Not sure if that will work but it is worth a try.
Solved!
I had a conflict with different entries in /etc/apache2/sites-available.
When I create a new site at localhost, I copy default to mysite, and modify the mysite file to point to it's DocumentRoot.
I don't know exactly why, but if I disable default site:
sudo a2dissite default
it works.
Maybe this does'nt solve the question, but I prefer to issue another question more specific to this problem, because I've tested and it's related to different sites enabled and one or more with RewriteEngine enabled.
I am having some trouble with configuring Apache for a website that has both a normal and mobile version. The idea was to redirect the user with a mobile browser automatically to the mobile version and if someone on a normal desktop PC is trying to connect to the mobile version to redirect it to the normal website.
Right now it redirects a mobile user to the mobile website correctly. But it is seems to be unable to redirect the other way to the desktop version. Also, when you go to the mobile version of the website, it displays the default "It works!" page instead of the mobile index page for some reason..
Here is all the configuration that I used. Hopefully someone is able to help me out with this. Thanks in advance!
Normal website:
<VirtualHost *:80>
ServerAdmin webmaster#henal.local
ServerName henal.local
ServerAlias www.henal.local
DocumentRoot /var/www/henal.local
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/henal.local>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
DirectoryIndex index.html
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}/deltionkrant/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/deltionkrant/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
.htaccess normal website:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot- mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://m.henal.local/ [L,R=302]
Mobile website:
<VirtualHost *:80>
ServerAdmin webmaster#henal.local
ServerName m.henal.local
ServerAlias henal.local
DocumentRoot /var/www/henal.local/mobile
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/henal.local/mobile>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
DirectoryIndex index.html
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
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
.htaccess mobile webiste:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|googlebot- mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)" [NC]
RewriteRule ^$ http://www.henal.local/ [L,R=302]
Ok - so you are trying to do content negotiation here and you are regexing on the user agent. Aside from the rewrtile rules you have, you need to consider the following:
Using the Apache Mobile Filter instead of a Regex. It is more accurate and provides a greater range of features
You should allow users to choose the representation/experience that they want. So if you are presenting them with the mobile version, then you should let them choose the desktop version instead since this might actually have been what they wanted; and vice versa.
This could be for a plethora of reasons e.g they have bookmarks to the desktop, someone shared a url to the desktop version etc. etc. Your content negotiation technique is pretty basic and doesn't take into consideration any of these use cases.
Having considered this, specific to your problems above:
Try removing the quotes from your RewriteCond patterns and add the R=302 and L flag to make sure now other rewrite directives are executed. i.e:
RewriteCond %{HTTP_USER_AGENT} !(android|blackberry|googlebot- mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos) [NC,R=302,L]
Secondly its likely that you are seeing the default desktop "it works" because you are testing on a desktop browser and being redirected to the desktop host.
Slight tangent, in response to William Greenly's
"Since your DNS is not externally resolvable, then you won't be able to use your mobile phone to test."
FYI Pagekite (http://pagekite.net/) makes it easy to expose localhost to the net, in order to facilitate testing stuff on your dev machine from your phone.
HTH someone out there.