I am new to this of course.
I am trying to configure PHP and Apache on a new Amazon EC2 AMI. This is a very lightweight server so the Micro instance fits the bill.
I just need
Apache
PHP
I ran
sudo yum install apache2
sudo yum install php
I copied info.php to /var/www/html
info.php only contains
<? phpinfo(); ?>
when i browse to http://www.example.com/info.php Apache serves info.php but it does not render it. I looks like apache is not configured to handle php files. What step or steps am I missing?
Thanks,
First try using full tags, so your script would be.
<?php phpinfo(); ?>
instead of <? ?>
If no luck, try:
sudo yum remove php
sudo yum install php
then service httpd restart
Alternatively try using one of the pre-built AMI's. Community AMI's have several LAMP configurations.
Just for those who get here from Google, try this:
sudo yum install -y php
sudo yum -y install httpd
If you need development versions:
sudo yum install -y php-devel
sudo yum -y install httpd
If you need Apache 2.4 and PHP 5.4:
sudo yum install -y php54
sudo yum -y install httpd24
From:
Install Apache, PHP, and MySQL on Amazon Linux
Install Apache 2.4, PHP 5.4, and MySQL on Amazon Linux
Just tar your info.php;
Upload it to another public directory;
Get the file to ec2 with wget;
Untar the file.
That's it ;)
Related
I have been trying to update PHP on my install of WordPress on Google Cloud.
I have followed these instructions: How do I upgrade from PHP 7.0 to 7.3 on google cloud platform?.
When I do a php -v command, it shows that it is updated, but within WordPress it is still showing version 7.0, not the updated version.
Your system appears to have two installations of PHP. One for the CLI and another Apache or you have not restarted Apache after the update. First restart Apache and recheck.
The command to install Apache PHP is sudo apt install libapache2-mod-php7.3.
Warning: Be careful with manual updates of PHP and other software that may have interdependencies. Make sure you have backed up your system (image) before so that you can recover is something goes wrong. Debian 4.9 is very old (obsolete) and might not be supported or even tested with the latest versions of third-party software.
The Linux command where php will tell you where PHP is installed. To figure out if you have a different installation for Apache, create a new web page, such as myphpinfo.php with the following contents. Then use your browser to view the page:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
Your browser will display a page like this:
Use SSH commands:
Go to root
sudo -i
install latest version of php
apt-get install php7.4
update it
apt-get update
install packages
apt-get install ca-certificates apt-transport-https
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
check your php version
php -v
enable php7.4 and disable your current php7.0
sudo a2dismod php7.0
sudo a2enmod php7.4
install the libraries
sudo apt-get install phpmyadmin php-mbstring php-gettext
sudo apt-get install php-mysql
sudo apt-get install php-curl
sudo apt-get install php-xml
sudo apt-get install php-gd
restart apache
sudo service apache2 restart
I've recently created LAMP servers on EC2 instances using Amazon Linux AMI.
using
sudo yum install -y php70-gd
I installed the GD extension.
This all worked fine and i could upload and manipulate images using PHP.
Now I've created a LAMP server using Amazon Linux 2 using the tutorial here :https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-lamp-amazon-linux-2.html
My problem is that I can't get the GD extension to work.
i tried using
sudo yum install -y gd
and this seemed to install an older version of GD.
I tried
sudo yum install php-gd
and this seems to install the latest version of the extension.
But the gd extension still doesn't seem to work.
when I enter
yum info gd
In the console it shows :
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Installed Packages
Name : php-gd
Arch : x86_64
Version : 7.2.5
Release : 3.amzn2.0.2
Size : 769 k
Repo : installed
From repo : amzn2extra-lamp-mariadb10.2-php7.2
Summary : A module for PHP applications for using the gd graphics library
URL : http://www.php.net/
License : PHP and BSD
Description : The php-gd package contains a dynamic shared object that will add
: support for using the gd graphics library to PHP.
when I try an image resize script I get an error.
I've tried this test script :
$testGD = get_extension_funcs("gd"); // Grab function list
if (!$testGD){ echo "GD not installed."; exit; }
echo"<pre>".print_r($testGD,true)."</pre>";
and this gives me the result
GD not installed.
so obviously something is not right.
Can anyone help?
thanks
Amazon Linux 2 uses Apache with PHP-FPM instead of mod_php. So you need to restart the php-fpm process to reload PHP with the new extension.
sudo systemctl restart php-fpm
I'm running php 7.2.14 on Amazon Linux 2 and this worked for me:
$ sudo yum update -y
$ sudo yum install -y php-gd
$ sudo reboot
And solved...
Turns out restarting apache with
sudo systemctl restart httpd
wasn't enough to load the newly installed component...
what i needed to do was
sudo reboot
and everything works...
Why did't i try that 24 hours ago!
my PHP version was - PHP 7.2.18
$ php -v
I had to install -y php72-gd
$ sudo yum update -y
$ sudo yum install -y php72-gd
$ sudo reboot
$ sudo yum install -y php-gd
$ sudo systemctl restart php-fpm
No need to reboot
I was getting error Required extension GD is not loaded while using Claviska Simple Image Library in my project on AWS with Php 7.0
So I needed to update the GD php library:
sudo yum install -y php70-gd
and then restart httpd service to load the updated php.
sudo /etc/init.d/httpd restart
Worked for me!
You may have done nothing wrong and might not need to reboot either. Sometimes, the extensions are not directly mapped in the php.ini file. As such, you may need to map the newly added extensions (or which are not mapped already) in the php.ini file. In your case, add
extension=gd.so
In general,
extension=<my_extension_name>.so
I have an AWS server running a website with NGINX and PHP. I originally installed these using the following:
sudo yum install -y nginx php-fpm
The version of PHP that is installed is 5.3.29 which but I need at least 5.4 to run a payments plug-in. All the info online indicates a PHP upgrade actually involves a reinstall. So I ran the series of commands below to upgrade to 7.1 (based on various online postings):
sudo yum remove php* httpd*
sudo yum clean all
sudo yum update -y
sudo yum install php71
After the upgrade all php files on my site result in a 404. But html files work fine, so NGINX is running. The resulting install of php7.1 doesnt seem to run as a service. If I run service --status-all I see no mention of any PHP. There is now no *.sock file in the /var/run/ folder hierarchy for nginx to link to. There is no www.conf file for php so I cannot configure a sock file location. The tutorials online mention running php afterwards using sudo systemctl restart php7.1-fpm.service but systemctl is not a command and there seems to be no PHP service to run anyway.
Am I missing something here? I am at a loss what to do next. Can anybody offer some direction or indication as to what I have done wrong and how I can debug this?
FINALLY! Seems the instructions on virtually every site I have looked at did not work. What did work was the following:
sudo yum install php71-fpm
I dont understand the difference between php71 and php71-fpm but using the latter seems to install the service and other files I needed. Not everything on my site is working though, as I now need to track down the various php components that are needed. It seems that the various php modules have changed name in assorted ways. For example, php71-pdo exists but php71-mysql does not.
Change PHP version.
sudo yum-config-manager --enable epel
yum install dnf -y
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
dnf install php74.x86_64
dnf clean metadata
dnf install php-cli php-pdo php-fpm php-json php-mysqlnd
dnf list installed php-cli php-pdo php-fpm php-json php-mysqlnd
which php
php -v
yum update
sudo systemctl restart httpd
I am trying to setup LAMP stack on Ubuntu 14.04 LTS by installing each of the packages seperately in terminal and not by using LAMP software bundle packages. The following are the commands that I executed:
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install mysql-server
sudo apt-get install phpmyadmin
Is there any other configuration that needs to be done like configuring the apache2 server, phpmyadmin, etc... I looked it up on google and unable to find recent results.
Appreicate your help
Edit: Updated the query with more information
Go in the apache2 config file by typing:
sudo nano /etc/apache2/apache2.conf
Then, type the following and save the file:
Include /etc/phpmyadmin/apache.conf
Now, restart the apache2 server by typing:
/etc/init.d/apache2 restart
I want to use SPLEnum, a part of the PECL-Extension SPL-Types, in my Web Application.
Now, I've never worked with extensions, so I don't know how they are working. I've asked my hoster to install the package, but they could not because of security reasons on their servers.
Is it somehow possible to manually include files, just like in Java (manually copy the files to the webserver and include them)?
Thanks for your answers
Regards, Flo
PECL contains C extensions for compiling into PHP. Therefore you need the appropriate rights on the server running PHP, which you will never get on a shared hosting. Try to find a similar PEAR extension, these are written in PHP and behave like any other PHP file.
I'm using Ubuntu 14.04 with Apache rather than nginx. Using the script from here works.
sudo apt-get install libpcre3-dev php5-dev php-pear -y
sudo pecl install SPL_Types
echo extension=spl_types.so | sudo tee /etc/php5/mods-available/spl_types.ini
sudo php5enmod spl_types
sudo service apache2 reload
The key difference between this and Michael Noyb's answer is that this continues on to take care of loading the extension into Apache by using the php5enmod system, which you can read about here.
Shared Hosting
CodeZombie's answer is spot on that a shared host will not let you do this, but you can spin up your own virtual private server (VPS) on something like DigitalOcean for $5 a month which is roughly the same cost of a shared hosting plan.
Ubuntu 14.04 using php5-fpm and nginx and php 5.5+
sudo apt-get install libpcre3-dev
sudo apt-get install php5-dev
sudo pecl install SPL_Types
then go to /etc/php5/fpm/php.ini and add this line
extension=spl_types.so
Note: you may have to do the same for /etc/php5/cli/php.ini
then
sudo service nginx restart
sudo service php5-fpm restart
Then you can write classes like this (real life example for me):
<?php
namespace Metronic\Lib;
use SplEnum;
class PortletColor extends SplEnum {
const __default = self::YELLOW;
const YELLOW = 'yellow';
}
When you need to call the constant yellow, you use \Metronic\Lib\PortletColor::YELLOW;
Ubuntu 12.04+ installation order:
sudo apt-get install libpcre3-dev
sudo apt-get install php5-dev
sudo apt-get install php-pear
sudo pecl install SPL_Types