PHP not running on VirtualHost after upgrading to OS X Yosemite - php

Upgraded to OS X Yosemite and now my virtualhosts are spitting out the PHP file contents instead of executing the file.
This works correctly:
http://localhost
This spits out the file contents onto the screen:
http://localhost/~MYUSERNAME
<?php phpinfo();
http://testing.dev spits out the
<?php and the contents of this file (which is WordPress)
apachectl -t
Syntax OK
/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
<VirtualHost *:80>
ServerName testing.dev
ServerAlias www.testing.dev
DocumentRoot "/Users/*/Sites/testing"
ErrorLog "/private/var/log/apache2/testing.dev-error_log"
<Directory "/Users/*/Sites/testing-env/">
Options Indexes FollowSymLinks
AllowOverride AlL
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 testing.dev
Why is it spitting out the PHP file instead of executing it?
running php -v gives me
PHP 5.5.3 (cli) (built: Aug 28 2013 13:28:31)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
error log shows:
[Mon Nov 17 17:30:08.338143 2014] [auth_digest:notice] [pid 3633] AH01757: generating secret for digest authentication ...
[Mon Nov 17 17:30:08.339341 2014] [mpm_prefork:notice] [pid 3633] AH00163: Apache/2.4.9 (Unix) PHP/5.5.14 configured -- resuming normal operations
[Mon Nov 17 17:30:08.339391 2014] [core:notice] [pid 3633] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'

Upgrading OS X restores the Apache configuration files to their defaults. You’ll need to edit them again. From memory, this includes:
un-commenting the PHP handler so Apache executes files rather than serving them
Setting AllowOverride to All for your web root directory
un-commenting the line that loads the VirtualHosts configuration file

I had the same issue and found there was a missing configuration section in my httpd.conf. After adding the following and restarting Apache PHP files were processed correctly.
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

Related

Trouble configuring custom folder for site (Apache)

I'm trying to configure httpd on fedora, but my two day effort has gotten me nowhere.
I installed httpd and php, added the configuration file for the site, everything is fine. I try to load it and see "access denied." but I have already granted to the apache user and apache group 755 rights (on every folder along the path).
Errors in apache log:
[Mon Jun 06 20:25:18.088420 2022] [negotiation:error] [pid 12656:tid
12758] (13)Permission denied: [client 127.0.0.1:45920] AH00686: cannot
read directory for multi: /home/concasse_master/Desktop/sample/public/
[Mon Jun 06 20:25:18.089421 2022] [proxy_fcgi:error] [pid 12656:tid
12758] [client 127.0.0.1:45920] AH01071: Got error 'Unable to open
primary script: /home/concasse_master/Desktop/sample/public/index.php
(Permission denied)'
localhost.conf:
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /home/concasse_master/Desktop/sample/public
ErrorLog logs/error.log
CustomLog logs/access.log combined
<Directory /home/concasse_master/Desktop/sample/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

apache is crashing not working for a php framework

ServerAdmin webmaster#localhost
DocumentRoot /home/sachin/neuu-dashboard/Telemetry_Backend/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/sachin/neuu-dashboard/Telemetry_Backend/www>
Options FollowSymLinks
AllowOverride All
#Order deny,allow
#Allow from all
Require all granted
</Directory>
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
my apache is keep on crashing when am setting up a php framework
apache is working fine when it is pointing to a default var/www/html
after changing the path it asked enmod and rewrite that also i did but still it is crashing
as soon as i restarted on the very 1st request it crashed
the error code is below from error.log
[Sun Dec 09 13:04:31.953572 2018] [mpm_prefork:notice] [pid 24209] AH00169: caught SIGTERM, shutting down
[Sun Dec 09 13:04:32.048381 2018] [mpm_prefork:notice] [pid 24328] AH00163: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Sun Dec 09 13:04:32.048453 2018] [core:notice] [pid 24328] AH00094: Command line: '/usr/sbin/apache2'
help me out to set up the php framework

Serve php RESTful server with apache2 (ubuntu)

I have a ubuntu machine on which I want to run a php rest server. Here is my default config file:
ServerName localhost
<VirtualHost *:80>
DocumentRoot /var/www/html/otherSite
ServerName www.vlio20_paka.com
Alias /otherSite /var/www/html/otherSite
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/lbserver/public
ServerName www.vlio20_lb.com
Alias /lbServer /var/www/lbserver/public
<Directory /var/www/lbserver/public>
AllowOverride all
DirectoryIndex index.php
Require all granted
</Directory>
</VirtualHost>
In my public directory I have .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When I try to access the server http://MACHINE_IP/lbServer
I am getting Not Found error.
How can I make it work
(I am doing apache restart after each change in the config file)?
Update:
apache2 -t produced:
[Sun Jun 28 12:00:00.789522 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Sun Jun 28 12:00:00.789835 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Sun Jun 28 12:00:00.789970 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Sun Jun 28 12:00:00.790088 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Sun Jun 28 12:00:00.790240 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sun Jun 28 12:00:00.794721 2015] [core:warn] [pid 22089:tid 140102153521024] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sun Jun 28 12:00:00.795136 2015] [core:warn] [pid 22089:tid 140102153521024] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sun Jun 28 12:00:00.795200 2015] [core:warn] [pid 22089:tid 140102153521024] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}
note: the first site is loading fine but the second gives a 404 error.
First this as almost nothing to do with a REST problem. It is a simple configuration error.
Second, for apache2 -t you should run . /etc/apache2/envvars before, because you need some envs variables loaded.
Then the configuration problem.
Your are defining 2 named based Virtualhosts, 1 with the name www.vlio20_paka.com and one with the name www.vlio20_lb.com. The first one is defined first, so if you use an unknown name it will be used, by default.
When you make a query this way:
http://MACHINE_IP/lbServer
the Host header used in your HTTP query is MACHINE_IP, so it's not www.vlio20_paka.com and not www.vlio20_lb.com. If you have no other default virtualhost (something you would find using apache2 -S) the first one will be used.
Let's have a look at the first one:
<VirtualHost *:80>
DocumentRoot /var/www/html/otherSite
ServerName www.vlio20_paka.com
Alias /otherSite /var/www/html/otherSite
</VirtualHost>
If we fall here the path searched on your disk will be DocumentRoot+url, so /var/www/html/otherSite/lbServer. You have a 404, chances are this path does not exists.
Note that your Alias instructions here simply tells Apache that a request to http://www.vlio20_paka.com/ and a request to http://www.vlio20_paka.com/otherSite would both point to the /var/www/html/otherSite/ directory, maybe not what you wanted to do.
Alias is simply a way to define some sort of url symlinks on the url-to-filesystem maps.
Let's now look the second VirtualHost, that you can only reach if you use the right name in your HTTP request, that is not requesting http://MACHINE_IP/lbServer but http://www.vlio20_lb.com/lbServer (for that you could an entry in your /etc/hosts file, on the machine running the http query).
<VirtualHost *:80>
DocumentRoot /var/www/lbserver/public
ServerName www.vlio20_lb.com
Alias /lbServer /var/www/lbserver/public
<Directory /var/www/lbserver/public>
AllowOverride all
DirectoryIndex index.php
Require all granted
</Directory>
</VirtualHost>
So here you set a DocumentRoot at /var/www/lbserver/public but also, via Alias, you tell Apache that a request to http://www.vlio20_lb.com/lbServer/ point to the same entry as http://www.vlio20_lb.com/.
Your best fix would be to add an entry in /etc/hosts a request your test websites with real names, so that you can use Name based VirtualHosting. Or use only one VirtualHost and try things with aliases, but that's usually far from the production settings.
The only thing I think of without seeing more of your config.
Change:
<Directory /lbserver>
DirectoryIndex index.php
</Directory>
To:
<Directory /lbserver>
DirectoryIndex index.php
Require all granted
</Directory>
In ubuntu there is no binary httpd, apache2 used instead:
ricardo#zeus:~$ httpd -t
No se ha encontrado la orden «httpd», quizás quiso decir:
La orden «xttpd» del paquete «xtide» (universe)
La orden «https» del paquete «httpie» (universe)
La orden «http» del paquete «httpie» (universe)
httpd: no se encontró la orden
ricardo#zeus:~$ apache2 -t
Now , paste the command output ;-)

Is HHVM or PHP5 Zend running?

After some struggle, I finally installed Facebook HipHop Virtual Machine in Ubuntu. It is running under FastCGI (Apache 2.22). Below, the service status:
marcelo#marcelo-VirtualBox:~$ service apache2 status
Apache2 is running (pid 3330).
marcelo#marcelo-VirtualBox:~$ service hhvm status
* hhvm is running
marcelo#marcelo-VirtualBox:~$ sudo service hhvm restart
* Restarting HHVM FastCGI Daemon hhvm [ OK ]
marcelo#marcelo-VirtualBox:~$
The same machine has PHP5 module enabled and configured in Apache.
Question:
I want to make sure that I am really rendering PHP code using HHVM and NOT Zend Framework.
All my PHP scripts are running on the webserver. But, when I disable PHP5 module using sudo a2dismod php5 the web server starts to render Internal Server Error.
Does HHVM need PHP5 module enabled to run? Supposedly, since I am using FastCGI, my answer is no. On the other hand, I think that my pages are being rendered by Zend and not HHVM.
What am I missing here? How can I make sure that I am really running HHVM? (in my mind, a clear test is to disable PHP5 module, but, as I said, when I disable, php stops working in the web browser).
If .php is not running with PHP5 module disabled does it means that my HHVM is not properly configured?
P.S.: The script that I am testing is a default Hello World example: <?php echo 'Hello World.'; ?>.
And, It works when I run from command line:
marcelo#marcelo-VirtualBox:/var/www$ sudo hhvm hello_world.php
Hello World.
marcelo#marcelo-VirtualBox:/var/www$
EDIT
Apache error.log:
marcelo#marcelo-VirtualBox:/var/log/apache2$ cat error.log
[Wed May 07 14:02:10 2014] [notice] FastCGI: process manager initialized (pid 2627)
[Wed May 07 14:02:10 2014] [notice] Apache/2.2.22 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
[Wed May 07 14:04:52 2014] [error] [client 127.0.0.1] (2)No such file or directory: FastCGI: failed to connect to server "/var/www/fastcgi/hhvm.fastcgi": connect() failed
[Wed May 07 14:04:52 2014] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server "/var/www/fastcgi/hhvm.fastcgi"
[Wed May 07 14:04:53 2014] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
marcelo#marcelo-VirtualBox:/var/log/apache2$
(Apparently, I should have 'hhvm.fastcgi' file. I only have the directory. Is anything wrong here?)
/var/www directory:
marcelo#marcelo-VirtualBox:~$ ls -l /var/www
total 20
drwxrwxrwx 2 root root 4096 May 6 23:45 fastcgi
-rw-r--r-- 1 root root 31 May 6 21:57 hello_world.php
-rw-r--r-- 1 root root 177 May 6 17:47 index.html
-rw-r--r-- 1 root root 21 May 6 17:50 info.php
-rw-r--r-- 1 root root 0 May 6 17:49 info.php~
drwxr-xr-x 13 997 1001 4096 May 6 18:13 mediawiki-1.22.6
marcelo#marcelo-VirtualBox:~$ ls -l /var/www/fastcgi/
total 0
marcelo#marcelo-VirtualBox:~$
- FastCGI configuration:
I added the lines below, as suggested here: https://github.com/facebook/hhvm/wiki/FastCGI, at the end of apache2.conf file. In other words, after all 'mods-enabled' were already loaded.
# fastcgi added by M. Sardelich
<IfModule mod_fastcgi.c>
Alias /hhvm.fastcgi /var/www/fastcgi/hhvm.fastcgi
FastCGIExternalServer /var/www/fastcgi/hhvm.fastcgi -socket /var/run/hhvm/socket -pass-header Authorization -idle-timeout 300
<Directory "/var/www/fastcgi">
<Files "hhvm.fastcgi">
Order deny,allow
</Files>
</Directory>
AddHandler hhvm-hack-extension .hh
AddHandler hhvm-php-extension .php
Action hhvm-hack-extension /hhvm.fastcgi virtual
Action hhvm-php-extension /hhvm.fastcgi virtual
</IfModule>
To make sure that you are in fact running HHVM, run the following command:
phpinfo();
It should produce HipHop as the output, instead of the normal php info.
To check for it programmatically, you can use the following (also mentioned here):
if (defined('HHVM_VERSION')) {
echo "ruuning HHVM";
}
As correctly noticed (thanks #Petah), my FastCGI config was wrong.
I changed it to the snippet below (from here: http://www.mediawiki.org/wiki/HHVM/Vagrant) and everything is working! (add it to your apache2.conf or httpd.conf file)
<IfModule mod_fastcgi.c>
Alias /hhvm.fastcgi /var/www/fastcgi/hhvm.fastcgi
FastCGIExternalServer /var/www/fastcgi/hhvm.fastcgi -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 300
<Directory "/var/www/fastcgi">
<Files "hhvm.fastcgi">
Order deny,allow
</Files>
</Directory>
AddHandler hhvm-hack-extension .hh
AddHandler hhvm-php-extension .php
Action hhvm-hack-extension /hhvm.fastcgi virtual
Action hhvm-php-extension /hhvm.fastcgi virtual
</IfModule>

My Apache localhost is not working - Forbidden

I am completely new to PHP and web servers. I have a test PHP file. When I run this in the terminal I can see that PHP is working "php /Users/Fryza/Sites/phptest.php"
When I type these into the web browser I get 403 Forbidden error:
http://localhost/~fryza/phptest.php
http://localhost/phptest.php
I have a file (/private/etc/apache2/users/fryza.conf) that has these contents:
<Directory "/Users/fryza/Sites/">
Options FollowSymLinks Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
My DocumentRoot in private/etc/apache2/httpd.conf is /Users/Fryza/Sites/
I also have this directory /Library/Webserver/Documents - I used to have this as the document root but it wasn't working in this location either.
I have read through a bunch of stack overflow posts but they are not working for me.
The apache server definitely is running. PHP is working. Just can't get the files to load in the browser.
I'm running Mountain Lion
I did the same tutorial as the guy here and am having the same problem:
403 Forbidden error when accessing localhost on Mac OS X10.8
This is the error log:
[Mon Oct 28 17:57:17 2013] [notice] caught SIGTERM, shutting down
[Mon Oct 28 17:57:17 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Mon Oct 28 17:57:17 2013] [warn] module php5_module is already loaded, skipping
[Mon Oct 28 17:57:17 2013] [notice] Digest: generating secret for digest authentication ...
[Mon Oct 28 17:57:17 2013] [notice] Digest: done
[Mon Oct 28 17:57:17 2013] [notice] Apache/2.2.24 (Unix) DAV/2 PHP/5.3.26 mod_ssl/2.2.24 OpenSSL/0.9.8y configured -- resuming normal operations
Access Log:
::1 - - [28/Oct/2013:18:05:38 -0700] "GET /~fryza/phptest.php HTTP/1.1" 403 220
If you are running skype, your localhost will not run because skype also use the port as localhost. but when you run localhost first before skype it will work.
but when skype run first, you must end task by pressing ctr+alt+del then task manager and select skype then end task..
but that's only for info..
the real deal here is how your localhost work..
try to do this.
click the icon of your wamp server on the right bottom of your computer..
then click Restart All Services..
And run your localhost.
That's all I know.. Im a newbie here.. tnx :)
I finally figured it out. I don't know WHY this worked - but it did.
I changed my fryza.conf file from:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
To:
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
Can someone explain why this worked?

Categories