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

后端 未结 14 1853
暖寄归人
暖寄归人 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:54

    The other answers seem to only work with Apache 2.2 but not 2.4.

    Here's how I installed php7 on Amazon Linux running Apache 2.4:

    First, if php is already installed, then remove it:

    sudo yum remove php5*
    

    Take note of the php5 packages that are being removed as you'll need to install the php7 versions of them. The php7 package names have a fairly direct and unambiguous mapping from their php5 counterparts as you'll see below. The rest of the instructions cover a classic LAMP stack and may be sufficient for your use-case.

    Using instructions from 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
    

    edit /etc/yum.repos.d/epel.repo and set 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
    

    Now you should have php70-php-fpm installed, which you can use in conjunction with apache:

    Start the fpm daemon:

    sudo service php70-php-fpm start
    

    Switch Apache from prefork to mpm event worker (this is required because mod_php isn't thread safe) in /etc/httpd/conf.modules.d/00-mpm.conf:

    LoadModule mpm_event_module modules/mod_mpm_event.so
    

    Instruct apache to pass all php requests to php-fpm by adding the following lines in /etc/httpd/conf/httpd.conf

    
             SetHandler "proxy:fcgi://127.0.0.1:9000"
    
    DirectoryIndex /index.php index.php
    

    Restart apache using sudo service httpd restart. If everything went ok you should be able to verify the installation by requesting a php file containing phpinfo().

    If you have existing shell scripts that use php's cli interpreter and thus start with #!/usr/bin/php, you have to set up a symlink to /usr/bin/php since the binary is now named /usr/bin/php70. You can do this as follows:

    sudo ln -s /usr/bin/php70 /usr/bin/php
    

    For more info on how to configure php-fpm see https://wiki.apache.org/httpd/PHP-FPM

提交回复
热议问题