Apache2, Wordpress index.php not executed, just text file - php

I have a problem with apache2, wordpress and php.
I configured virtual hosts and copied the existing wordpress (installed in single host).
The web server is working fine and loads the index.php, but doesn't execute it.

Check mod-enabled folder in your apache. You must have two files their php5.load and php5.conf. If not present, its means php support is not their.To enable php support use command a2enmod php5

It is because your apache2 can't execute php.
In my case, I install libapache2-mod-php by:
aptitude install libapache2-mod-php7.0
Then restart apache by:
/etc/init.d/apache2 restart
May it help you.

Related

Change apache2 php path

I am using https://github.com/wilmoore/php-version to switch between php versions on my local machine, installed within ~/php/versions. Currently setting up separate VMs with different versions of php installed is not an option.
When I switch php version through the command line using the linked tool, I see it listed as php 7. This also works when using php -v. I have restarted terminal and the machine and it still says php 7.
I have updated composer.json to require php 7.0.2 and greater. Yet when I use phpinfo() in my laravel application, it always states the default PHP Version 5.5.9-1ubuntu4.14.
Where is laravel pointing to the php distribution in my Ubuntu 14.04.3 machine and where can I change this path?
EDIT: I am using Apache. I can see in the phpinfo() output that it is reading the ini file from /etc/php5/apache2/php.ini. I have looked in this file but cannot see where to point to the php distribution.
first make sure that php7.*.conf and php7.*.load files are exist in /etc/apache2/mods-available directory.
then use sudo a2enmod php7.* to enable the mod
use sudo a2dismod php5.* to disable the mod
after running the two commands restart your apache2 server
using sudo systemctl restart apache2
The Apache loads the php5_module library in /etc/apache2/mods-available/php5.load.
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
If you know the loactions of your alternative libraries you can change them in this file.
After editing you need to restart your apache. sudo service apache2 restart or sudo systemctl restart apache2.service
Had the same issue on ubuntu16.
ls -l /etc/apache2/mods-available/php7* ,
showed 2 versions -
/etc/apache2/mods-available/php7.0.conf
/etc/apache2/mods-available/php7.2.conf
Deleted the /etc/apache2/mods-available/php7.0.conf, restarted apache2, and phpinfo() via apache2 showed php7.2

Enable XSL on Ubuntu 12.04

I am trying to enable XSL on Ubuntu 12.04 but its failing. I did this locally on my Ubuntu 13.04 and it was successful. Basically the following worked on my local computer.
apt-get install php5_xsl
edit php.ini file and add extension=php5_xsl.so
restart apache
I repeated the same procedures on my production server running Ubuntu 12.04 and PHP version 5.5.12 but the extension is not getting loaded from the phpinfo. I have also changed the extension=php5_xsl.so to extension=xsl.so because this is what in the extension directory.
I read that I might need to recompile PHP but I am not sure of this steps.
Try this:
sudo apt-get install php5-xsl
sudo php5enmod xsl
sudo service apache2 restart
Why:
http://www.lornajane.net/posts/2012/managing-php-5-4-extensions-on-ubuntu
What's happened here is that all debian-flavoured unixes have adopted
this standard for their PHP 5.4 packages, so if you're using debian,
ubuntu, or any of their relatives with PHP 5.4, you'll see a directory
structure like this. When you add a module to PHP, you'll add a file
to the mods-available directory enabling the module and adding any
config specific to it. If you want to enable the module, just do:
php5enmod http
This simply creates a symlink from the usual conf.d directory to point
to where the real files are in mods-available, prefixed with a number
that indicates the priority of the module. By default, the priority is
20.
Using this approach means we can toggle things on and off without
commenting out big chunks of config files and leaving them lying
around - if this seems familiar then that's no surprise; debian-like
linuxes manage their apache configuration in just the same way. Any
packages that you install using aptitude will use these exact same
commands to set up the configuration and then symlink it correctly. To
unlink, use the delightfully predictably-named php5dismod :)

Can I simply "repoint" apache to use a different version of PHP?

I have 2 versions of php installed in different directories. I can use both from the command line. However, I'm not able to figure out how to get apache to use a different one (in other words, it uses one, but I'd like to try running with the other).
Can I change simlinks or something? What process would I use to "repoint" apache to use my other installation of php?
Assume that you have php7.2 and 7.4 installed.
When you invoke phpinfo(), php 7.2 is responding (and displayed) and you want 7.4 running.
Hereafter how to proceed:
sudo a2dismod php7.2
sudo a2enmod php7.4
systemctl restart apache2
Working for me on Kubuntu 18.04
In your apache httpd.conf file there is a explicit include for the php module. Whatever this points to is the version of php to be used.
Look for a line something like this:
LoadModule php5_module  libexec/apache2/libphp5.so
Then change it to point to the library of the new version of php.
If this isn't in your httpd.conf file it may be in another conf file found in /etc/httpd/conf.d/
Any changes to these files require a reload or restart of apache.

How to install PHP extensions on nginx?

I recently discovered NginX, and decided to try it out on my server. I have NginX running and able to serve PHP and HTML files. But now I want to try to install drupal. When trying to install it and check the requirements, I am stopped by one requirement.
PHP extensions Disabled
Drupal requires you to enable the PHP extensions in the following list (see the system requirements page for more information):
gd
I have tried to install gd by doing apt-get install php5-gd, and it says it is already installed. So I created a phpinfo() file, and checked to see if gd was enabled and I wasn't able to find it. Does this have to do with NginX or PHP? What do I do to fix this?
Since you are using Nginx - that must mean you are running PHP with PHP-FPM.
After you install stuff you need to:
sudo /etc/init.d/php-fpm restart
or
service php5-fpm restart
in newer ubuntu versions
so that PHP will pickup the new extensions.
If your web server setup is in order, only install the php gd extension and restart php scripting interpreter and web server.
sudo apt-get install php5-gd
sudo /etc/init.d/php-fastcgi stop
sudo /etc/init.d/php-fastcgi start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
Here's a great LEMP tutorial http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid
For future me if I forget this.
If you've been messing around with /etc/php/fpm then you may have accidentally lost the symlink to conf.d which means the gd and PDO load files won't be booted with FPM.
This will be an issue if you're just using the basic config that comes with PHP5-FPM. If you have a custom config you may included the files in a different place.
Solution: Recreate the sym-link.
cd /etc/php5/fpm
sudo ln -s /etc/php5/conf.d /etc/php5/fpm/conf.d
PHP extensions have only to do with PHP. Your choice of webserver (apache, nginx, etc) do not affect them. Most likely you just need to enable the gd extension. If you are on Ubuntu, check /etc/php5/conf.d folder and add a gd.ini with the following line:
extension=gd.so
if you are using centos 7 and you can't find /etc/init.d/php-fpm, you may try systemctl restart php-fpm, that worked for me.
I encountered the same problem with making sudo apt-get install php5-gd to work. Console output suggested to do sudo apt-get update. Just basic updating on all your packages.
After updating, I run sudo apt-get instal php5-gd and it did all heavy lifting for me, including restarting php5-fpm and correctly installing everything in between.

php page being downloaded instead of being processed while accessing outside a particular domain

I have installed PHP5 with apache 2.2.16 and trying to serve an application based on php.
I am able to acess this application inside a particular domain (php scripts are processed normally) but when i trying to access it outside that domain my php pages are being downloaded instead of being processed ?
What could be the reason?
Are you sure Apache and PHP5 are properly installed? If Apache is not actually parsing the php files after you've installed PHP5 and restarted the server, install libapache2-mod-php5. This is usually installed when you initially install the PHP5 package, but perhaps it might have been moved or removed intentionally or inadvertently by other packages which need other PHP versions.
You may also need to actually enable PHP by doing sudo a2enmod php5 followed by sudo /etc/init.d/apache2 restart. If sudo a2enmod php5 returns "$ This module does not exist!", you should purge (not just remove) the libapache2-mod-php5 package and reinstall it.

Categories