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

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

    The php 7 package name is php70w. So what you can do is, install a Webtatic repo on you linux machine and install it from there.

    rpm -ivh https://mirror.webtatic.com/yum/el6/latest.rpm
    yum clean all
    yum install --enablerepo=webtatic php70w
    
    0 讨论(0)
  • 2020-12-04 12:47

    If you want a quick copy-paste install:

    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
    

    Test with:

    php70 -v
    

    And if you want the executable to be php:

    ln -s /usr/bin/php70 /usr/local/bin/php 
    php -v
    
    0 讨论(0)
  • 2020-12-04 12:48

    Here is how I installed PHP 7.1 on Amazon Linux:

    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

    0 讨论(0)
  • 2020-12-04 12:49

    Current answer to problem (not original version in question) - worth knowing since this is a bit simpler and php7 isn't available in the standard repos for Amazon Linux 2, and this didn't come up until I searched a bit harder:

    amazon-linux-extras install php7.2
    

    The version of extras can be checked with a list command if v7.2 is no longer current:

    amazon-linux-extras list
    
    0 讨论(0)
  • 2020-12-04 12:50

    You can now use the official php7 packages. Here an easy to follow guide.

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

    # 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. Modify DirectoryIndex to include index.php

    sudo nano /etc/httpd/conf/httpd.conf
    

    find this:

    <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>
    

    and modify it to look like this:

    <IfModule dir_module>
        DirectoryIndex index.html index.php
    </IfModule>
    

    If a directory contains an index.html and an index.php, the server will serve the index.html with this setup. If you do not want that to happen, you have the following options:

    Reverse the order, so index.php is served when both files exist:

     <IfModule dir_module>
        DirectoryIndex index.php index.html
     </IfModule>
    

    Only use index.php as the DirectoryIndex:

    <IfModule dir_module>
        DirectoryIndex index.php
    </IfModule>
    

    3. Start the Apache web server

    sudo service httpd start
    

    4. Configure the Apache web server to start at each system boot

    sudo chkconfig httpd on
    

    5. Test your installation

    Create phpinfo.php:

    echo '<?php print phpinfo();' | sudo tee --append /var/www/html/phpinfo.php
    

    Open your browser and enter your instance's public IP in the address bar followed by /phpinfo.php

    Example: http://xxx.xxx.xxx.xxx/phpinfo.php
    

    Note: Don't forget to allow incoming connections for HTTP (port 80) in the Security Groups of your instance, else your request will time out.

    0 讨论(0)
  • 2020-12-04 12:52

    It's simple. Just:

    sudo amazon-linux-extras install -y php7.2
    
    0 讨论(0)
提交回复
热议问题