Step 1: SSH into your Instance

Once your instance is running, you can ssh into it. First, you need to identify the address of your instance: Select the instance in the AWS Management Console, and look for the Public DNS in the instance description (bottom part of the screen)
  • Use that address (and a path to your .pem file) to ssh into your instance:
    ssh ec2-user@<PUBLIC DNS FOR INSTANCE> -i <PATH TO .pem FILE>
  • If you get a message about your .pem file permissions being too open, chmod your .pem file as follows:
    sudo chmod 400 <PATH TO .pem FILE>
  • Many of the shell commands below require root access. To avoid having to prefix these commands with sudo, let’s just switch user once and for all:
    sudo su

— Step 2: Install the Apache Web Server 2.4 and PHP 5.6/7.0

  • To install the Apache Web Server, type:
    yum install -y httpd24 php70
  • Start the Apache Web Server:
    service httpd start
To test your Web Server, open a browser and access your web site: http://ec2-50-17-14-16.compute-1.amazonaws.com (Use your actual public DNS name). You should see a standard Amazon place holder page.
  • Create a page to test your PHP installation:
    cd /var/www/html
    vi test.php
  1. Type i to start the insert mode
  2. Type <?php phpinfo() ?>
  3. Press ESC then type :wq to write the file and quit vi
Open a browser and access test.php to test your PHP installation: http://ec2-50-17-14-16.compute-1.amazonaws.com/test.php (Use your actual public DNS name).

— Step 3: Install PHP Add-ons and Extensions

  • Stop the Apache Service
    service httpd stop
  • Install PHP packages
    yum install php70-mysqlnd
    yum install php70-pecl-imagick
    yum install php70-mbstring
    yum install php70-opcache
    yum install php70-pecl-apcu
    yum install php70-zip
    
    or do this:
    yum install php70-mysqlnd php70-pecl-imagick php70-mbstring php70-opcache php70-pecl-apcu php70-zip -y
  • For sites with WooCommerce, also install the SOAP Client
    yum install php70-soap
  • Start / Restart Apache
    service httpd start
    service httpd restart

Step 4: Install MySQL

  • To install MySQL, type:
    yum install mysql-server
  • Start MySQL:
    service mysqld start
  • Create your database:
    mysqladmin -uroot create <DATABASE NAME>
  • Secure your database:
    mysql_secure_installation
Answer the wizard questions as follows:
  • Enter current password for root: Press return for none
  • Change Root Password: Y
  • New Password: Enter your new password
  • Remove anonymous user: Y
  • Disallow root login remotely: Y
  • Remove test database and access to it: Y
  • Reload privilege tables now: Y

— Step 5: Install WordPress

  • To install WordPress, type:
    cd /var/www/html
    wget http://wordpress.org/latest.tar.gz
    tar -xzvf latest.tar.gz
  • WordPress is now in its own “wordpress” directory. We will move the contents to the root folder:
    mv wordpress/* /var/www/html/
  • Create the WordPress wp-config.php file:
    mv wp-config-sample.php wp-config.php
    vi wp-config.php
  1. Type i to start insert mode.
  2. Modify the database connection parameters as follows:
    define(‘DB_NAME’, ‘blog’);
    define(‘DB_USER’, ‘root’);
    define(‘DB_PASSWORD’, ‘<PASSWORD CREATED EARLIER>’);
    define(‘DB_HOST’, ‘localhost’);
    
  3. Add the WordPress config keys by generating them here: https://api.wordpress.org/secret-key/1.1/salt/
  4. Add the following right below define(‘WP_DEBUG’, false);:
    define( 'WP_MEMORY_LIMIT', '96M' );
    define( 'DBI_AWS_ACCESS_KEY_ID', 'AKIAJ5U3WLADWPMQNYIA' );
    define( 'DBI_AWS_SECRET_ACCESS_KEY', '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' );
  5. Press ESC then type :wq to write the file and quit vi
  • Fix Apache permissions
    chown -R apache:apache /var/www/html
  • Restart the Apache server
    service httpd restart

— Step 6: Set Apache and MySQL to autostart on reboot

  • Enter the following two commands.
    sudo /sbin/chkconfig mysqld on
    sudo /sbin/chkconfig httpd on

Start typing and press Enter to search