PHP Module for Apache on Amazon EC2 - php

Using the basic Amazon 64 Bit AMI
and I do
sudo yum install php
sudo yum install httpd
However apache is not handling php files. When I visit one it just prints the source code to the browser. There is no php module in httpd.conf. How do I fix this? i.e. is there a different package to install or how do i modify httpd.conf to make it work.
Thanks!

Related

Why are modules available for PHP command line, not PHP-Apache?

I'm setting up an Amazon Linux environment, and after installing some modules:
sudo yum install php-xml
sudo yum install php-gd
for example... and installing Imagick, and restarting (sudo service httpd restart) it does not seem to be installing for PHP-Apache. I'm using the official PHP7.2 in Amazon Linux 2 and oddly enough, for example xml_parser_create() does work in the php -a console, but when I put it in a php file, it causes exception when going to the php file, blank screen. Oddly enough it's not even getting the function not defined error to the /var/log/httpd logs.
phpinfo() also does not show Imagick or gd although installed.
I have checked php ini files for disabled_functions and didn't find anything else that would otherwise be an obvious breakage in the default install... is there a new way I'm supposed to enable PHP modules for the Apache php install?
As others may have noted elsewhere there is another module I think it was service php-fpm restart? that is necessary on RHL

PHP not running after upgrade

I'm having some trouble getting PHP to run under Apache after updating my software. On my Amazon AWS running AMI, I followed this guide here, with the specific commands:
sudo yum remove httpd* php*
sudo yum install httpd24 php55
After updating the apache config files to use the newer directives, I can get to the server, but the PHP is just echoing out on the screen.
I checked to make sure that there is a php.ini file being read, that the module is loaded in Apache, the server is running, and I can execute php from the command line.
Anyone have any ideas on what I should check next?

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

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.

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.

pgsql.so is not loaded in PHP

I've been tasked to create a PHP app which accesses an existing PostgreSQL database. This is my first time working with Postgre, not to mention the PHP has already been installed in the Linux box on which the app is supposed to run. I have no experience setting up this stuff, I just code.
My question is that I can't seem to get the Postgre extension working in PHP. I checked the php.ini file, there were no "extension=..." lines. So I added "extension=pgsql.so". I then checked the "extension_dir" and found that there were only 2 files in there (ldap.so, phpcups.so), I added a pgsql.so file taken from another Linux box. I restarted httpd. And it does not work. I couldn't find any "pgsql" or "postgre" in phpinfo().
Forgive my noobness. I know too little Linux. I would really appreciate it if you can point me to the right direction.
I used the suggestion given by number5:
Dude, I'm on RedHat. I used the "yum" version of the command you gave, and I got this:
[root#perseus ~]# yum install php-pgsql
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=5&arch=x86_64&repo=extras error was
[Errno 4] IOError:
Error: Cannot find a valid baseurl for repo: extras
UNFORTUNATELY, the Linux server I'm using is NOT connected to the Internet. Any other way to install?
It depends on which Linux distro you are using.
If you are using Ubuntu/Debian, you need to:
sudo apt-get install php5-pgsql
Fedora/CentOS
yum install php-pgsql
usually you can find out which distro you are on by:
ls /etc/*-release
On CentOS extensions create separate *.ini file one per each php extension in /etc/php.d
So, don't alter main *.ini file, but create /etc/php.d/pgsql.ini and add there a line
extension=pgsql.so
Then you will need to restart Apache using
service httpd restart
But the best automated way is to just type
yum install php-pgsql
In your case that didn't work because of some problems in yum configuration. Go to /etc/yum-repos.d
Type
nano /etc/yum.repos.d/CentOS-Base.repo
Scroll down to [extras] section and ensure it is like this:
#additional packages that may be useful
[extras]
priority=1
name=CentOS-$releasever - Extras
=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Correct it if needed, save file (Ctrl-X) and do the following:
yum clean all
yum upgrade
Afterwards try to repeat
yum install php-pgsql
Remove the .so file you've copied from the other machine (though it might work, there's no need to take the risk)
Use the distribution's package manager to install the php_pgsql/php5_pqsql module
Restart the apache and try again. Maybe the module has been added to an .ini file automagically
If not, run <?php echo 'ini: ', get_cfg_var('cfg_file_path'); to see which php.ini you have to edit
edit this ini file
restart the apache
My operation system Linux mint kde and there was same issue
pg_connect()
You must install if you are use php5.6
sudo apt-get install php5.6-pgsql
After you must change extention name in "php.ini" file.
;extension=php_pgsql.dll
'dll' to 'so'
For example
extension=php_pgsql.so

Categories