How-tos

this category contains the tutorials about how to implements solutions

How to Safely Update WordPress on AWS ec2

vivek bangare

Vivek Bangare

Author

How to Safely Update WordPress on AWS EC2

Hello everyone, In this article, I will talk about how to safely update WordPress on AWS EC2 instances. In the next few minutes, we will understand creating AMI, take backup and restore the database. At the end of this article will be able to understand the safe updation process of production instances. 

Assumption:
  • You have a separate web instance (EC2) and DB instance (RDS) for your WordPress site.
  • DB is of MySQL is configured in AWS RDS
  • Credentials for MySQL 
Prepare Before Upgrading WordPress

Firstly create one AMI for the current web instance(EC2), please follow the below steps. We will perform this through the AWS console.

  • Login to the AWS console
  • Select the EC2 instance(WordPress web instance) from the EC2 section.
  • Create one AMI from the current WordPress instance.

Action ⇒ Image and templates ⇒ Create image

select-ec2-for-ami

Fill in the details for AMI and click on the ‘Create image’ button.

Note: Please make sure to enable No reboot, otherwise your instance will reboot.
create-ami-from-ec2

It may take a couple of minutes for the AMI to be created. After its creation, it will appear in the AMIs view in AWS Explorer.

Secondly, we have to take a backup of MySQL DB.

Follow the below command for taking backup(as a dump) of the MySQL database through the mysqldump utility.

mysqldump -u {username} -p'{password}' -h {hostname} -P {port} {db_name} > {wordpress}.sql

For restoring DB you can use the below command.

mysql -u {username} -p'{password}' -h {hostname} -P {port} {db_name} < {wordpress}.sql
Note: you can use any name for .sql file.
Backup and Restore steps are optional, but for safer side we should always take backup of any database before any activity.
Updating WordPress via the Admin Dashboard

This method is easier and is recommended for all users.

Thirdly and most importantly, log in to the admin area of your WordPress website. 

wordpress-login

Go to Dashboard » Updates page.

Note: While writing this article 5.7.1 is latest available update for worpress, in your case it might be diffrent.

Now you can see in the top most section that a new version of WordPress is available. You just need to press the ‘Please update now’ button, then ‘Update Now’ to initiate the update.

WordPress will now fetch the latest version of the software and install it for you.

See the update progress process on your screen. During the upgrade, WordPress will put your site in maintenance mode.

At this stage, your site will be visible to users, but will not be able to install any plugins or themes.

After successful installation, you will be redirected to the WordPress welcome screen. Depending on each release you may see a page explaining what’s new in WordPress and the new features which you should try.

That’s all, Now we have successfully updated WordPress to the latest version.

For better security, we need to update the PHP version also which is compatible with our WordPress.

How to update PHP version

vivek bangare

Vivek Bangare

Author

How to update PHP version

Hello everyone, In this article, we will understand how to update the PHP version. Before that let’s understand what is PHP.

Introduction:

PHP is a common server-side programming language. Many CMS and popular frames like WordPress, Magento and Laravel are written in PHP. While writing this article PHP 8.0 is the most recent major version of PHP. 

PHP introduces a number of revolutionary changes, performance enhancements, and many new features such as named arguments, JIT compiler, union types, match expression and more. This post will show you how to install PHP 8 on Ubuntu 18.04 and integrate it with Apache for WordPress. The same steps apply to Ubuntu 20.04 also. 

Check your PHP version installed.

Firstly, open the terminal, connect to your server using SSH, and switch to root account access or use sudo.

Note: Before upgrading or installing any PHP version, ensure that your applications support it. 
ssh <USERNAME>@<SERVER_IP> 
sudo su - 

Before we move ahead, we can check the existing installed PHP version on the server simply by typing the following command.

php -v
Check your PHP modules installed

To check installed PHP modules in Ubuntu, type the following command (as Ubuntu makes PHP modules available via packages

sudo dpkg --get-selections | grep -i php 
sudo update-alternatives --list php 
Add PPA for PHP 8

In order to install PHP 8.0 on Ubuntu you may have to add third-party repositories and install from there. 

Simply run the commands below to add the below repository to Ubuntu.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Install PHP 8 for apache

To use PHP 8.0 with Apache instead, use the steps below:  

For Apache2 you’ll want to run the commands below along with the installed modules above.

sudo apt install php8.0

After the installation has completed, you can confirm the installation using the following command. 

php -v
Upgrade to PHP 8 for Apache

Once you have installed PHP 8 you need to upgrade to the latest installed version of PHP. You need to disable the old PHP version and enable the new PHP version 8. 

sudo a2dismod php7.4 
sudo a2enmod php8.0

After enabling PHP 8.0, run the commands below to restart Apache2 and PHP 8.0 should be used to support WordPress.

sudo systemctl restart apache2.service   
or
sudo service apache2 restart
Testing PHP Processing

Suppose we have apache2 installed and we already deployed our site in that. Then we can test whether the web server is configured properly for PHP processing, by creating a new file named phpinfo.php inside the /var/www/html/ directory with the following code:

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

Save the file, open your browser, and visit: https://dns-or-server_ip/phpinfo.php

phpinfo
Note: Let's consider you have WordPress website hosted on same machine and it uses current php then you might get below error.
php-installation-mysql-extention-missing
PHP’s MySQL installation 

Run the following commands depending on the PHP version to resolve the above error.

sudo apt-get update
sudo apt-get install php8.0-mysql
sudo systemctl restart apache2.service   
or   
sudo service apache2 restart