[WordPress] Deployment on Amazon EC2: Solutions to Permalinks & PHP Issues

I have recently encountered 2 issues with deploying WordPress website on Amazon EC2; Permalinks not working on Amazon EC2 and old PHP version caused the code to break.

I would like to note the solutions here in order to save hours of Googling for everyone ๐Ÿ™‚

Permalink not working on Amazon EC2

We cannot get pretty permalink to work on Amazon EC2 with regard to these circumstances:

  • mod_rewrite is already turned on (check in /etc/httpd/conf/httpd.conf or use <?php phpinfo(); ?>)
  • If we changed to default permalink of /?p=123, it works just fine
  • .htaccess is generated automatically without a permission problem

The solution is to allow .htaccess in httpd.conf by following these steps:

  1. Edit /etc/httpd/conf/httpd.conf in 2 places. From AllowOverride None to AllowOverride All
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    
    ... and ...
    
    AllowOverride All
  2. Restart httpd by running
    sudo apachectl -k restart
  3. Make sure .htaccess is there. The pretty permalink should work now ๐Ÿ˜€

Reference: http://guiem.info/permalinks-on-wordpress-amazon-ec2/

PHP Version is too old (PHP 5.3.xx)

In our development environment, we were using PHP 5.6.1. As a consequence, after deployed on Amazon EC2 with PHP 5.3.xx, our PHP code breaks.

We have to find a way to remove PHP 5.3 in Amazon EC2 and install PHP 5.6. Finally, We found the solution remove PHP 5.3 on This StackOverflow, and steps to install PHP 5.6 on Another StackOverflow.

Here are the steps we used to remove old PHP 5.3 and install PHP 5.6:

  1. Remove old PHP with these commands
    sudo yum remove httpd*
    yum remove php-cli.x86_64 php-common.x86_64 php-mysql.x86_64 php-pdo.x86_64 php-xml.x86_64
  2. Install new PHP with these commands:
    (Make sure to have MySQL installed beforehand by typing ‘mysql’ in command line to test if it works)

    sudo yum install httpd24 php56
    sudo yum install php56-xml php56-xmlrpc php56-soap php56-gd
    sudo yum install php56-mysqlnd
  3. Restart Apache with this command
    sudo service httpd start
    sudo service httpd restart
  4. Your PHP 5.6 code should work by now ๐Ÿ˜€

Note that Amazon EC2 is based on different platform from DigitalOcean. Thus, apt-get function is not working. We will have to use something like ‘yum install xxx’ instead of apt-get.

Hope this helps for anyone who tried to deploy WordPress on Amazon EC2 for the first time ! ๐Ÿ™‚


Posted

in

, , ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *