我想在AWS EC2 T2.Micro实例上安装最新的PHP 7.0。到目前为止,我已经读到目前AWS不支持PHP 7.但是嘿..这只是云中的虚拟服务器,我可以完全控制其配置,所以必须有一些方法让PHP 7在这个上运行之一。
任何帮助非常感谢。
我的方框如下
$ cat /etc/*-release
---------------------------------------
NAME="Amazon Linux AMI"
VERSION="2015.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2015.09"
PRETTY_NAME="Amazon Linux AMI 2015.09"
ANSI_COLOR="0;33"
CPE_NAME="[*not significant*]"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
Amazon Linux AMI release 2015.09
$ uname -a
---------------------------------------
Linux ip-xxx-xxx-xxx-xxx 4.1.13-18.26.amzn1.x86_64 #1 [date] x86_64 x86_64 x86_64 GNU/Linux
$ uname -mrs
---------------------------------------
Linux 4.1.13-18.26.amzn1.x86_64 x86_64
$ cat /proc/version
---------------------------------------
Linux version 4.1.13-18.26.amzn1.x86_64 (mockbuild@gobi-build-64010) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) )
答案 0 :(得分:67)
您现在可以使用官方的php7包。这是一个易于遵循的指南。
<强> 1。在Amazon Linux AMI上安装Apache 2.4和PHP 7.0
# Remove current apache & php
sudo yum remove httpd* php*
# Install Apache 2.4
sudo yum install httpd24
# Install PHP 7.0
# automatically includes php70-cli php70-common php70-json php70-process php70-xml
sudo yum install php70
# Install additional commonly used php packages
sudo yum install php70-gd
sudo yum install php70-imap
sudo yum install php70-mbstring
sudo yum install php70-mysqlnd
sudo yum install php70-opcache
sudo yum install php70-pdo
sudo yum install php70-pecl-apcu
<强> 2。修改DirectoryIndex以包含index.php
sudo nano /etc/httpd/conf/httpd.conf
找到这个:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
并将其修改为如下所示:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
如果目录包含index.html和index.php,则服务器将使用此设置为index.html提供服务。如果您不希望这种情况发生,您有以下选择:
撤消订单,因此当两个文件都存在时,会提供 index.php :
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
仅使用index.php作为DirectoryIndex:
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
第3。启动Apache Web服务器
sudo service httpd start
<强> 4。将Apache Web服务器配置为在每次系统引导时启动
sudo chkconfig httpd on
<强> 5。测试您的安装
创建phpinfo.php:
echo '<?php print phpinfo();' | sudo tee --append /var/www/html/phpinfo.php
打开浏览器并在地址栏中输入实例的公共IP,然后输入/phpinfo.php
Example: http://xxx.xxx.xxx.xxx/phpinfo.php
注意:请勿忘记在您的实例的安全组中允许HTTP(端口80)的传入连接,否则您的请求将会超时。
答案 1 :(得分:34)
我在我的实例上运行了这个。你需要http2.2才能使用webtatic repo。我有这么多的回购,有一堆不同版本的不兼容性。我没有留下好记,但看着我的历史,我基本上做了这个:
# Remove current php & apache
sudo service httpd stop
sudo yum remove httpd* php*
# Remove any third party repos that aren't relevant
sudo yum repolist
sudo yum remove remi-safe
# Install Standard Apache for Amazon AMI
sudo yum install httpd #specify http22 if you get a different version
# Download webtatic
mkdir -p /tmp/php7
cd /tmp/php7
wget https://mirror.webtatic.com/yum/el6/latest.rpm
# Install webtatic repo
sudo yum install latest.rpm
sudo vi /etc/yum.repos.d/webtatic.repo 'set repo enables
sudo yum clean all
# Install base php7
sudo yum install --enablerepo=webtatic php70w
php -v #Should say something like PHP 7.0.2 (cli) (built: Jan 9 2016 16:09:32) ( NTS )
sudo yum install php70w-opcache
sudo yum install php70w-xml
sudo yum install php70w-pdo
sudo yum install php70w-mysqlnd
sudo yum install php70w-gd
sudo yum install php70w-apcu
sudo yum install php70w-pecl-apcu
sudo yum install php70w-mbstring
sudo yum install php70w-imap
# Restart apache
sudo service httpd restart
答案 2 :(得分:13)
截至2016年7月14日,aws linux现已有官方php7软件包。请参阅https://forums.aws.amazon.com/ann.jspa?annID=3902上的公告
要列出可用的包,请运行yum list php70 *
答案 3 :(得分:13)
问题的当前答案(不是原始版本的问题) - 值得知道,因为这有点简单,并且php7在Amazon Linux 2的标准存储库中不可用,并且这个问题直到我搜索了一下:
FooID
如果v7.2不再是最新版本,可以使用list命令检查附加项的版本:
amazon-linux-extras install php7.2
答案 4 :(得分:9)
我在已经拥有apache 2.4和PHP 5.5的生产盒上安装了PHP 7.0。我希望以一种没有服务器中断的方式安装PHP 7.0。这就是我所做的。
# Install PHP 7.0
# automatically includes php70-cli php70-common php70-json php70-process php70-xml
sudo yum install php70
# Install additional commonly used php packages
sudo yum install php70-gd
sudo yum install php70-imap
sudo yum install php70-mbstring
sudo yum install php70-mysqlnd
sudo yum install php70-opcache
sudo yum install php70-pecl-apcu
这很好地安装了PHP 7和PHP 5.5。诀窍是告诉apache使用7.0。我不确定这是否是最好的方法,但我通过更改这两个永久链接来实现这一目标:
ln -sf /etc/httpd/conf.d/php-conf.7.0 /etc/alternatives/php.conf
ln -sf /etc/httpd/conf.modules.d/15-php-conf.7.0 /etc/alternatives/10-php.conf
此时apache仍然高兴地运行5.5。然后当你重新启动apache时,应该使用7.0(可能是7.0.1)。这是没有停机的方式。我仍然建议做我做的,即在另一个实例上重建PROD(创建一个TEST服务器)并在实际上在PROD上执行之前测试一次。祝你好运!
哦,现在 php 命令仍会运行5.5。您可以更改任何脚本或CRON作业以指向php7或通过运行
更改默认版本alternatives --config php
答案 5 :(得分:8)
其他答案似乎只适用于Apache 2.2,但不适用于2.4。
以下是我在运行Apache 2.4的Amazon Linux上安装php7的方法:
首先,如果已安装php,则将其删除:
sudo yum remove php5*
请注意要删除的php5软件包,因为您需要安装它们的php7版本。 php7软件包的名称与php5对应软件有相当直接和明确的映射,如下所示。其余说明涵盖了经典的LAMP堆栈,可能足以满足您的使用需求。
使用http://www.spidersoft.com.au/2015/php-7-on-ami-linux-ec2/
中的说明wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install remi-release-6.rpm
修改/etc/yum.repos.d/epel.repo
并设置enabled=1
sudo yum upgrade -y
sudo yum install php70 php70-php-fpm php70-php-xml php70-php-pdo php70-php-mysqlnd php70-php-gd php70-php-pecl-apcu php70-php-mbstring php70-php-mcrypt php70-php-opcache
现在你应该安装php70-php-fpm,你可以和apache一起使用:
启动fpm守护程序:
sudo service php70-php-fpm start
在/etc/httpd/conf.modules.d/00-mpm.conf
中将Apache从prefork切换到mpm事件工作者(这是必需的,因为mod_php不是线程安全的):
LoadModule mpm_event_module modules/mod_mpm_event.so
通过在/etc/httpd/conf/httpd.conf
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
DirectoryIndex /index.php index.php
使用sudo service httpd restart
重启apache。如果一切顺利,您应该能够通过请求包含phpinfo()
的php文件来验证安装。
如果你有使用php的cli解释器的现有shell脚本,因此从#!/usr/bin/php
开始,你必须设置一个符号链接到/usr/bin/php
,因为二进制文件现在被命名为{{1} }}。您可以按如下方式执行此操作:
/usr/bin/php70
有关如何配置php-fpm的更多信息,请参阅https://wiki.apache.org/httpd/PHP-FPM
答案 6 :(得分:3)
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
可以按照LAMP安装的分步指南进行操作
sudo yum update -y
sudo yum install -y httpd24 php70 mysql56-server php70-mysqlnd
sudo service httpd start
答案 7 :(得分:2)
如果您想要快速复制粘贴安装:
SEVERE [RMI TCP Connection(3)-127.0.0.1]org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot create inner bean '(inner bean)#183e819c' of type [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter] while setting constructor argument with key [4]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#183e819c': Cannot resolve reference to bean 'http403EntryPoint' while setting bean property 'authenticationEntryPoint'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'http403EntryPoint' defined in file [C:\Users\k.mezhentsev\Desktop\apache-tomcat-9.0.0.M4\webapps\ROOT\WEB-INF\classes\fooConfig\fooSecurity.xml]: Cannot resolve reference to bean 'UNAUTHORIZED' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 11): Property or field 'Unauthorized' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
测试:
wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install -y remi-release-6.rpm
sudo yum update -y
sudo yum install -y --enablerepo=epel php70
如果您希望可执行文件为php70 -v
:
php
答案 8 :(得分:1)
php 7包的名称是 php70w 。所以你可以做的是,在linux机器上安装一个Webtatic repo并从那里安装它。
rpm -ivh https://mirror.webtatic.com/yum/el6/latest.rpm
yum clean all
yum install --enablerepo=webtatic php70w
答案 9 :(得分:1)
这个帖子让我足够接近完成它,我正在分享对我有用的命令和输出。
使用Amazon Linux Amazon Lightsail ( amzn1.x86_64 ),以下命令列表帮助我摆脱了Apache 2.2和PHP 5.3的系统进入Apache 2.4和PHP :
sudo yum remove php*
==============================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================
Removing:
php x86_64 5.3.29-1.8.amzn1 @amzn-main 7.4 M
php-cli x86_64 5.3.29-1.8.amzn1 @amzn-main 6.4 M
php-common x86_64 5.3.29-1.8.amzn1 @amzn-main 6.3 M
php-devel x86_64 5.3.29-1.8.amzn1 @amzn-main 9.9 M
php-gd x86_64 5.3.29-1.8.amzn1 @amzn-main 669 k
php-mbstring x86_64 5.3.29-1.8.amzn1 @amzn-main 4.1 M
php-mcrypt x86_64 5.3.29-1.8.amzn1 @amzn-main 92 k
php-mysql x86_64 5.3.29-1.8.amzn1 @amzn-main 445 k
php-pdo x86_64 5.3.29-1.8.amzn1 @amzn-main 381 k
php-xml x86_64 5.3.29-1.8.amzn1 @amzn-main 625 k
Transaction Summary
==============================================================================================================================================
Remove 10 Packages
conf
和conf.d
文件夹,imho;在我的情况下,这是一个新的系统设置,所以没有任何内容感兴趣):
sudo yum remove http*
==============================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================
Removing:
httpd x86_64 2.2.31-1.8.amzn1 @amzn-main 3.0 M
httpd-devel x86_64 2.2.31-1.8.amzn1 @amzn-main 534 k
httpd-tools x86_64 2.2.31-1.8.amzn1 @amzn-main 135 k
Transaction Summary
==============================================================================================================================================
Remove 3 Packages
sudo yum install httpd24.x86_64
sudo service httpd start
sudo yum install php70
==============================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================
Installing:
php70 x86_64 7.0.13-1.19.amzn1 amzn-updates 3.3 M
Installing for dependencies:
php70-cli x86_64 7.0.13-1.19.amzn1 amzn-updates 4.7 M
php70-common x86_64 7.0.13-1.19.amzn1 amzn-updates 1.2 M
php70-json x86_64 7.0.13-1.19.amzn1 amzn-updates 65 k
php70-process x86_64 7.0.13-1.19.amzn1 amzn-updates 79 k
php70-xml x86_64 7.0.13-1.19.amzn1 amzn-updates 309 k
Transaction Summary
==============================================================================================================================================
Install 1 Package (+5 Dependent packages)
Total download size: 9.6 M
Installed size: 31 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): php70-7.0.13-1.19.amzn1.x86_64.rpm | 3.3 MB 00:00
(2/6): php70-cli-7.0.13-1.19.amzn1.x86_64.rpm | 4.7 MB 00:00
(3/6): php70-common-7.0.13-1.19.amzn1.x86_64.rpm | 1.2 MB 00:00
(4/6): php70-json-7.0.13-1.19.amzn1.x86_64.rpm | 65 kB 00:00
(5/6): php70-process-7.0.13-1.19.amzn1.x86_64.rpm | 79 kB 00:00
(6/6): php70-xml-7.0.13-1.19.amzn1.x86_64.rpm | 309 kB 00:00
----------------------------------------------------------------------------------------------------------------------------------------------
Total 14 MB/s | 9.6 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : php70-json-7.0.13-1.19.amzn1.x86_64 1/6
Installing : php70-process-7.0.13-1.19.amzn1.x86_64 2/6
Installing : php70-xml-7.0.13-1.19.amzn1.x86_64 3/6
Installing : php70-cli-7.0.13-1.19.amzn1.x86_64 4/6
Installing : php70-common-7.0.13-1.19.amzn1.x86_64 5/6
Installing : php70-7.0.13-1.19.amzn1.x86_64 6/6
Verifying : php70-7.0.13-1.19.amzn1.x86_64 1/6
Verifying : php70-common-7.0.13-1.19.amzn1.x86_64 2/6
Verifying : php70-json-7.0.13-1.19.amzn1.x86_64 3/6
Verifying : php70-process-7.0.13-1.19.amzn1.x86_64 4/6
Verifying : php70-xml-7.0.13-1.19.amzn1.x86_64 5/6
Verifying : php70-cli-7.0.13-1.19.amzn1.x86_64 6/6
Installed:
php70.x86_64 0:7.0.13-1.19.amzn1
Dependency Installed:
php70-cli.x86_64 0:7.0.13-1.19.amzn1 php70-common.x86_64 0:7.0.13-1.19.amzn1 php70-json.x86_64 0:7.0.13-1.19.amzn1
php70-process.x86_64 0:7.0.13-1.19.amzn1 php70-xml.x86_64 0:7.0.13-1.19.amzn1
Complete!
答案 10 :(得分:1)
默认情况下,在RedHat EC2上仅启用了少量Yum Repo。 要启用所有功能,只需键入
yum-config-manager --enable rhui-REGION-rhel-*
现在做一个百胜清单,您应该可以看到以下内容:
yum列表| grep php7
答案 11 :(得分:1)
很简单。只是:
sudo amazon-linux-extras install -y php7.2
答案 12 :(得分:0)
这里应该有几个答案;但是,当我安装我的时,它不会呈现页面并显示文本而不是呈现PHP。
为了解决这个问题,我跑了
sudo yum install php70-php-fpm
之后,一切都开始有效了。
答案 13 :(得分:0)
以下是我在Amazon Linux上安装PHP 7.1的方法:
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
yum-config-manager --enable remi-php71
wget ftp://195.220.108.108/linux/epel/6/x86_64/Packages/s/scl-utils-20120229-1.el6.x86_64.rpm
rpm -Uvh scl-utils-20120229-1.el6.x86_64.rpm
yum install php71
https://gist.github.com/ihor/581d169886c29e7e17d01b0041167b01