Category: Server Configuration

  • Amazon Linux 2, Apache 2.4, PHP 7.3

    Amazon Linux 2, Apache 2.4, PHP 7.3

    In this guide, I will explain the steps necessary to create an Amazon Linux 2 server with:

    • Apache 2.4
    • PHP 7.3
    • Common PHP modules.
    • No RDBMS (MySQL / MariaDB) – We won’t need that as you’re using RDS 🙂

    Revision History

    • 2019-11-25: mcrypt Installation Instructions
    • 2019-11-24: Initial creation.

    Step 1: Follow AWS Guide on LAMP

    AWS created an awesome documentation on spinning up Amazon Linux 2 with LAMP. Follow steps 1 & 2 and forget about the other steps if you’re using RDS as your database provider (or another DB server).

    Step 2: Disable PHP 7.2 amazon-linux-extras

    If you went through Step 1, you now have LAMP 7.2 installed. You’re probably thinking, “wait a minute, I want PHP 7.3!”

    This is where it is tricky, but I’m here to make it easy for you 😉 First, you need to disable the amazon-linux-extras PHP7.2 you just installed:

    
    
    sudo amazon-linux-extras disable php7.2
    sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2

    Next, you will need to enable the PHP 7.3 packages:

    
    
    sudo amazon-linux-extras enable php7.3

    # Additional PHP addons you'll most likely need.
    sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd

    # Disable php7.3
    # See "Updating Your Server"
    sudo amazon-linux-extras disable php7.3

    That’s it! Whenever you need to do an update on your server (using yum update), see the next section about that.

    Updating Your Server

    For server maintenance, run the following:

    
    
    # Update LAMP
    sudo amazon-linux-extras enable lamp-mariadb10.2-php7.2
    sudo yum update -y
    sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2

    # Update php7.3
    sudo amazon-linux-extras enable php7.3
    sudo yum update -y
    sudo amazon-linux-extras disable php7.3

    Optional PHP Modules

    mcrypt

    Some of your legacy applications may rely on mcrypt. I’ve detailed the following on installing mcrypt and updating it to mcrypt 1.0.2.

    This module is also deprecated per official PHP documentation. While this may work for the time being, your ultimate goal is to develop using something else.

    To bake mcrypt into your server:

    
    
    sudo yum install libmcrypt-dev

    Future Updates: What if PHP 7.4 comes out and I need to update to that?

    While PHP 7.4 isn’t out yet, I do get your concern. It’ll be the same process as we upgraded from PHP 7.2 to PHP 7.3.

    First, we need to disable PHP 7.3:

    
    
    sudo amazon-linux-extras disable php7.3

    Next, we need to enable the future PHP 7.4:

    
    
    sudo amazon-linux-extras enable lamp-mariadb10.2-php7.2
    sudo yum update -y
    sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2
    sudo amazon-linux-extras enable php7.4
    sudo yum update -y
    udo amazon-linux-extras disable php7.4

    Resources

    The following resources has helped me with this setup. I am grateful for their shared knowledge.

  • Mac OS Terminal Shortcut for “ls -lGaf”

    Mac OS Terminal Shortcut for “ls -lGaf”

    On Ubuntu, I've always used "ll" to quickly get a list of folders/files from a directory.  This quick shortcut isn't built into iTerm for Mac.  Add the following to your ~/.bash_profile

    alias ll='ls -lGaf'

    What does this do?

    • List folders & files.
    • List hidden files.
    • Sorts the output and disregard case-sensitivity.
  • WordPress Assets Loaded from Production

    WordPress Assets Loaded from Production

    The following code snippets will let you load the production version of /wp-content/uploads to your local development computer.

    The order of placement matters so ensure this goes to the top (above the line that processes your PHP scripts).

     

  • Update Ubuntu 14

    The CLI process on updating Ubuntu 14:

    # Fetches the list of available updates.
    sudo apt-get update
    
    # Strictly upgrades the current packages.
    sudo apt-get upgrade
    
    # Installs updates for current Ubuntu release.
    sudo apt-get dist-upgrade
    

    Note: This does not upgrade to a new version of Ubuntu (such as Ubuntu 16). This updates your current Ubuntu version.

  • Nginx 400 Bad Request The plain HTTP request was sent to HTTPS port

    Problem

    When viewing any of my sites using port 80, the following error appeared on non-SSL websites:

    Nginx 400 Bad Request The plain HTTP request was sent to HTTPS port

    Original server block:

    server {
        listen 80;
        listen 443;
    
        ssl on;
        ssl_certificate         /path/to/cert/example.pem;
        ssl_certificate_key     /path/to/cert/example.private.key;
    
        root /path/to/wordpress;
        index index.php;
    
        # Website URL
        server_name blog.duaneleem.com;
    
        # etc...
    }

     

    Solution

    After reading NGINX documentation, the solution to this was to place the SSL directive on “listen.” Here’s a sample server block that demonstrates this:

    server {
        listen 80;
        listen 443 ssl;
    
        ssl_certificate         /path/to/cert/example.pem;
        ssl_certificate_key     /path/to/cert/example.private.key;
    
        root /path/to/wordpress;
        index index.php;
    
        # Website URL
        server_name blog.duaneleem.com;
    
        # etc...
    }

    By adding “ssl” to the listen directive to all my server blocks, everything started working again.

    Source: nginx.org