• Skip to primary navigation
  • Skip to main content

Magda Sicknick

  • About me
  • Articles
  • Portfolio

AWS

January 31, 2019 by Leave a Comment

MySql crash due to lack of memory for buffer pool

I just suddenly ran into a big issue of MySQL crashing every couple of minutes on my Lightsail Linux instance.

A quick look at the log (found in /var/log/mysql/error.log revealed:

2019-01-31T16:20:05.368890Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.25-0ubuntu0.18.04.2) starting as process 2084 …
2019-01-31T16:20:05.372726Z 0 [Note] InnoDB: PUNCH HOLE support available
2019-01-31T16:20:05.372745Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-01-31T16:20:05.372760Z 0 [Note] InnoDB: Uses event mutexes
2019-01-31T16:20:05.372764Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2019-01-31T16:20:05.372767Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-01-31T16:20:05.372771Z 0 [Note] InnoDB: Using Linux native AIO
2019-01-31T16:20:05.372995Z 0 [Note] InnoDB: Number of pools: 1
2019-01-31T16:20:05.373094Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-01-31T16:20:05.375782Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-01-31T16:20:05.375813Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
2019-01-31T16:20:05.375820Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
2019-01-31T16:20:05.375825Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-01-31T16:20:05.375830Z 0 [ERROR] Plugin ‘InnoDB’ init function returned error.
2019-01-31T16:20:05.375834Z 0 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.
2019-01-31T16:20:05.375837Z 0 [ERROR] Failed to initialize builtin plugins.
2019-01-31T16:20:05.375840Z 0 [ERROR] Aborting

The error basically states that InnoDB is tryign to use 128M of memory, and it is unable to get the memory it needs. So a solution to this is to lower the memory used by InnoDB and hope that the issue resolves itself.

Locate and the /etc/mysql/mysql.conf.d/mysqld.cnf file using one of the following commands:

  • sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

OR

  • sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

Scroll to the bottom of the file and find the # * InnoDB heading.
Paste the following line – or if it already exists: change it’s value.

innodb_buffer_pool_size = 64M

Save, and exit the editor.

Now, for this change to take effect, you must restart MySQL with the following:

  • sudo /etc/init.d/mysql restart

Make sure you monitor the system to make sure that this has fixed your issue – and check your error log periodically!

If that did not resolve your issue…

There can be a couple of other reasons as to why your InnoDB keeps crashing:

Not enough memory on your server.

It is possible that the reason your system is crashing is due to lack of RAM. To check how much RAM your system is using, run the following command:

  • top

Here, you will be able to see how much memory your system is using. If you see a fairly low number under KiB Mem free, you might want to consider upgrading your system.

Creating a swap file might also solve this issue. Learn how to do that here.

MySQL has a pending update, or your update was not installed correctly.

Run the following command to check if your MySQL server needs an update:

  • sudo mysql_upgrade -u root -p

Enter your root user MySQL password when prompted.

The system will prompt you if you need to install any updates.

If you see a message stating that your system is up to date, we will force an update just to make sure everything is correct:

  • sudo mysql_upgrade –force -u root -p

Enter your password again.

Your server needs an update

Run the following commands to get all the latest package updates for your server:

  • sudo apt-get update
  • sudo apt-get upgrade

June 11, 2018 by Leave a Comment

Securing Apache with Let’s Encrypt on Ubuntu 16.04

This tutorial will show you how to set up a TLS/SSL certificate from Let’s Encrypt on an Ubuntu 16.04 server running Apache as a web server.

SSL certificates are used within web servers to encrypt the traffic between the server and client, providing extra security for users accessing your application. Let’s Encrypt provides an easy way to obtain and install trusted certificates for free.

Step 1 — Install the Let’s Encrypt Client

Let’s Encrypt certificates are fetched via client software running on your server. The official client is called Certbot, and its developers maintain their own Ubuntu software repository with up-to-date versions. Because Certbot is in such active development it’s worth using this repository to install a newer version than Ubuntu provides by default.

First, add the repository:

$ sudo add-apt-repository ppa:certbot/certbot

You’ll need to press ENTER to accept. Afterwards, update the package list to pick up the new repository’s package information:

$ sudo apt-get update

And finally, install Certbot from the new repository with apt-get:

$ sudo apt-get install python-certbot-apache

The certbot Let’s Encrypt client is now ready to use.

Step 2 — Set Up the SSL Certificate

Generating the SSL certificate for Apache using Certbot is quite straightforward. The client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.

To execute the interactive installation and obtain a certificate that covers only a single domain, run the certbot command like so, where example.com is your domain:

$ sudo certbot --apache -d example.com

If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be the base domain used by Let’s Encrypt to create the certificate, and for that reason we recommend that you pass the bare top-level domain name as first in the list, followed by any additional subdomains or aliases:

$ sudo certbot --apache -d example.com -d www.example.com

For this example, the base domain will be example.com.

If you have multiple virtual hosts, you should run certbot once for each to generate a new certificate for each. You can distribute multiple domains and subdomains across your virtual hosts in any way.

After the dependencies are installed, you will be presented with a step-by-step guide to customize your certificate options. You will be asked to provide an email address for lost key recovery and notices, and you will be able to choose between enabling both http and https access or forcing all requests to redirect to https. It is usually safest to require https, unless you have a specific need for unencrypted http traffic.

When the installation is finished, you should be able to find the generated certificate files at /etc/letsencrypt/live. You can verify the status of your SSL certificate with the following link (don’t forget to replace example.com with your base domain):

https://www.ssllabs.com/ssltest/analyze.html?d=example.com&latest
You should now be able to access your website using a https prefix.

Step 3 — Verifying Certbot Auto-Renewal

Let’s Encrypt certificates only last for 90 days. However, the certbot package we installed takes care of this for us by running certbot renew twice a day via a systemd timer. On non-systemd distributions this functionality is provided by a cron script placed in /etc/cron.d. The task runs twice daily and will renew any certificate that’s within thirty days of expiration.

To test the renewal process, you can do a dry run with certbot:

$ sudo certbot renew --dry-run

If you see no errors, you’re all set. When necessary, Certbot will renew your certificates and reload Apache to pick up the changes. If the automated renewal process ever fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.

Conclusion

In this guide, we saw how to install a free SSL certificate from Let’s Encrypt in order to secure a website hosted with Apache. We recommend that you check the official Let’s Encrypt blog for important updates from time to time, and read the Certbot documentation for more details about the Certbot client.

May 25, 2018 by Leave a Comment

Uploading a large SQL Dump file to phpMyAdmin

Connect to terminal on your instance [Instructions]

Run the following command to sign in to mySQL:

Replace <username> with your mySQL username, and when prompted, enter your password.

$ mysql -u <username> -p

Replace <database> with the name of the database which you are trying to run the dump file for:

mysql> USE <database>

Run the following command to dump the data into the chosen database:

mysql> SOURCE /path/to/your/file/dump.sql; 

April 8, 2018 by Leave a Comment

Creating an Ubuntu instance in AWS

In the following tutorial, you will be able to initialize and set up a Ubuntu 16.04 instance in Amazon Lightsail and Amazon EC2.

Ubuntu instance on Amazon lightsail

First, sign in to AWS and navigate to https://lightsail.aws.amazon.com

On the page, click the Create instance and select Linux/Unix, OS Only and Ubuntu

Scroll to the bottom and select your instance plan. This choice depends on how big you want your wordpress site to be. If you will be posting a lot of pictures, I suggest a larger instance size. For this demo purpose, I will be selecting the $5/month 20GB SSD, with the first month free.

Make your selection, give your instance a name, and hit Create.

You will now be redirected back to the Lightsail dashboard, where you will see your new instance is initializing. After a couple moments, it will say Running and will be a darker gray color.


Now that your instance is initialized, let’s finish setting it up.

Click on the 3 dots and select Manage inside your instance block. You will be taken to the management screen, where you will select Networking.

Under Firewall select Add another and add an HTTPS port 443, and click Save

You can now go back to the Connect tab and click Connect using SSH. AWS will connect you to your instance in a new browser window.

Ubuntu instance on Amazon EC2

April 8, 2018 by Leave a Comment

Setting up WordPress on Ubuntu

Step 1: Get the latest Ubuntu updates

Run the following command to get the latest updates/patches:

  • sudo apt-get update

Step 2: Install Apache Web Server

To install Apache web server, type the following command:

  • sudo apt-get install apache2 apache2-utils

Next, enable the service to start at boot time, as well as start the service:

  • sudo systemctl enable apache2
  • sudo systemctl start apache2

To test whether the server is running, open your web browser and enter http://server_address. The Apache2 default index page will be displayed in case the web server is up and running.

Note: The Apache default root directory is /var/www/html, all your web files will be stored in this directory.

Step 3: Install MySQL Database Server

Next, we need to install MySQL database server with the following command:

  • sudo apt-get install mysql-client mysql-server

During the installation, you will be asked to set the root user password for mysql as shown below. Choose a secure password and hit the OK button twice to proceed.

The database server deployment is not yet secure, for this reason, issue the following command to harden it’s security:

  • sudo mysql_secure_installation

You will be asked to install the ‘validate_password’ plugin, so type in Y/Yes and press Enter and choose the default password strength level.

If you do not want to change the root password, then type N/No when prompted to do so. Answer Y/Yes for the rest of the subsequent questions.

Step 4: Install PHP

PHP 7.0

To install PHP 7.0 and all the necessary modules to work with the web and database servers, run the following command:

$ sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd  
PHP 7.3

We will use the Ondřej Surý’s PPA to install PHP 7.3 version, so install the software-properties-common and python-software-properties packages:

  • sudo apt install software-properties-common python-software-properties

After the installation is complete, add the Ondřej PPA:

  • LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php

and then update your sources:

  • sudo apt update

We can install PHP 7.3 with the following command:

  • sudo apt install php7.3 php7.3-cli php7.3-common

To check if PHP 7.3 is installed on your server, use the command below:

  • php -v

If you want to install a specific module for PHP 7.3, you can search with this command:

  • apt-cache search php7.3

Or, if you want to check all the PHP modules available in Ubuntu, run:

  • apt-cache search –names-only ^php

You can find the command below useful if you want to install the most frequently used PHP modules.

  • sudo apt install php-pear php7.3-curl php7.3-dev php7.3-gd php7.3-mbstring php7.3-zip php7.3-mysql php7.3-xml php7.3-fpm libapache2-mod-php7.3 php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-intl

To set PHP 7.0 as the default, run:

  • sudo update-alternatives –set php /usr/bin/php7.0

To set PHP 7.2 as the default, run:

  • sudo update-alternatives –set php /usr/bin/php7.2

To set PHP 7.3 as the default, run:

  • sudo update-alternatives –set php /usr/bin/php7.3

Before we can configure Apache to use PHP 7.3, we need to disable the old version of PHP 7.0 by typing:

  • sudo a2dismod php7.0

Now enable the newly installed PHP 7.3 version with the following command:

  • sudo a2enmod php7.3

Restart the Apache web server for the changes to take effect:

  • sudo systemctl restart apache2

To test your PHP installation, create a info.php file inside the /var/www/html directory with the following commands:

$ sudo nano /var/www/html/info.php

And paste the code below into the file

<?php 
    phpinfo();
?>

Note: To save and exit, press CTRL+X, confirm with a Y/y, and hit Enter to save.

You should then be able to navigate to http://server_address/info.php and see a page like the one below for successful confirmation of your PHP installation.

Step 4: Install phpMyAdmin

phpMyAdmin is the most common

$ sudo apt-get install phpmyadmin php-mbstring php-gettext

This will ask you a few questions in order to configure your installation correctly.

Warning: When the first prompt appears, apache2 is highlighted, but not selected. If you do not hit Space to select Apache, the installer will not move the necessary files during installation. Hit Space, Tab, and then Enter to select Apache.

For the server selection, choose apache2.
Select yes when asked whether to use dbconfig-common to set up the database
You will be prompted for your database administrator’s password
You will then be asked to choose and confirm a password for the phpMyAdmin application itself
The installation process actually adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/ directory, where it is automatically read.

The only thing we need to do is explicitly enable the PHP mcrypt and mbstring extensions, which we can do by typing:

$ sudo phpenmod mcrypt
$ sudo phpenmod mbstring

Afterwards, you’ll need to restart Apache for your changes to be recognized:

$ sudo systemctl restart apache2

You can now access the web interface by visiting http://server_address/phpmyadmin

Step 5: Install WordPress CMS

Download the latest WordPress package and extract it by issuing the commands below on the terminal:

$ wget -c http://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz

Then move the WordPress files from the extracted folder to the Apache default root directory, /var/www/html/:

$ sudo rsync -av wordpress/* /var/www/html/

Next, set the correct permissions on the website directory, that is give ownership of the WordPress files to the web server as follows:

$ sudo chown -R www-data:www-data /var/www/html/
$ sudo chmod -R 755 /var/www/html/

Step 6: Create WordPress Database

Execute the command below and provide the root user password, then hit Enter to move to the mysql shell:

$ mysql -u root -p 

You will be prompted to enter the password you created for the MySQL installation in Step 3.

At the mysql shell, type the following commands, pressing Enter after each line of a mysql command. Remember to use your own, valid values for database_name, database_user, and also use a strong and secure password as databaseuser_password:

mysql> CREATE DATABASE database_name;
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'localhost' IDENTIFIED BY 'databaseuser_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Next, go the /var/www/html/ directory and rename existing wp-config-sample.php to wp-config.php with the following command:

$ sudo mv /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Open the file for editing:

$ sudo nano /var/www/html/wp-config.php

and update the file with your database information under the MySQL settings section in the highlighted spots:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** 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: To save and exit, press CTRL+X, confirm with a Y/y, and hit Enter to save.

Afterwards, restart the web server and mysql service using the commands below:

$ sudo systemctl restart apache2.service 
$ sudo systemctl restart mysql.service

Open your web browser, then enter your server address: http://server-address to get the WordPress welcome page. Fill all requested on screen information, starting with your choice of language.

Step 7: Enable HTTPS and add an SSL Certificate

Note: Make sure you have HTTPS port 443 enabled in your hosts firewall. [Instructions here]

On Ubuntu systems, the Certbot team maintains a PPA. Once you add it to your list of repositories all you’ll need to do is apt-get the following packages.

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache 

Certbot has a fairly solid beta-quality Apache plugin, which is supported on many platforms, and automates certificate installation.

$ sudo certbot --apache

The Certbot packages on your system come with a cron job that will renew your certificates automatically before they expire. Since Let’s Encrypt certificates last for 90 days, it’s highly advisable to take advantage of this feature. You can test automatic renewal for your certificates by running this command:

$ sudo certbot renew --dry-run
I hope this tutorial was helpful.

Let’s Talk

Looking to get your business a website or update your current online presence?

Please send me information about you project so that I can determine how to best fulfill your needs.

    Service Required *

    Copyright© 2023 · Magda Sicknick · All Rights Reserved · Powered by Wordpress and the Genesis Framework.