I have setup php/apache according to this linode guide: https://www.linode.com/docs/guides/install-php-8-for-apache-and-nginx-on-ubuntu/
This seems to have worked, and I have an apache server that can serve files, and process .php files.
However, I am having the darndest time figuring out how to tell apache to process .html files with .php. Any modification I make to .htaccess (a-la- https://manage.accuwebhosting.com/knowledgebase/2492/Parse-HTML-As-PHP-Using-HTACCESS-File.html and similar) produce no change. I have also set AllowOverride All to the /var/www/ directory in /etc/apache2/apache2.conf. Additionally, most online information on the subject points to earlier versions of .php, with no specific reference to 8.0.
What can get apache to process .html with php 8.0?
You need to have module for this, confirm you have this line in httpd.conf, or add it there:
LoadModule mime_module modules/mod_mime.so
Also check if you have the modules/mod_mime.so file present on your system.
Then find or add module section in httpd.conf:
<IfModule mime_module>
# following line will change mime type of .html file to php
# and they will be handled as such
AddType application/x-httpd-php .html
</IfModule>
Directive AllowOverride All will enable .htaccess files but you need the mime_module enabled too.
And of course restart the apache server after making configuration changes.
Module documentation: here
Related
I try to install php on a mac M1 monterey, but this simple code is not interpretated :
<?php phpinfo(); ?>
I installed php with brew
brew install php
brew link php
I signed the libphp module
codesign --sign "certificate" --force --keychain ~/Library/Keychains/ /opt/homebrew/Cellar/php/8.1.2/lib/httpd/modules/libphp.so
Should I use the dynamic link instead ?
/opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Loading the module in the apache2.conf file
LoadModule php_module /opt/homebrew/Cellar/php/8.1.2/lib/httpd/modules/libphp.so "certificate"
enable php page to be view in the apache2.conf file
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
result of which php
/opt/homebrew/bin//php
Is the double slash normal here ?
I can access the index.php of my web directory but php is still not executed.
Thanks
As I mentioned in the comments you probably done most the steps but this guide I found has one last step it mentions for PHP. Here is the link:
https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey/
Also I found a lot of my issues went away when I started using homebrew Apache instead.
I am glad the guide was able to help you get it working.
For anyone else who is stuck, here is the relevant section from the guide:
PHP 8 and macOS Apache
One extra step is needed for PHP 8 and macOS bundled Apache:
sudo nano /etc/apache2/httpd.conf
Add the new PHP 8 and comment out the old one.
LoadModule php_module /usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
Go to the end of the file and add:
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
Restart Apache
Sometimes php configs are added through "other" configs if you have a line as below at the end of your httpd.conf
Include /private/etc/apache2/other/*.conf
Check config files under /private/etc/apache2/other/ and make necessary changes. I had a file called +php-osx.conf in that folder I edited as following:
LoadModule php_module /usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule php_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
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 have a problem with apache and PHP 5.4 running on a centOS 7 machine.
Apache host have the directory index option:
<Directory my/directory>
Options Indexes
</Directory>
The directory where apache points to contains a index.php. But when I navigate the browser to the related website, the browser only shows the php code.
I've already checked, if php is activated in http.conf - and it is. The application (zabbix) should work with this version of PHP and all necessary SQL- and PHP-plugins are installed.
No more Google suggestions for this problem - any of you an idea how to solve this?
Output of /etc/http/conf.d/php.conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
#<FilesMatch \.phps$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
Please check below thinks in your httpd config file
LoadFile "D:/wamp/php/libpq.dll" // Your sepcified path
LoadModule php5_module "D:/wamp/php/php5apache2_4.dll" // Your sepcified path
AddType application/x-httpd-php .php // Your sepcified path
PHPIniDir "D:/wamp/php" // Your sepcified path
You probably installed PHP from the distribution packages. If so, make sure Apache was restarted after that:
sudo systemctl restart httpd
If that does not help, try reinstalling the PHP packages, then restarting Apache.
If that does not help, post the contents of /etc/httpd/conf.d/php.conf here.
I had a friend configure my server for sqlite3 yesterday.
He went in through putty and used a command line to determine if it was already installed:
locate sqlite3
it came back that it was indeed located as this shows:
/usr/bin/sqlite3
/usr/lib64/libsqlite3.so.0
/usr/lib64/libsqlite3.so.0.8.6
/usr/lib64/apr-util-1/apr_dbd_sqlite3-1.so
/usr/lib64/apr-util-1/apr_dbd_sqlite3.so
/usr/share/man/man1/sqlite3.1.gz
/usr/share/rails/configs/databases/sqlite3.yml
So then he proceeded to explain how we had to configure the apache to recognize and load that module. So we went into the httpd/conf.d/ directory and vi edited the php_conf file by adding this line <<---THIS LINE & now the complete file looks like this:
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
LoadModule php5_module modules/pdo_sqlite.so<<---THIS LINE
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
We then saved that file (i just double checked). We then called /etc/init.d/httpd reload and then restart. We got Green OKs all around.
But I still get:
PHP Fatal error: Class 'SQLite3' not found
when calling this line in my php file:
$db = new SQLite3($sqlite_database);
Any ideas how else I could test to see what is wrong?
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