How to install PHP 7 on EC2 t2.micro Instance running Amazon Linux Distro

后端 未结 14 1849
暖寄归人
暖寄归人 2020-12-04 12:29

I want to install the latest PHP 7.0 on an AWS EC2 T2.Micro Instance. So far I have read that currently AWS do not support PHP 7. But hey.. This is just a virtual server in

14条回答
  •  日久生厌
    2020-12-04 12:55

    I was installing PHP 7.0 on a production box that already has apache 2.4 and PHP 5.5. I wanted to install PHP 7.0 alongside it in a way that would have no Server outage. This is what I did.

    # 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
    

    This happily installed PHP 7 alongside PHP 5.5. The trick was to tell apache to use 7.0. I'm not sure if this was the best way, but I achieved this by changing these 2 permalinks:

    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
    

    At this point apache is still happily running 5.5. Then when you restart apache it should be working with 7.0 (maybe 7.0.1). This is the no downtime way. I'd still recommend doing what I did, which is to rebuild PROD on another instance (create a TEST server) and test it all once before actually doing it on PROD. Good luck!

    Oh, and right now the php command will still run 5.5. You can either change any scripts or CRON jobs to point to php7 or change the default version by running

    alternatives --config php
    

提交回复
热议问题