File not being found on server Apache - php

I'm simply trying to open a php file I have created and keep getting this.
The requested URL /~Wade/HelloWorld.php was not found on this server.
I just recently did a reinstall on my Mac. Which shouldn't have affected my .conf files. With that being said, I can still typein localhost in my URL and it returns "It Works" so I know the server is still up? I'm confused

(Note: Assuming you use a recent version of OS X)
Since a couple of versions (not sure which, but at least since Mavericks), userdir Sites are disabled in the httpd.conf shipped with OS X.
Assuming you know how to edit files owned by root, remove the # from these two lines in /etc/apache2/httpd.conf:
#LoadModule userdir_module libexec/apache2/mod_userdir.so
#Include /private/etc/apache2/extra/httpd-userdir.conf
Next, create a file in /etc/apache2/users/. Its name doesn't matter, as long as it ends in .conf.
Its contents should be:
<Directory "/Users/Wade/Sites">
Require all granted
# The next two lines are optional and may bee too lax for
# production, but I deem them good for a development environment.
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
Also, in every httpd.conf that has shipped with OS X for as long as I can remember, PHP has been disabled by default. So you'll also have to remove the # from this line in httpd.conf:
#LoadModule php5_module libexec/apache2/libphp5.so
You probably also want to set the ServerName directive, to suppress a startup warning.
There's a commented out line somewhere that reads
#ServerName www.example.com:80
Either change it (and remove the #), or just add a new one after it that reads
ServerName 127.0.0.1:80
If you want your server to be accessible from other devices in your local network, replace 127.0.0.1 with 0.0.0.0, and if you use a different post, adjust accordingly.
After that, run sudo apachectl -k restart to restart Apache and you should be good to go.

Related

Site only opens in localhost

I'm setting up a windows server 2019 with apache 2.4 and PHP 5.6.
I was able to load the phpinfo in the browser with localhost.
I am trying to get the sites to open up in an htdocs folder on another drive (D:) using an alias that, according to our networking team is quoting, "DNS is set up correctly pointing to newprod.company.name.com", with "newprod" being the acutal alias.
In my httpd.conf file, I have the following settings:
Define SRVROOT "c:/Apache24"
ServerRoot "${SRVROOT}"
Listen 80
The above is pointing at the C: drive where Apache24 is located.
LoadModule rewrite_module modules/mod_rewrite.so
I have the above module uncommented. There are several other modules that have been uncommented, but the one above seems to be one of the main modules that, according to various Apache setup tutorials, is the main module.
ServerAdmin my.company#company.com
ServerName newprod.company.name.com:80
ServerName Localhost:80
According to various tutorials, the above seems to be accurate. I have compared my previous httpd.conf files, and they work using very similar configurations, including Localhost:80.
DocumentRoot "D:/htdocs"
<Directory "D:/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
The main part to focus on above the D:/htdocs. This is where I figured the sites should be opening from, as well as opening using the alias.
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
The above is typical for an Apache setup, per various tutorials.
<VirtualHost newprod.company.name.com:80>
ServerName newprod.company.name.com
Redirect / http://newprod.company.name.com/
</VirtualHost>
I use the above on another server (with a different alias) without any issues.
PHPIniDir "C:/PHP5.6"
AddHandler application/x-httpd-php .php
LoadModule php5_module "C:/PHP5.6/php5apache2_4.dll"
Then finally, the above is to ensure Apache will read PHP.
I have two other servers that are loading the sites with their own aliases with no problem. I literally went line for line trying to ensure everything matches. The only things that don't match is the PHP configurations at the bottom of the file. My other two servers are using PHP 7.4, while the problem server is using PHP 5.6.
Why aren't my sites loading using the alias I provided?
If you're using
ServerName newprod.company.name.com:80
ServerName Localhost:80
in main httpd.conf (or main apache config file), get rid of
ServerName Localhost:80
The vhost configuration
<VirtualHost newprod.company.name.com:80>
ServerName newprod.company.name.com
Redirect / http://newprod.company.name.com/
</VirtualHost>
is probably going to create a redirect loop: if that's all the configuration inside the virtualhost, get rid of it: it's useless.
Is port 80 on your apache server reachable from another pc? Are you able to telnet from a pc in the same lan on po 80 of apache server? Have you checked if the firewall is dropping the first syn packet?

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

PHP Symfony apps on OSX El Capitan apache

I have installed the symfony_demo application on El Capitan (10.11.2)
If I run the inbuilt PHP server as follows:
php app/console server:run 127.0.0.1:8111
the demo application is Live at localhost:8111
but if I access the application via El Capitan's inbuilt apache instance (by copying it into my <user>/Sites directory), I just get a directory listing.
Note that I do have PHP enabled on apache, and other PHP-based applications run through apache as currently configured (e.g. Joomla).
What more configuration of apache do I need?
Addendum:
I am running the Server version of the OS. I read that there exists another apache configuration file at: /Library/Server/Web/Config/apache2/httpd_server_app.conf
But uncommenting the vhosts .conf and .so directives and restarting 'Websites' via the Server app in this file made no difference to the behaviour
You'll need to uncomment few lines in your /etc/apache2/httpd.conf. Remove the # in front of the following lines if it's there (these lines are in different parts of the file):
LoadModule php5_module libexec/apache2/libphp5.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
Include /private/etc/apache2/extra/httpd-vhosts.conf
Next, you can edit /etc/apache2/extra/httpd-vhosts.conf to define your virtual hosts. For example if your project is located in /Users/username/Sites/symfony (replace "username" with your username, and "symfony" with you project directory):
<VirtualHost *:80>
ServerName symfony.dev
DocumentRoot "/Users/username/Sites/symfony/web/"
<Directory "/Users/username/Sites/symfony/web/">
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
</VirtualHost>
In the example I used a fake domain symfony.dev. If you want to use it you'll need to add it to your /etc/hosts file (add a new line there):
127.0.0.1 symfony.dev
After changing apache's configuration don't forget to restart it:
sudo /usr/sbin/apachectl restart
You might need to adapt the vhost config to your needs. Read more about configuring the web server in the Symfony documentation.
Success!
The pivotal information here is that the Server version of OSX has it's own configuration which disables .htaccess redirection by default.
After finding the setting in Server > Websites > Server Website (edit) > Edit Advanced Settings > "Allow overrides using .htaccess files
And restarting Websites, the symfony demo works fine at http://localhost/symfony_demo/web/
n.b.: No need for vhosts - that's merely a convenience

Can't view index.php of Zend Framework 1.0 after setting up Apache/Host requirements?

UPDATE: the following error is coming up in the Apache error logs...
[Sat Dec 08 16:41:39 2012] [error] [client 127.0.0.1]
PHP Fatal error: require_once():
Failed opening required 'Zend/Application.php'
(include_path='/Library/WebServer/Documents/quickstart/library:.:/php/includes:/Users/markmcdonnell/Dropbox/Library/PHP/ZendFramework-1.12.0/library')
in /Library/WebServer/Documents/quickstart/public/index.php on line 18
I'm using Mac OSX 10.8.2 (Mountain Lion) and I'm having problems getting the Zend framework set-up and running (just the basic QuickStart).
I'm using Apache 2.2.22
My localhost files are accessible from /Library/WebServer/Documents
I have PHP 5.3.15 running as well.
I've created a new project via the command line (using the zf.sh file) called 'quickstart' (as per the section on the Zend website recommends) and that is stored here: /Library/WebServer/Documents/quickstart
I've followed both the official Zend website instructions and also an online book about installing Zend: http://www.survivethedeepend.com/zendframeworkbook/en/1.0/creating.a.local.domain.using.apache.virtual.hosts
My php.ini (/private/etc/php.ini) file has been updated to include the path to the library folder inside the ZendFramework directory...
include_path = ".:/php/includes:/Users/<home>/Dropbox/Library/PHP/ZendFramework-1.12.0/library"
I've updated /etc/apache2/httpd.conf so it includes...
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
# Ensure "localhost" is preserved unchanged pointed
# to the default document root for our system.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName quickstart.local
DocumentRoot /Library/WebServer/Documents/quickstart/public
SetEnv APPLICATION_ENV "development"
<Directory /Library/WebServer/Documents/quickstart/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
...I've also updated /etc/hosts so it includes...
127.0.0.1 localhost
127.0.0.1 quickstart.local
I'm restarting Apache using sudo apachectl graceful (I've also used sudo apachectl restart)
So if I try and now access http://localhost/ I see my /Library/WebServer/Documents directory and I can see PHP is running still with no problems. But if I try and access http://quickstart.local/ I just get an empty page?
Can any one advise as to what the problem might be, what I'm missing and what I can do to get the initial 'welcome' page to display.
I'm sure I'm just missing someone small, but it's obviously causing problem enough for the basic page not to show.
Thanks.
Mark
Just for others who may have followed this. The answer by Kamil, above, will work, but opens a security hole outside Apache's security configuration. That's fine as long as you know it and have another layer of security above Apache.
Another way to resolve the problem is to put the ZendFramework somewhere inside the root directory's hierarchy. Like:
DocumentRoot/Library/WebServer/Documents/ZendFramework-1.12.0/library
or
DocumentRoot/Library/WebServer/Documents/quickstart/public/ZendFramework-1.12.0/library
Any path that's inside the root directory of your Apache server.
Maybe a user permissions issue between the Zend files and the Apache process.
Since you can create the project using zf.sh, the Zend files are obviously there. But the fail you get via Apache suggests that the Zend files might not be accessible via the Apache process (that is, the user under which the Apache process runs).
$ chmod 0777 /Users/markmcdonnell/Dropbox/Library/PHP/ZendFramework-1.12.0/library
to test.
You could probably get away with much less expansive permissions - 0644, for example - but I confess I'm terrible at that aspect of it. ;-)

While intsalling cakephp on ububtu 11.10 give rewrite_module error

I am attempting to install cakephp-1.3 on Ubuntu 11.10. I have finished all the required changes in the configuration file as mention in http://book.cakephp.org.
It shows all database connections as being setup.
Temp folder is rewrite-able.
But it give me an apache module rewrite error. I have checked the apache rewrite mode and it is enabled.
But I still get the URL_REWRITE error repeatedly and am unsure how to proceed. All help appreciated.
You should check if mod_rewrite is actually on. To do that, make a php file with
<?php php_info(); ?>
in your web root folder. At Loaded Modules you should see mod_rewrite.
If not, check for the line:
LoadModule rewrite_module modules/mod_rewrite.so
In httpd.conf (apache2.conf in UBUNTU > /etc/apache2/apache2.conf). It must be uncomented (without ; in front).
Check if AllowOverride option is on for your project. To do that, add the following line at the end of httpd.conf (apache2.conf in UBUNTU)
<Directory "/var/www/myProjectName">
AllowOverride all
</Directory>

Categories