How do I install WordPress in a Lightsail instance instead of the WordPress blueprint that Bitnami provides?

4 minute read
1

I want to install the WordPress application in my Amazon Lightsail instance instead of the Lightsail WordPress blueprint that Bitnami provides.

Short description

Complete the following steps to install WordPress in the major Linux distributions that are available in Lightsail.

Important:

  • As a best practice, WordPress suggests that you use either Apache or NGINX as the preferred hosting service. The following resolution installs Apache.
  • WordPress suggests a version minimum of PHP 7.3 and MariaDB 10.2 for their latest packages. It's a best practice to use newer versions of these packages and the latest Linux distributions in Amazon Lightsail.
    For more information, see Server environment on the WordPress website.
  • The latest package and WordPress's minimum requirements are subject to change. The following resolution uses the configurations that WordPress supports as of October 2021.
  • The following resolution provides the basic installation steps. You can personalize WordPress through plugins, the operating system-level firewall, and so on.

Resolution

For instructions on how to install WordPress in Amazon Linux 2, see Host a WordPress blog on Amazon Linux 2.

Install a LAMP stack

To install LAMP (Linux, Apache, MariaDB, and PHP) in your Lightsail instance, see How do I manually install a LAMP stack on my Lightsail instance?

Create the database and a user

WordPress is a database-oriented website. Before you install the WordPress application, you must create a database and a user.

Complete the following steps to create the database and user:

  1. Run the following command to enter the MySQL shell as root:

    sudo mysql -u root -p
    password: <insert-root-password>

    Note: The password doesn't appear when you enter it so that it isn't visible to other users.

  2. Create a database and user with a password, and then add permissions to the new database:

    mysql> CREATE DATABASE databasename;
    mysql> GRANT ALL PRIVILEGES ON databasename.* TO 'wordpress_user'@'localhost' IDENTIFIED BY 'PASSWORD';
    mysql> FLUSH PRIVILEGES;
    mysql> exit;

    Note: Replace databasename with your database name, wordpress_user with your WordPress user's name, and PASSWORD with your password.

Install and configure the WordPress package

To download the latest WordPress package to the /tmp directory and extract the package to access the configuration files, complete the following steps:

  1. Download the latest WordPress package:

    cd /tmp
    wget https://wordpress.org/latest.tar.gz
  2. Run the following command to extract the package:

    sudo tar -xzvf latest.tar.gz
  3. Move the WordPress files to the /var/www/html directory so that you can access them through Apache:

    sudo cp -pr /tmp/wordpress/* /var/www/html/
  4. To create the wp-config.php WordPress configuration file, rename the file to wp-config-sample.php:

    cd /var/www/html
    sudo mv wp-config-sample.php wp-config.php
  5. Run the following command to open the WordPress configuration file in the vi editor:

    sudo vi wp-config.php
  6. Add the DB credentials. The following is an example snippet:

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define( 'DB_NAME', 'databasename' );
    
    /** MySQL database username */
    define( 'DB_USER', 'wordpress_user');
    
    /** MySQL database password *
    define( 'DB_PASSWORD', 'PASSWORD' );
    
    /** MySQL hostname */
    define( 'DB_HOST', 'localhost' );
    
    /** Database charset to use in creating database tables. */
    define( 'DB_CHARSET', 'utf8' );
    
    /** The database collate type. Don't change this if in doubt. */
    define( 'DB_COLLATE', '' )

    Note: Replace databasename, wordpress_user, and PASSWORD with your values.

  7. To save the file, press Esc, type :wq!, and then press Enter.

  8. (Optional) In some distributions, such as Ubuntu and Debian, the Apache installation might have added a preexisting file that's named index.html. This file causes conflicts with the WordPress index.php file. If this occurs, then delete index.html or move it to a backup file:

    $ sudo mv index.html backup_index.html
  9. Restart the Apache service:
    CentOS and Amazon Linux 2

    $ sudo systemctl restart httpd

    Ubuntu and Debian versions

    $ sudo systemctl restart apache2

Verify that the port is open and active

When you launch a Lightsail instance, port 80 is open by default. If you turned on SSL for your website, then make sure to open port 443 so that the port is accessible over the internet. For information about how to add a firewall rule to your instance, see Instance firewalls in Lightsail.

Do a final check

Access your instance's public IP address in your web browser, and then confirm that it goes to the page wp-admin/install.php. You can now create WordPress credentials in wp-admin/install.php and access the WordPress dashboard.

AWS OFFICIAL
AWS OFFICIALUpdated 3 months ago