Apache: The requested URL / was not found on this server. Apache - php

I've installed Apache 2.2 server and PHP 5.3 on Windows XP SP3. After the initial install, Apache loaded the test page, i.e.,
http:/localhost (C:/Program Files/Apache2.2/htdocs/index.html) showed "It works!".
After configuring Apache and installing PHP, trying to load http:/localhost/phptest.php i.e. (C:/testsite/htdocs/phptest.php).
But this throws an error:
Not Found. The requested URL /phptest.php was not found on this server.
I also get the same error now loading
http://localhost
httpd.conf edits:
ServerName localhost:80
DocumentRoot "C:/testsite/htdocs"
<Directory "C:/testsite/htdocs">
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
LoadModule php5_module "c:/testsite/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddHandler application/x-httpd-php .php
PHPIniDir "C:/testsite/php"
File php.ini edits:
include_path = ".;C:\testsite\php\includes"
extension_dir = "C:/testsite/php/ext/"
System path:
The PHP directory was added to the Windows path, e.g.
PATH=C:\Windows\System32;C:\many_dir;C:\testsite\php
The only errors in the Apache error.log are:
Warning: DocumentRoot [C:/Program Files/Apache Software Foundation/Apache2.2 /docs/dummy-host.localhost] does not exist
Warning: DocumentRoot [C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost] does not exist
Warning: DocumentRoot [C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host.localhost] does not exist
Warning: DocumentRoot [C:/Program Files/Apache Software Foundation/Apache2.2/docs/dummy-host2.localhost] does not exist
The Apache service restarts successfully and is running. I can't find anything amiss. Can anyone spot any stupid errors?

Try changing Deny from all to Allow from all in your conf and see if that helps.

In httpd.conf file you need to remove #
#LoadModule rewrite_module modules/mod_rewrite.so
after removing # line will look like this:
LoadModule rewrite_module modules/mod_rewrite.so
And Apache restart

I had the same problem, but believe it or not is was a case of case sensitivity.
This on localhost:
http://localhost/.../getdata.php?id=3
Did not behave the same as this on the server:
http://server/.../getdata.php?id=3
Changing the server url to this (notice the capital D in getData) solved my issue.
http://localhost/.../getData.php?id=3

Non-trivial reasons:
if your .htaccess is in DOS format, change it to UNIX format (in Notepad++, click Edit>Convert )
if your .htaccess is in UTF8 Without-BOM, make it WITH BOM.

Related

Netbeans lamp php interpereter not working

I am following this netbean guide https://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html#createDocumentRootLocation
But I am stuck at creating the virtual host. I try to do as in the tutorial but there is no <Directory> tags in the "000-default.conf" file. I kept going and ignored that.
I did as in the tutorial and put it in my /home/user/public_html. but now when I run it the php code is not interpreted
If I a2ensite the default I can access virtual host set at /var/www/html and that php is interpreted
There are no errors the php is just not being interpreted, what am I doing wrong here.
Im using:
Ubuntu 18.10 LTS
PHP 7.2.10-0ubuntu1 (cli)
Apache/2.4.34
Edit:
My "TestPhp.conf" file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/jelly/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit 2 and answer:
Turned out to be some lines in my "php7.2.conf" file that had to be commented out as the out-commented lines in that file explains. as running PHP scripts in user directories is disabled by default.
what is your test script like? if you start with <? try <?php instead.
Also check php.ini for expose_php = false (may hide php form the headers)
If the error persists, include your config and test script, along with any errors in http.log
You need to find a config file which enables php
I only have a Ubuntu, and the files in my installation may vary compared to yours:
Enable PHP engine [php.load]
This is the part that loads the PHP interpreter, and allows you to use php scripts
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Enable .php file directed to php [php5.conf]
This is the part tells apache to send *.php (and in this case some other extensions like *.phtml) to the php interpreter
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Require all denied
</FilesMatch>
EDIT I noticed that you were on UBUNTU as well
use sudo a2enmod and select php in the list
EDIT 2
Note that if you are following a general Guide and not a UBUNTU specific one, you may encounter several issues since the UBUNTU apache config is spread out in several files, as opposed to one big file, which is what you may encounter in other distros

How to execute php code in html files (php-fpm and apache 2.4) on centos 7

As we have upgrade OS from centos 6.9 to Centos 7 on server. We have installed "Apache/2.4.6" and "PHP 5.6.36 (fpm-fcgi)" on this server. But we are facing problem to execute "PHP Code" in ".html" files. PHP code working fine in ".php file" but not in ".html files". I have ready many blogs but no where mentioned exact solution.
Can you please guide us how we can execute PHP code in .html files.
Note : We are using Apache 2.4, PHP-FPM and MPM_worker on centos 7.
After change below in files "/etc/php-fpm.d/www.conf" and "/etc/httpd/conf.d/php.conf" :
"security.limit_extensions = .php .php3 .php4 .php5 .htm" // in www.conf
and
SetHandler "proxy:fcgi://127.0.0.1:9000" // in php.conf
PHP code working in htm files but due to to these changes every html files renders as php. We want only php code render as php not html code render by php.
Your help would be appreciated.
This is how I configure Apache / PHP-FPM for a virtual host. It's not a public server so I'm only using HTTPS. This is from /etc/httpd/conf.d/ssl.conf:
<VirtualHost _default_:443>
DocumentRoot "/home/myvhost/public_html"
ServerName myvirtualhost.com:443
<Directory "/home/myvhost/public_html">
allow from all
Options FollowSymLinks SymLinksIfOwnerMatch
Require all granted
php_admin_value open_basedir /home/myvhost/public_html
</Directory>
SuexecUserGroup myvhost myvhost
ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/home/myvhost/public_html/$1
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</FilesMatch>
</VirtualHost>
And this is from /etc/php-fpm.d/myvhost.conf (copied from the default PHP-FPM configuration file):
[myvirtualhost.com]
user = myvhost
group = apache
listen = 127.0.0.1:9000
security.limit_extensions = .php
So basically you could just copy the "ProxyPassMatch" line and change php to html and do the same thing with "FilesMatch". You can also modify the regex but I'm not really good at that.

Apache 2.4 does not execute PHP

I have a problem with apache and PHP 5.4 running on a centOS 7 machine.
Apache host have the directory index option:
<Directory my/directory>
Options Indexes
</Directory>
The directory where apache points to contains a index.php. But when I navigate the browser to the related website, the browser only shows the php code.
I've already checked, if php is activated in http.conf - and it is. The application (zabbix) should work with this version of PHP and all necessary SQL- and PHP-plugins are installed.
No more Google suggestions for this problem - any of you an idea how to solve this?
Output of /etc/http/conf.d/php.conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
#<FilesMatch \.phps$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
Please check below thinks in your httpd config file
LoadFile "D:/wamp/php/libpq.dll" // Your sepcified path
LoadModule php5_module "D:/wamp/php/php5apache2_4.dll" // Your sepcified path
AddType application/x-httpd-php .php // Your sepcified path
PHPIniDir "D:/wamp/php" // Your sepcified path
You probably installed PHP from the distribution packages. If so, make sure Apache was restarted after that:
sudo systemctl restart httpd
If that does not help, try reinstalling the PHP packages, then restarting Apache.
If that does not help, post the contents of /etc/httpd/conf.d/php.conf here.

Virtual Host not parsing PHP

Alright, I have spent hours searching through very similar questions but I still don't seem to have found the answer:
I have set up a virtual host with the following in my httpd-vhosts.conf
Listen 80
<VirtualHost *:80>
ServerName test.dev
ServerAlias test.dev
DocumentRoot "/Users/OrangeSoda/OneDrive/Projects/Test/Website"
ErrorLog "/private/var/log/apache2/test.dev-error_log"
CustomLog "/private/var/log/apache2/test.dev-access_log" common
<Directory "/Users/OrangeSoda/OneDrive/Projects/Test/Website">
Options all
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
In my http.conf I have Include /private/etc/apache2/extra/httpd-vhosts.conf as well as LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so uncommented.
When I go to test.dev/index.php which just has <?php echo "PHP TEST"; ?>, I see the contents of the file output as a string.
It seems as though PHP is not enabled and is therefore not being recognized.
If i go to localhost, I do see the "It Works!" page, so I know php is working, just for some reason not on my virtual host.
Someone suggested to put php_admin_flag engine on but that just makes the whole page crash.
Does anybody understand why php is not enabled here?
Have you checked if port 80 is opened? It might help more if you include detailed log.
You're on the right track but you need to actually load php onto the virtual host. On the <Directory> entry, add these lines :
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
I got the solution from here.
It looks like mod-php may not be installed. What OS are you on?
On Ubuntu/debian:
sudo apt-get install php5
on redhat:
sudo yum install php
The solution was that while php was enabled, for some reason the default setting in httpd.conf was not to read .php files as .php.
Although I am not really sure why that would not be the default setting, I added the following to my httpd.conf and now it works just fine:
AddType application/x-httpd-php .php

Local host not working after changes in httpd.conf - apache

OSX Yosemite 10.10
2.4 apache
Error: After localhost in browser, I get below error:
The requested URL / was not found on this server.
Following are the changes I've made:
1
file httpd.conf
changed username to mine, it belongs to groups _www So group is unchanaged.
uncommented
LoadModule php5_module libexec/apache2/libphp5.so
In
etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/users/*.conf
#LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf
--
ServerName localhost
File /etc/apache/users/myname.conf has Directory pointing to:
/Users/myname/Sites
With
Options Indexes MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
Points:
- I've not edited Directory or DocumentRoot in httpd.conf
- I have info.php in /users/myname/Sites folder
- Am I running it incorrectly?
Tried in browser as:
localhost, localhost/myname/Sites/info.php, localhost/info.php
Nothing worked.
apachectl configtest
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist
Syntax OK
Restarted server every time I made changes.
chmod 777 ~/Users/myAccount/Sites
Please guide me here.
PS: I am fresh to apache, webserver, config file settings.

Categories