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

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

    
        DirectoryIndex index.html
    
    

    and modify it to look like this:

    
        DirectoryIndex index.html index.php
    
    

    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:

     
        DirectoryIndex index.php index.html
     
    

    Only use index.php as the DirectoryIndex:

    
        DirectoryIndex index.php
    
    

    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 '

    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.

提交回复
热议问题