I upgraded a digital ocean box from 14.04 to 16.04 and ran in to some issues. The .htaccess file is not being parsed. I can throw garbage at the top of the file which normally breaks a server and it does not matter, leading me to believe it is not being parsed. My ultimate goal is to parse html files as php.
Virtual host settings were not changed after upgrade and worked before.
You can see an instance of the test droplet here: http://162.243.70.81/
I spent about 3 hours digging through other solutions including:
Checking conf file:
//Part of conf file
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
Checking if rewrite module is enabled
Module rewrite already enabled
service apache2 restart
Review .htaccess file (this is the first few lines and the random chars should result in a 500 if working)
kldlkldfg
AddType application/x-httpd-php .html .inc
editing mime types and looking if some php extensions are not commented out.
When I did the upgrade I did keep old conf files when it said the previous were modified and offered to overwrite or keep. I kept the defaults. Keep in mind everything worked before the upgrade and can be seen at www.pylamdyes.com
When I upgraded to php7 I had to disable php5.
That is all of the relevant info I can think to give, happy to try anything or post specific info as requested. Thanks for looking at this.
Define your virtualhost correctly by removing the <Directory /> entry and use this instead:
<Directory /var/www/www.pylamdyes.com>
Require all granted
Options FollowSymLinks
AllowOverride all
</Directory>
About Directory / it should be in server config (outside virtualhosts) like:
<Directory />
Require all denied
AllowOverride none
</Directory>
Also note: if you have access to the server configuration, there is no reason to use .htaccess files. .htaccess files are meant for people without admin rights to configure the web server.
If you need access for another directory, such as the target for that Alias, then define it in the same fashion as the documentroot Directory entry I defined. Policy is and should always be, deny all to /, and give access to the specific directories from where you serve files.
Related
Just got a new dedicated server from a reputable hosting company for my new website project.
It runs Centos 7.9/WHM with Apache 2.4+PHP 7.4 Package.
PHP-FPM as handler.
I ran some test with some php files in my website folder and I noticed that any .php files is accessible without his extension. Without any .htaccess file!
"https://www.example.com/myinfo.php" is Accessible.
"https://www.example.com/myinfo" Should be inaccessible without any .htaccess + rules.
It's annoying me a lot because I know it's gonna bring me some issues during my website project.
Where could these rule be as I am not using any htaccess file?
Thanks for any information you can give me.
As Magnus Eriksson said: You could be having multiviews enabled in your vhost. Try turning them off, restart apache and check if the issue is resolved. There could also be rewrite rules directly in your vhost.
As you have cPanel installed, my guess is the /etc/httpd/httpd.conf, and /var/cpanel/templates/apache2_4/ea4_main.default. Before you edit the ea4_main.default, copy it to ea4_main.local: cp -a /var/cpanel/templates/apache2_4/ea4_main.default /var/cpanel/templates/apache2_4/ea4_main.local, and only edit the ea4_main.local file. Please be careful when editing it, as it could mess up a lot of things. I would suggest you to ask questions on cPanel Forums if you are using cPanel, because this must be a cPanel related issue. And, I am not responsible if any problems occur, I have warned you already.
Edit:
Since you linked your httpd.conf file, I found this:
<Directory "/">
AllowOverride All
Options MultiViews FollowSymLinks IncludesNOEXEC Indexes ExecCGI
</Directory>
Change it to:
<Directory "/">
AllowOverride All
Options -MultiViews +FollowSymLinks +IncludesNOEXEC +Indexes +ExecCGI
</Directory>
I just got a VPS and it's running CentOS 6.8 with WHM 58.0. I really don't want the WHM, I only want to add one site to the server. So I just installed an FTP server and uploaded the files to the Apache root dir at /usr/local/apache/htdocs and gave all files chmod 777.
All works good, but when I go to PHP or ajax to PHP I get "403 Forbidden". I suppose the problem is in the http.config but I really have no idea. Here is my http.conf file and I don't have any .htaccess files.
Among other things, you want to make sure that the Linux user that is running Apache has permission to read and execute the PHP files where they are on the server.
This is a good guide for transferring PHP files and setting the permissions using PHP: https://www.digitalocean.com/community/tutorials/how-to-use-sftp-to-securely-transfer-files-with-a-remote-server
There's also a guide here to setting up the server and checking that PHP is set up correctly here, but I assume you have done this already: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04
I just replace this
<Directory "/usr/local/apache/htdocs">
Options Includes Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
With this
<Directory "/usr/local/apache/htdocs">
Options Indexes
Order allow,deny
Allow from all </Directory>
I'm having a problem where it seems like my Vagrant VirtualBox isn't reading the .htaccess file for a site I have mapped out. (a proccesswire site)
I've don't know enough about Vagrant to find where I should be editing the directives so that my .htaccess file will be read. As far as I've gathered from searching I need to set a directive like so:
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
It seems the primary offender is the AllowOverride is typically set to "None" and needs to be "All". But I have put this in a httpd.conf file in apache and I'm guessing that isn't correct.
A bit more information: When I installed PW in the site root I got this error: " Unable to determine if Apache mod_rewrite (required by ProcessWire) is installed. ". As a result when I try to access a part of the CMS, that is usually handled by rewrite rules, the url (/admin or /processwire by default) just reroutes me to the homepage.
Also, I can delete everything in .htacess or add garbage to it and no errors occur. This tells me that .htacess isn't even being read.
I appreciate the help.
I have built a Zend Framework application. By configuring it to read routes.ini file, my application after deployment is not going to any routes but only default route is working. I have total of 4 routes in this application and none of them are working. Apache is showing a Not Found error.
I had look at .htaccess file it is perfect and in my local it is working fine. I also checked the permissions. It is having read and write rights for www-data. I also checked Apache URL rewrite module.
I did this again and tried:
sudo a2enmod rewrite
Still same issue.
My apache error log says that file does not exist.
Please tell me where I have gone wrong.
After researching for hours , I could notice that there was a very minor and sensitive mistake in the apache vhost file .
my entry was like this
<Directory /var/www/your_project>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
But actually my entry should be as per mssb some what like this
<Directory /var/www/your_project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory
Since I am not an experienced webmaster I couldn't noticed one simple thing which is
AllowOveride option which was set to None
I referred to Core apace documentation today in order find where I was wrong .
The reason for not picking .htaccess file is as follows
When AllowOveride directive is set to None, then .htaccess files are
completely ignored. In this case, the server will not even attempt to
read .htaccess files in the filesystem.
When this directive is set to All, then any directive which has the
.htaccess Context is allowed in .htaccess files.
I personally felt like Posting this entire solution for the problem to help others who may face a similar problem in future
Once again I would like to thank you all for responding to this post
Try following steps to mod_rewrite
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
sudo gedit /etc/apache2/sites-enabled/000-default
add following codes
<Directory /var/www/your_prject_name>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</Directory>
then restart the server
sudo /etc/init.d/apache2 restart
First off let me start by saying that yes I have searched for this in google and in stackoverflow specifically, I have found many answers and tried them all. At this point I believe my only resource is posting the question myself, even if the scenario sounds repeated please be so kind as to try to help.
The situation is quite basic, on Ubuntu desktop 10.04 I set up apache via Synaptic and Php5 according to this guide and its spin-off here.
At this point if I go on command line and call a php script it works, for example:
php test.php
outputs my hello world without any problem. But if I go to firefox and point to test.php it will show the 403 error Forbidden...
I have changed ownership on /var/, /var/www/ and /var/www/test.php to every variable I can think of (www-data [apache runs as this user], purefan [my regular user], root) it makes no difference, I have also changed permissions several times 777, 0777 (just to be safe), 644, 755, no change.
from CLI I got the phpinfo into a file and added it here.
If Im not mistaken the problem is happening when Apache calls the php interpreter, as when I go to http://localhost/index.php it shows apache's default "It Works!" page, but if I add php content to that file it simply gets ignored, no error is shown though (also checked error log and syslog).
So please, if you have any suggestion let me know, this is not a life or dead thing but would really like to set up using worker instead of prefork.
Thank you for your time
I had exactly this same problem.. first I installed apache2 with worker mpm and php5 with fastcgi successfully under a virtual machine.. but when I tried it (using exactly the same process) on my production host, it gave me forbidden errors.
After a lot of search, I finally got it working. Here you can find the steps I've done to get it working:
These are the packages I've installed to get apache2 with mpm-worker & php5 with fastcgi:
apache2
apache2-mpm-worker
php5-cli
php5-cgi
php5-common
libapache2-mod-fcgid
Then you need to create a file to tell apache how to use php files. I've created one under the /etc/apache2/conf.d directory named php.conf. This should be the content:
<Directory /usr/share>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options ExecCGI FollowSymlinks Indexes
</Directory>
<Files ~ (\.php)>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options ExecCGI
allow from all
</Files>
And that's all. Obviously, ensure that the user, group and permissions for the files are the correct one (www-data for user and group and 644 & 755 for files and folders).
My failure was not to add the <Files></Files> tag. After adding it I finally could access the site. Before having the php configuration under the <Files> tag I was adding those lines in the virtual-host, under the <Directory> tag of my host. Like this:
<Directory /var/www/website/>
AddHandler fcgid-script .php
FCGIWrapper /usr/lib/cgi-bin/php5 .php
Options ExecCGI Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
But this wasn't working! In my virtual machine I have exactly this lines and it works perfectly... so, maybe my solution works for you too.
I hope this will help somebody :)
Edit: This is the forum thread that saved my life: http://forum.parallels.com/showthread.php?t=85413
YOu get the PHP only forbidden error, if you have not enabled ExecCGI in your apache httpd.conf
Options Indexes FollowSymLinks **ExecCGI**
AllowOverride None
Require all granted
hmm have you installed the Apache2 PHP module?
It sounds a bit that you have installed php5-cli but not the apache2 module.
On this page you found a short example. Perhaps i could help you.
It puzzles me really a lot. Had exactly same problem.
Solved it that way:
I added .htaccess file with following content in it:
# Follow symbolic links in this directory.
Options +FollowSymLinks
And everything under that folder suddenly started to work properly.
Adding Indexes and FollowSymLinks to Files tag solved my problem:
<Files ~ "\.php$>"
AddHandler fcgid-script .php
FcgidWrapper "c:/php/php-cgi.exe" .php
Options ExecCGI Indexes FollowSymLinks
allow from all
</Files>