Site deployment connection refused for Laravel Project hosted on EC2 instance - php

I'm trying to get my site deployed using Laravel on an AWS EC2 instance running CentOS7. I've checked to make sure the ports and traffic settings are correct and they are as I was able to hit the apache landing page prior to editing the conf and I am also able to ssh in and ping the IP, but I believe I am possibly having some issue with the config files. This is what I hit when I hit the endpoint:
My httpd is running and I was able to access the apache landing page prior to editing my config files.
Here is the main part of my httpd.conf (please note: I didn't include the whole thing because it is massive and consists of mostly commented out code):
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/[project_path]/public"
#
# Relax access to content within /var/www.
#
<Directory "/var/www/[project_path]/public">
AllowOverride All
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/[project_path]/public">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ".ht*">
Require all denied
</Files>
and here is my added project.conf file inside of conf.d:
<Directory "/var/www/[project_path]/public">
AllowOverride All
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/[project_path]/public">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
<Directory "/var/www/[project_path]/public">
Options -Indexes
</Directory>
<VirtualHost hostIP:80>
ServerName hostIP
DocumentRoot /var/www/[project_path]/public
TraceEnable Off
</VirtualHost>
ServerTokens Prod
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>
<IfModule mpm_prefork_module>
StartServers 50
MinSpareServers 10
MaxSpareServers 30
ServerLimit 50
MaxClients 50
MaxRequestsPerChild 100
</IfModule>
Any help would be greatly appreciated!

Your RewriteEngine is redirecting port 80 to HTTPS which goes to port 443 which is not defined.
If you want to run the server under port 80 (HTTP connection), remove the
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>

Resolved this by adding an ssl.conf file along with a project.conf.bak in conjunction with the project.conf file

Related

Laravel document root Forbidden with HTTP 403 error

I have laravel instaled CentOS 7 server. PHP, MariaDB and HTTPD are installed and works. All services are up and works. Browse the document root shows
Forbidden
You don't have permission to access / on this server.
this is the document root of my server
DocumentRoot "/var/www/html/api/public"
Document root configurations
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
This is welcome.conf file ( /etc/httpd/conf.d/welcome.conf)
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL. To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
What can I do for this issue?
Create and put this .htaccess file in your app folder.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
Below server configurations are fixed the issue with me.
Grant Folder Permission and Set ownership
chown -R apache:apache /var/www/html/laravel
chmod -R 755 /var/www/html/laravel/storage
Restore Security
restorecon -R /var/www
Disable SELinux
setenforce 0

Server-generated directory index forbidden by Options directive

I know this question has been asked a bunch of times but I'm not finding any answer that helps.
So I have two pages, index.php and refer.php. I put a rule into my httpd.conf that used mod_rewrite to get rid of the .php extension when a user goes to the page. Refer.php worked fine to show up as just refer, but trying to go to index.php gives me a Forbidden error.
Error log shows this:
AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive.
Here's the relevant part of my httpd.conf:
<Directory "/var/www">
AllowOverride All
# Allow open access:
Require all granted
</Directory>
# Further relax access to the default document root:
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
The file index.php exists, of course. Any help?
Edit:
The url is just the root url - like domain.com. It should access index.php, which it did fine before I did the mod_rewrite. So I expect the index page to come up, which it doesn't because of the errors that I described above. .htaccess file is just all defaults except for:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

You don't have permission to access /folder on this server - AWS EC2

I know that there are a billion questions about that, but I cannot make it work.
What have I done so far :
Change my httd.conf file so that the DirectoryRoot is /home/ec2-user/folder.
Restarted my apache server.
chmod -R 775 /home/ec2-user/folder
Changed my httd.conf (only the changed lines are in here)
...
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "/var/www/html"
DocumentRoot "/home/ec2-user/folder"
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
<Directory />
# Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
# Allow from all
Require all granted
</Directory>
and then this :
# This should be changed to whatever you set DocumentRoot to.
#
#<Directory "/var/www/html">
<Directory "/home/ec2-user/folder">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
# Options Indexes FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
# Allow from all
Require all granted
</Directory>
and then this :
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
#Listen 80
Listen 0.0.0.0:80
But I still have permission denied on /file.php.
What am I missing?
EDIT : I have also changed the DocumentRoot. Before that, I had a wrong url error, now I do not have the permissions. So, right now, the url is correct, I just haven't set the correct permissions for it.
I didn't do something different from the above - but after restarting my Apache and exiting my AWS a number of times - then it magically worked. By following the above steps and checking the logs for errors, you should have it fixed.

wamp local host .htaccess causing forbidden error?

I have been trying to rewrite the url.
Here is the content from my httpd.conf
<Directory "C:\wamp\www\base">
Options None
AllowOverride all
Order deny,allow
Allow from all
Satisfy all
</Directory>
#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory C:\wamp\www\base>
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride all
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
Options None
AllowOverride all
Order Deny,Allow
Allow from all
Allow from 127.0.0.1
</Directory>
Error log from apache:-
error] [client 127.0.0.1] client denied by server configuration: C:/wamp/www/base/category
.htaccess file under base directory
Options +Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteBase /base/
RewriteRule ^category /category.php
Before i was not doing url rewriting. If i remove .htaccess from base directory then it works fine.
so can anyone help me to enable url rewriting?

Apache server ignores .htaccess

I'm trying to get a website working on my test environment, but somehow it is not working. I can load the normal index page, but when I want to access /page/test it throws an error saying the page does not exists. My log says:
File does not exist: /home/page_url/www/page
Which is in fact true, but it should got to my Page controller instead and load the test method.
My .htaccess looks like:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* /$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
My vhost configuration looks like:
<VirtualHost *:80>
ServerName page_url
Include /etc/apache2/vhosts.d/vhco.include
DocumentRoot "/home/page_url/www/"
# Logging
CustomLog /var/log/apache2/access_log common
ErrorLog /var/log/apache2/error_log
# This should be changed to whatever you set DocumentRoot to.
<Directory "/home/page_url/www/">
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride All
# Controls who can get stuff from this server.
Order allow,deny
Allow from All
</Directory>
<IfModule alias_module>
# Redirect: Allows you to tell clients about documents that used to
# exist in your server's namespace, but do not anymore. The client
# will make a new request for the document at its new location.
# Example:
# Redirect permanent /foo http://www.example.com/bar
# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
# Example:
# Alias /webpath /full/filesystem/path
#
# If you include a trailing / on /webpath then the server will
# require it to be present in the URL. You will also likely
# need to provide a <Directory> section to allow access to
# the filesystem path.
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the target directory are treated as applications and
# run by the server when requested rather than as documents sent to the
# client. The same rules about trailing "/" apply to ScriptAlias
# directives as to Alias.
ScriptAlias /cgi-bin/ "/var/www/localhost/cgi-bin/"
</IfModule>
# "/var/www/localhost/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
<Directory "/home/page_url/www/">
AllowOverride None
Options None
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
I'm using Gentoo.
Any help would be appreciated.
<Directory "/home/page_url/www/">
AllowOverride None
This AllowOverride None disables .htaccess files from being read. See the manual.
Also, please bear in mind that there's nothing magical about .htaccess files. They are a crude workaround for not having full access to the server configuration. All they are is a piece of Apache configuration. If you have full access to the server configuration, you should be putting stuff like this into the vhost configuration, not .htaccess files.
As Jim said, if you have full access to your server, you should just put everything in the server configuration files.
I reached here because I thought my server was ignoring my own htaccess/server configuration files. However, it turned out I had mod_expires and mod_rewrite disabled. After I had those two looked into, everything was working again as it should.
You can enable them by executing these commands:
sudo a2enmod expires
sudo a2enmod rewrite
Then restart apache
service apache2 restart
Hope this helps someone out there!
One thing to remember if your rewrite rules still don't work:
Also activate the ModRewrite module! It is not by default in Ubuntu.
See other answer here on how to do that.
In my case the problem was the permissions for .htaccess file.
Solution:
sudo chown apache:apache .htaccess

Categories