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
Related
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?
I have successfully installed suhosin in my server and I'm blocking the devil PHP eval function on some virtualhosts with this configuration:
<VirtualHost 123.123.123.123:80>
<Directory /var/www/html/www.example.com>
#SUHOSIN
php_admin_value suhosin.executor.disable_eval On
</Directory>
</VirtualHost>
However, I need to enable eval on some specific URL since it is used by the platform on some specific cases. I've tried the following:
<VirtualHost 123.123.123.123:80>
<Directory /var/www/html/www.example.com>
# SUHOSIN
php_admin_value suhosin.executor.disable_eval On
</Directory>
<Location "/some/path">
# Reenable eval for this path
php_admin_value suhosin.executor.disable_eval Off
</Location>
</VirtualHost>
And also with the tag LocationMatch, with no success (it's like if it was not there: no effect at all).
Any ideas how can I have this directive working just for a specific path?
Thanks
I am not using SUHOSIN, I solved with different php.ini files for each website.
Something like:
<VirtualHost 123.123.123.123:80>
[...]
PHPINIDir /path/to/specificinifile
[...]
</VirtualHost>
Hope this helps.
I am running Apache 2.2.26 with PHP 5.4.24 on Mac OS X 10.9.4. I have several virtual hosts running on this system, and all of them run successfully. I'm trying to add environment variables to one of the virtual hosts, and I don't want them to be in .htaccess so my only option is adding them to the in httpd-vhosts.conf.
The problem is that the environment variables don't appear after I install them in the httpd-vhosts.conf file (and, of course, after I restart Apache "sudo apachectl restart"). If, however, I add them to .htaccess (just for comparison purposes), they appear just fine. What am I missing?
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "/path/to/mysite.com"
SetEnv siteid 1234
ErrorLog "/var/log/apache2/mysite.local-error_log"
</VirtualHost>
I've also double-checked my php.ini file to be sure there's nothing prohibitive there, and the only relevant line looks good:
variables_order = "GPCSE"
Again, just to be clear, my virtual hosts RUN FINE. It's just that the environment variables don't appear when called in my PHP code. I've tried each of these three commands:
echo $_SERVER["siteid"];
echo getenv("siteid");
echo apache_getenv("siteid");
What can I be doing wrong??
This has been an excruciating quest for me, but I have found a very simple yet obscure answer. First of all, let me clarify my earlier question, that what I didn't realize is my Mac runs OS X Server, which has effectively altered the way Apache runs on my system.
With that said, below is the equivalent httpd-vhosts.conf file PER VIRTUAL HOST installed on my system via OS X Server application.
/Library/Server/Web/Config/apache2/sites/0000_any_80_mylocalsite.conf
Clearly, "80" is the port for regular http requests and "mylocalsite" is the name of the local virtual host that I created (within the OS X Server application). Now that this file has been produced by OS X Server, I can now edit it as follows:
sudo vi /Library/Server/Web/Config/apache2/sites/0000_any_80_mylocalsite.conf
Which opened a config file looking similar and almost exactly like a normal httpd-vhosts.conf file (note the SetEnv testid "1234" line which is the solution I have been searching for, and this can only be done manually and not through the OS X Server application)...
<VirtualHost *:80>
ServerName mysite.local
ServerAdmin admin#example.com
DocumentRoot "/my/local/docroot/path/to/mysite.com"
SetEnv testid "1234"
DirectoryIndex index.html index.php /wiki/ /xcode/ default.html
CustomLog /var/log/apache2/access_log combinedvhost
ErrorLog /var/log/apache2/error_log
<IfModule mod_ssl.c>
SSLEngine Off
SSLCipherSuite "ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM"
SSLProtocol -ALL +SSLv3 +TLSv1
SSLProxyEngine On
SSLProxyProtocol -ALL +SSLv3 +TLSv1
</IfModule>
<Directory "/my/local/docroot/path/to/mysite.com">
Options All -Indexes -ExecCGI -Includes +MultiViews
AllowOverride All
<IfModule mod_dav.c>
DAV Off
</IfModule>
<IfDefine !WEBSERVICE_ON>
Deny from all
ErrorDocument 403 /customerror/websitesoff403.html
</IfDefine>
</Directory>
</VirtualHost>
PLEASE, I hope this helps someone else someday. I have spent far too much time searching for this solution, only to stumble on it in brute-force tactics, and I would like to know this hopefully saves someone hours of searching themselves.
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.
I'm trying to set up a new Zend project using Zend Server CE under OS X 10.6
First, I have downloaded and successfully installed Zend Server CE: opening http://localhost:10081 in my browser shows the dashboard, and everything seems to be working fine.
Than I created a new project, following the tutorial:
$ cd /usr/local/zend/apache2/htdocs
$ /usr/local/zend/share/ZendFramework/bin/zf.sh create project quickstart
The project was created without errors.
Then I added
<VirtualHost quickstart.local:10088>
ServerName quickstart.local
DocumentRoot /usr/local/zend/apache2/htdocs/quickstart
SetEnv APPLICATION_ENV "development"
<Directory /usr/local/zend/apache2/htdocs/quickstart>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
to the /usr/local/zend/apache2/conf/extra/httpd-vhosts.conf file and the entry 127.0.0.1 quickstart.local to my /etc/hosts/ file.
Finally, I restarted the Apache bundled with Zend Server CE.
But now, if I open http://quickstart.local:10088/ in my browser, I see this:
instead of the default index view I was expecting.
What a I missing?
Thanks.
I was having a hell of a time trying to figure out the directions from "Zend Framework Quick Start" Even though you didn't solve it, you pointed me in the right direction and I was able to get it. You probably figured it out by now but for everyone else coming to this page here goes:
By default the httpd.conf file has the 'Include httpd-vhosts.conf' line commented out. So edit /usr/local/zend/apache2/conf/httpd.conf to change this line:
#Include conf/extra/httpd-vhosts.conf
to this line:
Include conf/extra/httpd-vhosts.conf
We are almost done now. The code you added to /usr/local/zend/apache2/conf/extra/httpd-vhosts.conf wasn't quite correct. It should be:
<VirtualHost quickstart.local:10088>
ServerName quickstart.local
DocumentRoot /usr/local/zend/apache2/htdocs/quickstart/public
SetEnv APPLICATION_ENV "development"
<Directory /usr/local/zend/apache2/htdocs/quickstart/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Notice how I added the /public onto the paths. Otherwise you won't point to the index.php file. Now restart Apache using this command sudo /usr/local/zend/bin/zendctl.sh restart
and it should now be working.
Happy coding :)