Skip to main content

Installing Yii2 on Graviton Servers

Steps to configure EC2 instance​

Create EC2 instance​

  1. Login to AWS console
  2. Go to Services > EC2 > Instances > Launch Instances
  3. Select Amazon Linux 2 64-Bit ARM
  4. Select instance type and click next to launch the instance.

Configure EC2 instance​

To configure the instance SSH into the EC2 instance and follow the steps below

  1. Install Apache, PHP and other dependencies

    yum update
    amazon-linux-extras install epel
    amazon-linux-extras install php7.4
    yum install httpd php-ctype php-mbstring php-intl php-fpm php-zip php-xml php-gd php-imagick php-curl php-memcache php-opcache php-bcmath php-soap php-apcu php-pdo php-pdo_mysql
  2. Install imagick

    yum install php-pear
    yum install php-devel
    yum install gcc
    yum install ImageMagick
    yum install ImageMagick-devel
    pecl install imagick
    echo "extension=imagick.so" > /etc/php.d/imagick.ini
    service httpd restart
  3. Open /etc/php.ini and edit the following lines

    expose_php = off
    session.use_strict_mode = 1
    max_execution_time = 180
    memory_limit = 512M
  4. Open /etc/httpd/conf/httpd.conf and edit the following lines

    # Supplemental configuration
    <IfModule mpm_event_module>
    ServerLimit 500
    StartServers 100
    MinSpareThreads 75
    MaxSpareThreads 250
    ThreadLimit 16
    ThreadsPerChild 8
    MaxRequestWorkers 4000
    MaxConnectionsPerChild 10000
    </IfModule>
    KeepAliveTimeout 600
    MaxKeepAliveRequests 500
    TimeOut 600
    ServerSignature Off
    ServerTokens Prod

    # Load vhost configs
    IncludeOptional conf.d/vhosts/*.conf

    Commnt out in file conf.modules.d/00-mpm.conf: LoadModule mpm_prefork_module modules/mod_mpm_prefork.so and uncomment : LoadModule mpm_event_module modules/mod_mpm_event.so

  5. Run mkdir /etc/httpd/conf.d/vhosts/.

  6. Edit '/etc/httpd/conf.d/vhosts/test.conf'.

    <VirtualHost *:80>
    # ServerName [domain].samarth.ac.in
    # ServerAlias www.[domain].samarth.ac.in
    # RequestHeader set "Host" "[domain].samarth.ac.in"
    DocumentRoot /var/www/html/
    CustomLog /var/log/httpd/access_log combined
    ErrorLog /var/log/httpd/error.log
    <Directory />
    Options FollowSymlinks
    DirectoryIndex index.html index.php
    AllowOverride All
    Require all granted
    </Directory>
    <LocationMatch "^(.*\.php)$">
    ProxyPass unix:/var/run/php-fpm/www.sock|fcgi://localhost/var/www/html/
    DirectoryIndex /index.php index.php
    </LocationMatch>
    </VirtualHost>
  7. Check Syntax httpd -t

  8. open /etc/php-fpm.d/www.conf

    pm.max_children = 150
    pm.start_servers = 30
    pm.min_spare_servers = 20
    pm.max_spare_servers = 70
  9. Check syntax php-fpm -t

  10. Restart apache and php-fpm

    service php-fpm start
    service httpd start
  11. Add apache and php-fpm to auto restart

    chkconfig httpd on
    chkconfig php-fpm on
  12. Create test files in /var/www/html

  13. Change the timezone

    rm /etc/localtime
    ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
  14. Install yum-cron

    yum install yum-cron
  15. Edit /etc/yum/yum-cron.conf file

    change the folowing line: apply_updates=no to apply_updates=yes

  16. Go to http://[ec2-pblic-ip]/test.html and http://[ec2-pblic-ip]/test.php to check if everything is working.

Note: The pre-configured AMI is ami-05579e96af93dc54a.

tip

Warnings while performing composer update with Php7.2+ need to resolved after thorough testing.

  1. Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead.
  2. Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
  3. Package codeception/base is abandoned, you should avoid using it. No replacement was suggested.
  4. Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
  5. Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.