Today I wanted to give my users possibility to test their PHP scripts, but without all the fuss with creating virtual hosts for each one of them. My first and obvious choice was userdir – user creates public_html directory in his home dir, puts there files, and those files are accessible via http://servername/~username/ URL. To enable this behavior you only have to enable userdir module (a2enmod userdir), and remember to set correct permissions to the userdir (chmod +x $HOME) and public_html (chmod 755 $HOME/public_html). I did this, and everything was working fine, except PHP scripts – browser wanted to download them instead of displaying proper processed content. It appeared that apache in Debian has by default PHP disabled for userdirs. To enable scripting in this dirctory, open file /etc/apache2/mods-enabled/php5.conf, find that piece of code:
<IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_value engine Off </Directory> </IfModule>
and disable it, either by deleting or by commenting it out (precede each line with # sign). You can also change php_admin_value engine setting to On, but if you do that, you will be unable to turn off PHP engine in .htaccess files.
Thanks !!
It’s help me !!
Greetings from Argentina.
Eduardo.
Thanks, it worked for me too, I commented this 5 line out :)
I don’t know how I overlooked that… thanks for the tip. :)
just switched from opensuse to try unbuntu – and this tip was usefull to me :)
Thanks, that helped a lot :)
Ok, but if I want to leave this option unchanged, and enable php only for one user. How can I get this?
You can add next entry in config, enabling the php engine just for this user. Whole block would look like this:
This should work. If it’s not, drop me a comment and I’ll test it thoroughly.
Thanks, it helped me. However, it didn’t work immediately. I figured out a bit later that I had to delete the browser cache too.
Good tip – problem identified, googled and fixed in under 2 mins. Thank you :)
Thank you!! it’s was very useful to me ;)
Just what I was looking for! Thx!
Lifesaver… Thanks! Beware of the browser cache, as Jabba said!
Unfortunately it took a lot more than 2 minutes for me to find this site, but luckily I found it at last. Thanks a lot! – Funny thing that I have never seen this documented elsewhere…
Thank you.
Greetings from Montenegro.
thanks. it worked :)
Thanks! This helped
Thanks a lot to!
Thanks man. That helped!
thanks very much.
it’s what I want now .
^_^
Thank you very much. Its saves my time.
many thanks, still useful!
Trevor, UK
Can I enable php as non-super user, of do I need admin support?
@Adrie: there is possibility to enable PHP via .htaccess file, but only if admin allowed you to do so in main Apache config file.
Thanks, saved a large amount of head scratching
Mike
thank you this solution
Thank U, I was looking for this whole day. It worked
I saved a lot of time with your post, thanks a lot
Thank you so much for this.
It took me ages to track down what the problem was. You are a life saver!
Whoever thought this setting was a great idea to introduce needs to be shot in front of their families.
Assuming you had scripts in your home dir, this setting comes with an update and from then on your serving those scripts AS SOURCE, not as parsed script. It’s not even a sechole, I’d almost consider it a deliberate backdoor.
it worked but I had to delete chrome’s cache first
php_admin_value engine On
after I setted engine On,however .php file in /home/user/test.php also downloaded by my browser.I’ll appreciate it if you explain how does this directive work.
Thanks.
if i comment out the IfModule in php5.conf and restart apache, php workd fine.
however, if i set it up like leafnode mentioned above, it does not work.
I also read that setting it up this way is considered bad practice, and you should use a php-in-homedirs.conf file instead. i tried this way, and it does not work.
the only way i can get php to work in public_html is by commenting out IfModule in php5.conf.
can anyone please explain how to set up aphp-in-homedirs.conf file?
I had the same problem after upgrading Ubuntu 11.04 last year. Google suggested me this page and I saw visited link in the results.
Thank’s. Your Post helps me very much with the configuration in apache2 and php5. I only need comment the lines from php5.conf that apache interpreted the php in my public_html.
Thanks a lot. This worked just fine for me.
It didn’t work for me. Neither “#php_admin_value engine Off” nor “php_admin_value engine On” worked.
However, I found the solution thanks to an Anonymous hero (http://fr.php.net/manual/fr/apache.configuration.php#ini.engine, first note) :
Replace : #php_admin_value engine Off
By : php_admin_value engine 1
0 = Off
1 = On
Hope it will help.
Cheers !
I did eneable php on my server this way for users. Just to drop a line to all who said they needed to clear cache… you don’t just restart apache server: sudo service apache2 restart, that schould do the trick.
Thanks so much!
This has solved a problem I had for 2 days! :)
Things work fine now with 3 different php versions.
I recommend this btw:
https://www.tecmint.com/install-different-php-versions-in-ubuntu/#commentlist-container
cheers
Thank you so much sir. ;)
Hi, but…. php file without php extension comments php code. And if I add php extension to public_html and search for: http://marcge.site/~marc/public_html.php
it says 404 not found (The requested URL /~marc/public_html.php was not found on this server.
Apache/2.4.18 (Ubuntu) Server at marcge.site Port 80.).
Any ideas? Thanks.
Thank you! =)
Thank you!!
I stacked over a half of day!!
Commenting out the lines in php7.2.conf helped. Thanks
Thank you very much. Saved my time.
Commenting out the lines in php7.3.conf helped!
Thanks a lot!
This is crazy. Ten years later and this is still not better documented. I have working on this for hours, I tried nginx, lighttpd, and apache and none worked. Then I found this is tried apache again and it worked. How is this not documented in any basic server guides or anything for Ubuntu?
Hello, Eleven years an this solution still works in Debian 10. Thanks!