I have installed a collection of PHP versions from Remi Repositories, which may be ignored, for the question itself, but kept for the sake of understanding the processed I tried.
They work fine from command line, but I'd like to use them with Apache 2 (httpd on Fedora 24), running multiple virtual hosts as in:
php54.test
php55.test
php56.test
php70.test
php71.test
I have created the VirtualHost conf files and each one is working fine.
I want to run each corresponding php version (accordingly to the suggestive ServerName), but I can't find how to load PHP from each Virtual Host.
I couldn't find the corresponding Remi libphpX.so for loading them as modules:
<VirtualHost *:80>
ServerName php54.test
DocumentRoot /var/www/php54
#SOMETHING LIKE THIS...
LoadModule php??_module modules/libphp??.so
</VirtualHost>
I have, and this is not news, a shared hosting that allows me to change PHP version from .htaccess and I can do something like this:
AddHandler application/x-httpd-php54 .php
AddHandler application/x-httpd-php55 .php
AddHandler application/x-httpd-php56 .php
AddHandler application/x-httpd-php7 .php
AddHandler application/x-httpd-php71 .php
I may look like a dummy now, but how can I do the same .htaccess switching for having multiple PHP versions available?
I probably am not knowing what and how to search on Google to find the best matched answer.
You cannot use multiple versions of mod_php.
Better solution is to use php-fpm (the Fastcgi Process Manager), using in each vhost a SetHandler to fcgi server:
SetHandler "proxy:fcgi://127.0.0.1:9070"
Or (using unix domain socket)
SetHandler "proxy:unix:/var/opt/remi/php70/run/php-fpm/www.sock|fcgi://localhost"
This is described in this article : My PHP workstation.
Related
Overview
I'm trying to host a few legacy PHP apps on Heroku with Apache. They all relied on the following deprecated syntax to parse any unknown file types (without the .php extension) as PHP.
DefaultType application/x-httpd-php
This has been replaced by AddType in Apache 2.4 (Heroku currently uses v2.4.37). Heroku also uses mod_proxy_fcgi to process PHP files via fcgi://heroku-fcgi.
Issue
I have a file foo.test and I want to have it handled by PHP FPM. Taking cues from the docs and the default Apache config provided by Heroku, here's what I've tried:
# .htaccess
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}">
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
# apache_app.conf (properly loaded via Procfile)
ProxyPassMatch "^/(.*\.test(/.*)?)$" "fcgi://heroku-fcgi/app/$1"
With both of these I get a plain-text 403 Access denied. response from PHP FPM. I'm sure both configs are properly loading and pointing to the FCGI handler because changing the endpoint results in other errors.
My Apache skills are long since rusty and I can't seem to find any good pointers online. The Apache error log is also clean. Any ideas (without the obvious "change all extensions to PHP, you dumbass") would be appreciated!
Fairly obvious solution. PHP FPM has its own configuration with a security.limit_extensions flag. It defaults to .php.
The solution was to unset that value: security.limit_extensions =. This naturally can pose some security threats, but these apps are only going up for static demo.
I was using heroku/heroku-buildpack-php but forked that to update this file. The htaccess FilesMatch should work now but I just ended up placing it into the Apache config file to avoid repetition across the sites I'll be serving.
security.limit_extensions can be customized with a configuration file passed as a Procfile argument.
https://devcenter.heroku.com/articles/custom-php-settings#php-fpm-settings
PHP-FPM settings:
In addition to php_value and php_flag for php.ini specific settings, any pool specific PHP-FPM configuration directives are valid in that configuration file, so you can use it to fine tune PHP-FPM’s behavior.
So you can set up it like the following
Procfile
web: vendor/bin/heroku-php-apache2 -C apache.conf -F fpm_custom.conf web/
apache.conf
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}"> # make sure the file exists so that if not, Apache will show its 404 page and not FPM
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
fpm_custom.conf
security.limit_extensions = .php .test
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
I have tried reinstalling PHP. PHP is working, and Apache2 is running. I don't know why it's not opening in a browser and displaying normally.
Just so you know - my httpd.conf is empty - and instead I have everything in apache2.conf. This is because I'm using Ubuntu.
Can you help me? I know it's something simple, but I can't seem to find the answer.
Have you virtual host on this project?
Are you open php file with http://localhost/file.php or directly like file://...../file.php ?
In your apache conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Don't forget to restart apache afterwards. Let me know how it goes.
In my case there was a modification of the /etc/apache2/mods-enabled/php5.conf by module userdir
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>
The solution is inside the config file, just comment the lines from <IfModule mod_userdir> to </IfModule>.
Try
sudo a2enmod php5
in terminal.
Assuming you are using php 5 :)
If you are using php5 the complete solution would be
sudo apt-get install libapache2-mod-php5
Then
sudo a2enmod php5
I recently had this problem, but only when accessing my site's root (e.g. http://example.com) - it worked as expected when accessing index.php explicitly (e.g. http://example.com/index.php).
The issue was that before creating index.php, I had an index.html file in the web root, but then I renamed it to index.html.bak to 'move it out of the way'. Unfortunately, that doesn't move it out of the way. For whatever reason, Apache will serve that file up with a MIME type of application/x-trash.
(As the /etc/mime.types file contains a line reading "application/x-trash ~ % bak old sik")
Maybe that will help someone else who is scratching their head as I was.
Also, when moving a site and you encounter this, make sure your .htaccess file doesn't specify a different method handler for php. We ran into this moving a wordpress site for a client.
Had same problem - and it was in the .htaccess file I had accidentally downloaded from the live server. Once you've deleted the .htaccess file, you will need to clear your cache to be able to load the .php file in your browser via http://
I wanted to use postgres with php, and the default install of mac os x, doesn't have the postgres php modules installed. I tried using the entropy.ch install not realizing that it was incompatible with mac os x 10.6. After removing the entropy code, attempts to render php files responded with a textual representation of the php file.
Additional configuration of php is called out in this line:
Include /private/etc/apache2/other/*.conf
of /private/etc/apache2/httpd.conf
I believe I had accidentally deleted the php configuration file that should be in that directory. I created a file named php.conf and put the following lines into that file:
<FilesMatch
"\.php$|\.php5$|\.php4$|\.php3$|\.phtml$|\.phpt$">
SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
That enabled apache to set the right mime type on the request, pass it to php which then rendered the code. Painful time wasting mistake.
In addition you need this also:
<IfModule dir_module>
DirectoryIndex index.html index.php index.htmls index.htm
</IfModule>
You might want to consider using XAMPP or MAMP fore development purposes. I think most Mac devs do and I do as well. It makes things much easier for me.
when i point my browser to http://localhost/phpmyadmin, instead of showing me its front page, it comes up with save as dialog.
I'm running:
Apache/2.2.3 (Debian) PHP/5.2.0-8+etch13 Server
I've reinstalled both apache2 and php5.
After re-install i don't have httpd.conf file, how can i get it back? Is there a standard file which i can just copy into /etc/apache2?
I did a locate httpd.conf and the only file i got was the empty file i have under /etc/apache2/ which i made.
Did you configure the php extension to send an http header?
In httpd.conf:
AddType application/x-httpd-php .php
EDIT
The file is not necessarily named httpd.conf, that's just the default name. Try searching for other configuration files in the Apache directory -- the extension probably is .conf but it might be something else...
If you used apt-get on debian to install apache2, try /etc/apache2/apche2.conf
/EDIT
I also get this problem when I install ISPconfig. I solved the problem by this tutorial:
http://www.howtoforge.com/perfect-server-debian-wheezy-apache2-bind-dovecot-ispconfig-3-p4
I think the main code is change suphp.conf config.
sudo nano /etc/apache2/mods-available/suphp.conf
comment out the <FilesMatch "\.ph(p3?|tml)$"> section and add the line AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml - otherwise all PHP files will be run by SuPHP
<IfModule mod_suphp.c>
#<FilesMatch "\.ph(p3?|tml)$">
# SetHandler application/x-httpd-suphp
#</FilesMatch>
AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml
suPHP_AddHandler application/x-httpd-suphp
<Directory />
suPHP_Engine on
</Directory>
# By default, disable suPHP for debian packaged web applications as files
# are owned by root and cannot be executed by suPHP because of min_uid.
<Directory /usr/share>
suPHP_Engine off
</Directory>
# # Use a specific php config file (a dir which contains a php.ini file)
# suPHP_ConfigPath /etc/php5/cgi/suphp/
# # Tells mod_suphp NOT to handle requests with the type <mime-type>.
# suPHP_RemoveHandler <mime-type>
</IfModule>
Hope I can help someone :)
I think you just do not know where that config file is. I don't think apache can run without httpd.conf. Here is how you can find your config:
$>locate httpd.conf
/etc/httpd/conf/httpd.conf
$>vim /etc/httpd/conf/httpd.conf
Once you located it, find where other AddType reside and add
AddType application/x-httpd-php .php
Last thing you need to do is restart your httpd, it depends on install, but doing apachectl restart does the trick. You might have to locate it just like you did with httpd.conf file and type in the entire path to the file.
Afterwords, your phpmyadmin should come up.
I dont know anything about this but... does someone knows a way in javascript to download selected files, for example I select through checkboxes 2 files, and then I click on a button in order to download these 2 files choosing the route where i will save the archives