I'm having what seems to be a common problem deploying a codeigniter web app to an Amazon AWS EC2 instance and configuring it for SSL/TLS.
The app is running on an Amazon Linux 2 AMI (HVM) instance.
The web app works fine under HTTP i.e. the basic URL will load the index.php with the default route. The codeigniter routes all call the controller functions fine and load the respective views and any functions on the page that use AJAX to call a controller function all work fine.
When trying with HTTPS the basic URL will load the index.php with the default route, however when adding routes to the end of the URL I encounter a 404 not found error.
Not Found
The requested URL was not found on this server.
The same is true with any functions on the page that use AJAX to call a controller function:
Request URL: https://www.mysite.co.uk/Home/test_fn
Request Method: POST
Status Code: 404 Not Found
Remote Address: xx.xxx.xxx.xx:443
Referrer Policy: strict-origin-when-cross-origin
I've been following the guide here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SSL-on-amazon-linux-ami.html and have:
Enabled mod_ssl
Used Route 53 to set up the DNS records for my domain
Have a CA-signed certificate (90 day certificate from ZeroSSL)
Placed the certificate in /etc/pki/tls/certs
Placed the key in /etc/pki/tls/private
Updated SSLCertificateFile and SSLCertificateKeyFile in ssl.conf accordingly
Loading the index page under HTTPS (https://www.mysite.co.uk) in a browser works fine. All of the elements are loaded (css and images) and I see the closed padlock symbol in the address bar. Clicking on it states the connection is secure and the certificate is valid, so it appears the configuration there is OK.
In addition:
I've updated the vhost with an entry for port 443:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/html/myApp"
ServerName https://www.mysite.co.uk/
<Directory "/var/www/html/myApp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "/var/www/html/myApp"
SSLEngine on
SSLCertificateFile "/etc/pki/tls/certs/certificate.crt"
SSLCertificateKeyFile "/etc/pki/tls/private/private.key"
ServerName https://www.mysite.co.uk/
<Directory "/var/www/html/myApp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
The .htaccess file is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
</IfModule>
I've tried the config.php file with base_url settings of:
$config['base_url'] = 'https://www.mysite.co.uk';
as opposed to the original
$config['base_url'] = 'http://www.mysite.co.uk';
The values for index_page and uri_protocol are:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Controller names have initial characters in uppercase, and as things are working with HTTP in a linux environment I can discount case sensitivity being an issue. Likewise as the routes work under HTTP I don't think it is an issue with the routes.php file:
$route['default_controller'] = 'Home';
$route['home'] = 'Home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['companies'] = 'Company_c/view_companies';
$route['users'] = 'User_c/view_users';
$route['layers'] = 'Layer_c/view_layers';
I've tried many permutations for the .htaccess file.
I'm sure there is something I'm missing somewhere but have been going around in circles for he last few days to no avail.
Is there anything obvious I've missed somewhere along the line? Any assistance greatly appreciated.
I deployed a fresh CI4 with a custom domain on a fresh beanstalk instance. I used amazon certificate. Never used SSH. All done through web interface.
Only changes I did on codeigniter
copied .htaccess and index.php from /public to root folder
altered $pathsConfig in index.php to point project subfolder
altered $baseURL in Config\App.php and added https://
This should run with no problem.
What I suspect is ssl is not configured properly and it points to another virtual host or the default apache directory.
Try creating a regular file in the root folder /test.php and try to access it. If you still get 404 error then your virtual host configuration is broken.
Thanks #Ergec, it does look like a virtual host issue. It can't be picking up the vhost.conf file correctly.
Adding the virtual host section for port 443 to then end of httpd.conf and restarting the service has done the trick.
Related
I've trying to deploy my website on Heroku, the implementation that i used for this it's Model View Controller with PHP. I don't know what happend but when i try to access to the main page (or index) this works perfectly, when i'm trying to access other pages on mi website something occurs like this:
enter image description here
I know one reason which this is happening, i used in my Router the next:
$currentURL = $_SERVER['PATH_INFO'] ?? '/';
//var_dump($_SERVER);
$method = $_SERVER['REQUEST_METHOD'];
if($method === 'GET'){
$fn = $this->routesGET[$currentURL] ?? null;
} else{
$fn = $this->routesPOST[$currentURL] ?? null;
}
So, i displayed global variable of PHP $_SERVER on my website and i noticed $_SERVER['PATH_INFO'] doesn't appear on it. So, i guess that the problem comes from Apache's configuration because i use Apache2 and PHP for this. So, i don't know how configure because it's my first time doing this, if you can help me, i'll really thank to you.
Here is my directory:
enter image description here
And, finally my procfile:
web: vendor/bin/heroku-php-apache2 public/
These are the general appliable steps of configuring an MVC-based web application. Presumed web server version for the settings below: Apache HTTP Server v2.4.
1) Block access to all directories and files:
First of all, in the config file of Apache, the access to all directories and files should be blocked by default:
# Do not allow access to the root filesystem.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
# Prevent .htaccess and .htpasswd files from being viewed by Web clients.
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
2) Allow access to a default directory:
The access to a default directory (here /var/www/), supposedly used for projects, should then be allowed:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
My recommendation: For security reasons, this location should contain only a index.php and a index.html file, each of them displaying a simple "Hello" message. All web projects should be created in other directories and the access to them should be set separately, as described below.
3) Set access to a separate project directory:
Let's suppose that you create your project in another location (like in the directory /path/to/my/sample/mvc/) than the default one (/var/www/). Then, taking into consideration, that only the subfolder public should be accessible from outside, create a web server configuration for it, like this:
ServerName www.my-sample-mvc.com
DocumentRoot "/path/to/my/sample/mvc/public"
<Directory "/path/to/my/sample/mvc/public">
Require all granted
# When Options is set to "off", then the RewriteRule directive is forbidden!
Options FollowSymLinks
# Activate rewriting engine.
RewriteEngine On
# Allow pin-pointing to index.php using RewriteRule.
RewriteBase /
# Rewrite url only if no physical folder name is given in url.
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite url only if no physical file name is given in url.
RewriteCond %{REQUEST_FILENAME} !-f
# Parse the request through index.php.
RewriteRule ^(.*)$ index.php [QSA,L]
</Directory>
Note that the above settings can be defined either:
in the config file of Apache, or
in a .htaccess file inside the project, or
in a virtual host definition file.
In case a virtual host definition file is used, the settings must be included between the tags <VirtualHost> and </VirtualHost>:
<VirtualHost *:80>
... here come the settings ...
</VirtualHost>
Note: Don't forget to restart the web server after each change of the configuration settings.
Some resources:
What is Options +FollowSymLinks? (1)
What is Options +FollowSymLinks? (2)
RewriteRule Flags
Exposed folders in MVC application
mod_rewrite: what does this RewriteRule do?
I am building an application in Laravel which will be in construction for some time. In the meantime, I have 2 "conventional" websites, one static html and one php, which I'd like to include in my source control and make publicly accessible as I build the laravel application.
I have my public folder set up like this :
public/website1/many folders and files
public/website2/many folders and files
public/index.php
I would like to route / redirect users in the following way (lets use my development environment "localhost" as the domain):
localhost/laravelapp/ -> index.php
localhost/website1/ -> website1/index.html
localhost/website2/ -> website2/index.php
This way I can maintain all my code within a single project / source control / server.
But how do I route this!?
I have tried:
Route::get('/website1', function() {
return File::get(public_path() . '/website1/index.html');
});
but this just returns a static file with no relative links to the css folder or other linked files. How can I redirect the user properly to the correct area? Rebuilding the existing sites in Laravel framework is not an option. Thanks.
This should be pretty simple. I assume that you are using apache?
If you put a separate .htaccess file inside public/website1 and public/website2 then those rules will apply instead when you are visiting those routes, ignoring the rewrite rules in public/.htaccess.
You can configure your new .htaccess-files however you want, but all you need is
<IfModule mod_rewrite.c>
RewriteEngine On
</IfModule>
This is rerouted on the webserver level. Nothing is passed through laravel. This is what you want.
Now, we have solved this part:
localhost/website1/ -> website1/index.html
localhost/website2/ -> website2/index.php
But the laravel app acts like this:
localhost/ -> index.php
instad of:
localhost/laravelapp/ -> index.php
To solve this part, create a new directory inside public called laravelapp
and move public/.htaccess to public\laravelapp\.htaccess and change the following line
RewriteRule ^ index.php [L]
to
RewriteRule ^ ../index.php [L]
This was solved by by doing a couple of things:
1) VirtualHosts on the webserver to handle the domain name routing. Create a file on the Apache server:
httpd/conf.d/vhost.conf
NameVirtualHost *:80
<VirtualHost *>
ServerName domain1.com
ServerAlias dev.domain1.com
DocumentRoot /var/www/html/public
</VirtualHost>
<VirtualHost *>
ServerName domain2.com
ServerAlias dev.domain2.com
DocumentRoot /var/www/html/public/website2
</VirtualHost>
This routed my domains to their subfolders
2) The localhost environment was not working well. I switched from using "php -S server.php" (Laravels own server script configuration) to MAMP for OSX. This instantly cleared up my remaining permissions issues.
I hope this answer can help someone else in the future.
I'm new in Laravel, I made virtual host http://example.com and installed Laravel in folder of this domain but when I try to access this domain I get this
This is your VirtualHost setup
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/example" ## <-- pointed to wrong folder
ServerName example.com
ServerAlias www.example.com
ErrorLog "logs/www.example.com.domain-error.log"
</VirtualHost>
You didn't point it to the public folder. It should be (These are minimum requirements)
<VirtualHost *.80>
DocumentRoot "C:/xampp/htdocs/example/public"
ServerName example.com
</VirtualHost>
You should point it to the public folder because index.php is inside public folder.
I use this kind of setup
<VirtualHost laravel4.dev>
DocumentRoot "D:/xampp/htdocs/laravel4/public"
ServerName laravel4.dev
</VirtualHost>
Corresponding setup in windows/system32/drivers/etc/host file is
127.0.0.2 ci.dev
127.0.0.3 laravel4.dev ## <-- This is for current vHost
127.0.0.4 symcom.dev
So, I can navigate to my site on local host using http://laravel4.dev (dev for development)
That's exactly what you should be seeing. When you click the 'public' folder do you see a 'You have arrived.', with the laravel logo? If so, then you've correctly installed laravel.
The 'public' folder, is the main folder in which the actual public has access to your website when you put it on a server. You'll want to do one of two things here:
The simple (but insecure) way:
Add a .htaccess file to the root of your web folder containing this text:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This will make all requests go to www.example.com/public, but only show www.example.com in the URL.
The harder (but correct) way:
This completely depends on which provider you will be hosting your website on, but on Godaddy and others, you have the option of selecting the root folder of your website. In this case you'd select the 'public' folder to be the root. I cannot give you a tutorial on that because this option ranges on availability on every hosting provider.
EDIT: I should add just in case. When you add content to your site, such as CSS/images/files and everything the public will have access to, make sure you put them in the public folder.
You VirtualHost configuration needs to point DirectoryRoot further into public/ directory, so it can use its .htaccess and index.php inside that directory.
I've been building on localhost and all this stuff works perfectly. Now trying to load the site on a shared host. I've worked through most of the issues and actually have a working site but without any css.
Layout:
My app is in: /home/cake/app
public_html is in: /home/public_html
In public_html/index.php, the only way I was able to get rid of missing file errors was to do this...
require '../cake/app/webroot' . DIRECTORY_SEPARATOR . 'index.php';
The .htaccess in public_html:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
My app was baked from the command line.
All of the index.php and .htaccess files up through the chain are untouched.
/cake
/cake/webroot
/cake/app
/cake/app/webroot
It just can't find the path to all the css and js files.
in my default.ctp, I used the standard html helper links.
echo $this->Html->css('default');
I'm at the end of the proverbial rope. Any help appreciated.
On localhost, I point the apache directory at /cake/app, but I'm pretty sure I don't have access to apache config files on a shared host, hence the reason I pointed the public_html index.php at /cake/app. Probably not right, but it felt like I was moving in the right direction since the site started working.
All your CSS & JS should be inside the app/webroot directory.
It sounds like you've setup your virtual hosts incorrectly. (This is why the CSS works in public_html but not in the webroot directory).
Basically, We only allow access to our application through app/webroot/. This will load the index.php inside the webroot which is provided by cakePHP to load the controllers for every request.
Your virtual host file should look like this:
<VirtualHost *:80>
# Correct: Notice the "/app/webroot/"
DocumentRoot "/path/to/app/public_html/app/webroot/"
# Below is INCORRECT
# Incorrect: DocumentRoot "/path/to/app/public_html/app/"
ServerName yourdomain.com
</VirtualHost>
Now.. the ONLY directory accessible from the outside world is everything in webroot, this can be JS, CSS, Images, Files or whatever other assets you require.
This is how it should be setup, you dont want people to be able to access files outside of your webroot (ie all other CakePHP files).
On shared hosting providers, you will require a slightly different setup (you wont have access to the vhosts of the shared server). This explains the slightly different directory structure the OP has said. Read here for more info on deploying cakephp on a shared host.
http://bakery.cakephp.org/articles/gedm/2009/08/29/installing-cakephp-on-shared-hosting
Instead of including the index.php from the webroot in another index.php (inside your public_html), consider changing the webroot folder entirley to your public_html.
View here for more info on change cakephp webroot folder: CAKEPHP - Change default path to webroot
Change AllowOverride none to AllowOverride FileInfo in /etc/apache2/sites-available/default.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/user/app/
<Directory />
Options FollowSymLinks
AllowOverride FileInfo
</Directory>
<Directory /home/user/app/>
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
It worked for me.
Finally this one was the command wich worked for me to enable mod_rewrite:
$ a2enmod rewrite
Well, not sure whether this is all "right" or not, but I copied all the folders with the css and js files into public_html, which kind of makes sense. All of those assets need to be publicly accessible. Site works now.
As the title states, I cannot get my site to redirect. I've made several attempts and am about to lose it.
My .htaccess file is as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
I have this file placed in the www/Laravel/public folder as well as www directory
mod_rewrite is enabled
AllowOverride is set to All
My host file is as follows
127.0.0.1 localhost
Here is the code for route contained in routes.php
Route::get('authors', array('uses'=>'authors#index'));
I have a controller named authors.php, here is the code
class Authors_Controller extends Base_Controller {
public $restful = true;
public function get_index () {
return View::make('authors.index');}
}
I am using Windows 7 Ultimate. I'm about to blow my brains out. Please help me, I suck.
If your laravel project is located in c:\wamp\laravel\ then you should be able to call
http://localhost/laravel/public
and see the default laravel welcome page or your own.
If thats the case, you have to check two thins:
Open your /app/config/app.php file and check that the value of url directs to your project.
'url'=>'http://localhost/laravel/
Then open your .htaccess file and add the RewriteBase rule under the RewriteEngine On Line
RewriteBase /laravel/public/
Hope that helps! :)
I had the same problem. I used the solution above and it worked.
Apache rewrite_module must be enable in wamp as well.
You need to setup a virtual host pointing to your public directory...
in httpd.conf file.
Which can be found under the Apache menu...
Like so...
<VirtualHost *:80>
DocumentRoot c:\wamp\www\laravel\public
ServerName testing.com
</VirtualHost>
And your hosts file will reflect the url you choose...in this case...testing.com
127.0.0.1 testing.com
Checking rewrite_module
Go to
wamp icon
Apache
Apache modules
check rewrite_module
And cheers , there you are after some headache
Apache rewrite_module must be enabled in WAMP as well. It works with my wampserver.
Actually it has a pretty easy solution. All you have to do just check the rewrite module in apache. Check the steps in image
laravel problem with wamp server solution
Create an index.php file in the root.
<?php
header("refresh: 0; http://localhost/appnamehere/public");
?>
If you have multiple sites under one domain, you may not be able to change your public webroot.
I had all the correct settings, and the right .htaccess files in the right place, but it would not redirect. This fixed it for me.
This article was helpful in getting the wampserver/wampmanager links working.
Project Links do not work on Wamp Server
Post Script:
If you add to the virtual host file at:
E:\wamp\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf
and you create a virtual host that points to the public directory like this:
<VirtualHost *:80>
ServerName Blog
ServerAlias Blog
DocumentRoot E:/wamp/www/Blog/public
<Directory "E:/wamp/www/Blog/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
#
and you add to C:\Windows\System32\drivers\etc\hosts
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost
127.0.0.1 Blog
::1 Blog
You do not need the index.php file I suggested. That file works if you are NOT creating a virtual host, both are not needed. It's one or the other (although it does no harm to have it).
They only right way to do this is to point web server to public directory. For example, if you've installed Laravel in C:/xampp/htdocs/ directory, you need to use these settings:
DocumentRoot "C:/xampp/htdocs/public"
<Directory "C:/xampp/htdocs/public">
Never edit .htaccess inside public folder. If you did this, you need to get original file back. Restart Apache after you make these changes.