I am using Apache 2.2.3 server on RHEL5. In my system, php is installed (PHP 5.1.6). I placed a simple php script
<?php
phpinfo();
?>
in my /var/www. However, when I start my server (it starts fine) and go to the php page, it does not show anything. My local machine has ubuntu installed, where I can see the file properly.
Following the information provided here (http://dan.drydog.com/apache2php.html), I did following things:
Added following lines to /etc/httpd/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
AddType text/html .php
AddType application/x-httpd-php-source phps
restarted httpd,
service httpd restart
But I still don't see any results. What am I doing wrong?
Related
I've been trying to get PHP working locally on my machine in Fedora 26.
I have httpd installed, and that seems to be working. When I first had it set up, typing localhost in my browser showed me the HTML contents /var/www/html/index.html, but not the PHP contents. <?php phpinfo(); ?> was not working, either.
I think PHP is also working, since php -r "phpinfo();" works in the command line.
I tried following the advice in this thread by adding AddType application/x-httpd-php .php to my httpd.conf file, and this made my browser try to download the PHP files instead of displaying them. Weirdly, when I took this line back out and restarted httpd, my browser is still trying to download the files.
First of all add php AddType to to httpd.conf file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
And then load php module in apache configuration based on your php version that installed on your machine and you wanted to use:
LoadModule php7_module modules/libphp7.0.so
Im running USBWebserver v8.6 on a USB drive on a windows 10 machine, I need to update PHP to run Mautic and it requires PHP version 5.6.19 while my USB server has PHP Version 5.4.17. I tried to download windows version and extract it to the PHP folder on the drive and did a restart on the web server but that did not work.
I don't know how to update the PHP please help.
Did you change the httpd.conf file in the Settings folder?
Almost at the end of that file there are these lines:
# For PHP 5 do something like this:
LoadModule php5_module "{path}/php/php5apache2_4.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# configure the path to php.ini
PHPIniDir "{path}/php"
Change these values according the PHP installation you want. Let me know if this works for you. I got this information from the documentation on how to install PHP.
When I navigate to my website (e.g. www.mydomain.com), the browser opens a pop-up window to download a file.
In my httpdocs folder i have:
- index.html
- index.php ()
- I do NOT have .htaccess file
Checking in the browser:
- www.mydomain.com/index.html -> it works fine
- www.mydomain.com/index.php -> it works WRONG (it downloads the index.php file)
- www.mydomain.com -> it works WRONG (it download "descarga" file with index.php contents).
PHP is installed, and when I run the php -v command, it says that I am using PHP 5.3
I have other domains on the same server working fine with php files, so AddHandler or LoadModule should not be the problem as far as PHP is a constant for all my domains.
This is my php.conf and looks like everythin is right:
# 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>
#
# 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.
#
DirectoryIndex index.php
What should I try to navigate to my domain successfully?
Make sure you have the PHP module loaded. Somewhere in your config you should see something like:
LoadModule php5_module modules/libphp5.so
Then, make you you add a handler to handle files with the php extension:
AddHandler application/x-httpd-php .php .php5 .phtml
AddHandler application/x-httpd-php-source .phps
I would recommend you take advantage of yum as it can help you get things setup quickly, and allows for easy ways to update your server down the road per the yum update command. The following are some commands that may be of use to you:
yum update
yum install php*
yum install httpd*
yum update
chkconfig httpd on
/etc/init.d/httpd start
service httpd restart
I solved the problem.
There was just one domain asking me to download a file, rest of domains were working fine.
I could not find what was the problem so I went to my Plesk Panel, I deleted that domain, and I created the same domain again. After that it was working fine.
My server is a Linux CentOS 6, and I use Parallel Plesk Panel 11.
Thanks to everybody that was trying to help me on this issue.
J. Pablo.
I run a Windows 7 x64 machine with apache 2.2 and PHP 5.2.17
Whenever I try to add the PHP dll to the httpd.conf file, apache will not start.
this is how it is being put into httpd.conf
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
I have successfully managed to setup and run a Apache server with PHP before, so I'm not new to this, but I'm fairly certain that this is right.
If everything that's being output on launch is the DNS error, Apache is launching just fine. FQDN resolution is a warning, not an error.
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 7 years ago.
I've been writing PHP applications using PHP for a while in WAMP. Now I'm installing PHP and Apache HTTP Server separately on my work PC. I've installed PHP 5, and the latest Apache. I go to localhost and see it works!
Now I add a file called test.php which displays:
<?php
phpinfo();
?>
But in the browser it just displays plain text. Is there somewhere I have explicitly tell it to use PHP 5?
You should install the PHP 5 library for Apache.
For Debian and Ubuntu:
apt-get install libapache2-mod-php5
And restart the Apache:
service apache2 restart
You'll need to add this to your server configuration:
AddType application/x-httpd-php .php
That is assuming you have installed PHP properly, which may not be the case since it doesn't work where it normally would immediately after installing.
It is entirely possible that you'll also have to add the php .so/.dll file to your Apache configuration using a LoadModule directive (usually in httpd.conf).
Yet another reason (not for this case, but maybe it'll save some nerves for someone) is that in PHP 5.5 short open tags <? phpinfo(); ?> are disabled by default.
So the PHP interpreter would process code within short tags as plain text. In previous versions PHP this feature was enable by default. So the new behaviour can be a little bit mysterious.
You need to configure Apache (the webserver) to process PHP scripts as PHP. Check Apache's configuration. You need to load the module (the path may differ on your system):
LoadModule php5_module "c:/php/php5apache.dll"
And you also need to tell Apache what to process with PHP:
AddType application/x-httpd-php .php
See the documentation for more details.
You might also, like me, have installed php-cgi prior to installing Apache and when doing so it doesn't set up Apache properly to run PHP, removing PHP entirely and reinstalling seemed to fix my problem.
You will need to add handlers in Apache to handle php code.
Edit by command sudo vi /etc/httpd/conf/httpd.conf
Add these two handlers
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
at position specified below
<IfModule mime_module>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
--Add Here--
</IfModule>
for more details on AddType handlers
http://httpd.apache.org/docs/2.2/mod/mod_mime.html
Are you using the userdir mod?
In that case the thing is that PHP5 seems to be disabling running scripts from that location by default and you have to comment out the following lines:
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
in /etc/apache2/mods-enabled/php5.conf (on a ubuntu system)