Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install PHP 7.1 on EC2 running on Amazon Linux AMI 2018.03 having nginx as web server?

How to install PHP 7.1 on Amazon EC2 t2.micro Instance running Amazon Linux AMI 2018.03 having nginx as web server?

Reference to PHP7

like image 382
Ramratan Gupta Avatar asked Jul 13 '17 05:07

Ramratan Gupta


3 Answers

With reference to this answer, change Step 1 to the following:

1. Install Apache 2.4 and PHP 7.1 on Amazon Linux AMI

# Remove current apache & php 
sudo yum remove httpd* php*

# Install Apache 2.4
sudo yum install httpd24

# Install PHP 7.1
sudo yum install php71

# Install additional commonly used php packages
sudo yum install php71-gd
sudo yum install php71-imap
sudo yum install php71-mbstring
sudo yum install php71-mysqlnd
sudo yum install php71-opcache
sudo yum install php71-pdo
sudo yum install php71-pecl-apcu

Basically replacing php70 with php71.

Continue with step 2 and the rest as per the original tutorial.

like image 128
Arun Basil Lal Avatar answered Oct 14 '22 23:10

Arun Basil Lal


I followed below steps to install PHP7.1 which had already Nginx as web server for Amazon Linux AMI 2018.03

#Remove Old PHP
yum remove php*

#Update Reposistory
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

#Update Amazon AMI
yum upgrade -y

#Install PHP
#List of PHP packages https://webtatic.com/packages/php71/

yum install php71w php71w-cli  php71w-fpm
yum install php71w-mysql php71w-xml php71w-curl
yum install php71w-opcache php71w-pdo php71w-gd
yum install php71w-pecl-apcu php71w-mbstring php71w-imap
yum install php71w-pecl-redis php71w-mcrypt

#change listen mode to CGI
sed -i 's/127.0.0.1:9000/\/tmp\/php5-fpm.sock/g' /etc/php-fpm.d/www.conf

/etc/init.d/php-fpm restart
touch /tmp/php5-fpm.sock
chmod 777 /tmp/php5-fpm.sock
service nginx restart

The reason I am still using /tmp/php5-fpm.sock file so that I do not need to change PHP7 sock file in all website nginx conf and assuming server do not have PHP5 as as on first step it has been removed.

like image 41
Ramratan Gupta Avatar answered Oct 15 '22 00:10

Ramratan Gupta


A reliable way to achieve the same output is by following commands on Amazon Linux AMI 2.

# Remove current php & apache
sudo service httpd stop
sudo yum remove httpd* php*

sudo yum install httpd

amazon-linux-extras install php7.1
like image 38
Ritesh Aryal Avatar answered Oct 14 '22 22:10

Ritesh Aryal