Tuesday, November 29, 2022

// Tutorial // Databases Checkpoint

Here is the article.

By Caitlin Postal

Introduction

This checkpoint is intended to help you assess what you learned from our introductory articles to Databases, where we defined databases and introduced common database management systems. You can use this checkpoint to test your knowledge on these topics, review key terms and commands, and find resources for continued learning.

A database is any logically modeled collection of information or data. When people refer to a “database” in the context of websites, applications, and the cloud, they often mean a computer program that manages data stored on a computer. These programs, known formally as database management systems (DBMS), can be combined with other programs (like a web server and a front-end framework) to form production-ready applications.

In this checkpoint, you’ll find two sections that synthesize the central ideas from the introductory articles: a brief explanation of what a database is (including subsections on relational and non-relational databases) and a section on how to interact with your DBMS through the command line or graphical user interfaces. In each of these sections, there are interactive components to help you test your knowledge. At the end of this checkpoint, you will find opportunities for continued learning about database management systems, fully managed databases, and building your apps with backend databases.

Resources

What Is a Database?

A database is any logically modeled collection of information, and a database management system is what most people think of when they think “I know what a database is!” You use a database management system (DBMS), which is a computer program designed to interact with the information, to access and manipulate the information stored in your database.

Terms to Know

Define the following terms, then use the dropdown feature to check your work.

Replication

Sharding

There are three common relational models used for database systems:

Relational ModelRelationship
One-to-oneIn a one-to-one relationship, rows in one table (sometimes called the parent table) are related to one and only one row in another table (sometimes called the child table).
One-to-manyIn a one-to-many relationship, a row in the initial table (sometimes called the parent table) can relate to multiple rows in another table (sometimes called the child table).
Many-to-manyIn a many-to-many relationship, rows in one table can related to multiple rows in the other table, and vice versa. While these tables may also be referred to as parent and child tables, the multidirectional relationship does not necessitate a hierarchical relationship.

These relational models structure how databases can relate to each other.

There are two categories for database management: relational and non-relational databases. In the following subsections, you will learn about each type and the common DBMSs for those types.

Relational Databases

A relational database organizes information through relations, which you might recognize as a table.

Check Yourself

What are the elements that make up a relation?

Relation table displaying the tuple on the y-axis and the attribute on the x-axis

What is the difference between a primary key and a foreign key?

When information is stored in a database and organized in the relation, it can be accessed through queries that make a structured request for information. Many relational databases use the Structured Query Language, commonly referred to as SQL to manage queries to the database.

You can use SQL constraints when designing your database. These constraints impose restrictions on what changes can be made to the data in the table.

Check Yourself

Why might you impose constraints on your database?
What are the five constraints that are formally defined by the SQL standard?

Some open-source relational database management systems built with SQL include MySQL, MariaDB, PostgreSQL, and SQLite. Continue learning about relational databases with Understanding Relational Databases and review common relational DBMS with SQLite vs MySQL vs PostgreSQL: A Comparison Of Relational Database Management Systems.

Relational Database Terms To Know

Through each of the articles, you have developed a vocabulary about relational databases. Define each of the following terms, then use the dropdown feature to check your work.

Constraint

Data Types

Object Database

Serverless

Signed and Unsigned Integers

Now that you know about relational databases, you can understand their counterpart: non-relational databases.

Non-relational and NoSQL Databases

If you need to store data in an unstructured way, a non-relational database provides an alternative model. Because a non-relational database does not use SQL, it is sometimes referred to as a NoSQL database.

There are a variety of available options for a non-relational database, such as key-value stores, columnar databases, document stores, and graph databases. Each of these models attends to possible issues with using a relational database, including horizontal scaling, eventual consistency across nodes, and unstructured data management.

Non-relational Database Terms to Know

Each of the non-relational database models has specific features that make it unique. Define the type of model, then use the dropdown feature to check your work.

Key-value databases

Columnar databases

Document-oriented databases

Graph databases

You can check your knowledge about which popular non-relational databases management systems align with the type of database model with the following interactive dropdown feature.

Check Yourself

Match the following database management system to its operational database model.

  • Redis
  • Couchbase
  • Cassandra
  • OrientDB
  • MongoDB
  • Neo4j
  • MemcacheDB
  • Apache HBase
Compare your answers using the dropdown feature.

Whether you are using a relational or a non-relational database, you are likely building an application that includes a database management system as part of its stack.

Building an Application Stack

The database management system is most often deployed as an essential aspect of a larger application. These applications are sometimes called stacks, such as the LAMP stack or Elastic stack.

Check Yourself

Use the dropdown feature to get the answers.

What makes up a LAMP stack?

What makes up Elastic stack?

If you set up a remote server with your application stack, it is recommended that you encrypt your data to protect your system from malicious interference. You can encrypt communications using transport layer security (TLS), which will convert data in motion into a ciphertext that can only be decrypting by the right cipher. The static data stored in your database will remain unencrypted unless using a DBMS that offers data at rest encryption.

To manage your database, you may opt do so directly from the command line interface or through a graphical user interface.

Using the Command Line with your DBMS

You began to use the Linux command line with our introductory articles on cloud servers and you configured a web server with the introductory articles on web server solutions. Through the articles on databases, you have continued to develop familiarity with the command line using commands such as:

  • grep to search plain-text data for a specific text or string.
  • netstat to check network configuration with the flags -lnp to show listening sockets (-l), numeric addresses (-n), and the PID and name of the program for each socket (-p).
  • systemctl to control the systemd service.

You have also experimented with the command line tools that come with different database management systems in order to interact with the database installation. The CLI tool enables you to execute commands on the database server and work interactivley from your terminal window. The following table lists common DBMSs and their associated CLI tool:

DBMSCLI tool
MongoDBMongoDB shell
MySQLmysql
PostgreSQLpsql
Redisredis-cli

There are also third-party command line clients for some database management systems, such as Redli for Redis.

When you use the command line to work with your database system, you open a database-specific server prompt, typically associated with your user account for that database management system. For example, if you were to open a MySQL server prompt and log in with your MySQL user, you would review a database prompt like so:

Each DBMS command-line client has its own syntax for commands.

After learning about SQL constraints, you might use those constraints with a MySQL database by running these commands:

  • CREATE DATABASE to create a database.
  • USE to select a database.
  • CREATE TABLE to create a table with specifications for the columns and constraints applied to those columns.
  • ALTER TABLE with ADD to add constraints to an existing table and with DROP CONSTRAINT to delete a constraint from an existing table.

You can continue to develop your MySQL database skills with the How To Use SQL series.

With Redis, you installed and secured Redis with the following commands and experimented with renaming commands:

  • auth to authenticate clients for database access.
  • exit and quit to exit the Redis-CLI prompt.
  • get to retrieve the key value.
  • ping to test connectivity.
  • set to set keys.

And, in MongoDB shell, you used binary JSON (known as BSON) to run CRUD operations with the following methods of query filtering:

  • count method to check the object count in a specified collection.
  • deleteOne to remove the first document that matches the specifications.
  • deleteMany to remove multiple objects at once.
  • find to retrieve documents in your MongoDB database with the pretty printing feature to make the lines more readable.
  • insertOne method to create individual documents.
  • insertManymethod to insert multiple documents in a single operation or collection.
  • ObjectId object datatype for storing object identifiers.
  • updateOne to update a single document with specified keys.
  • updateMany to update every document in a collection that matches the specified filters.

You will likely use CRUD operations to interact with your data across many database management systems.

Check Yourself

What does CRUD stand for?

While you may opt to manage your database directly from the command line, you can also use a graphical user interface (GUI) for many common database management systems.

Using a Graphical User Interface

There are many different GUI tools for working with your database if you decide against using the designed CLI tool.

To handle MySQL administration over the web, you can use phpMyAdmin by installing and securing phpMyAdmin on many different operating systems or connecting remotely to a MySQL Managed Database. You can also use MySQL Workbench to connect to a MySQL server remotely.

Similar to phpMyAdmin, pgAdmin is a web interface for managing PostgreSQL. You can install and configure pgAdmin in server mode or use it to schedule automatic backups with pgAgent.

For MongoDB, you might consider using MongoDB Compass as the graphical interface to access your database.

Whether you choose to use the command line or a graphical interface to manage your database, you now have the tools necessary to manage your database system.

What’s Next?

With a stronger understanding of databases and popular database management systems, you can store and manage your data or build an application that uses a database system.

For more about working with specific database management systems, you can follow our How To Use SQL and How To Manage Data with MongoDB series. If you run into issues with MySQL, you can debug with How To Troubleshoot Issues in MySQL. For MongoDB issues, assess how your issues related to How To Perform CRUD Operations in MongoDB.

When you’re ready to build your apps with databases, try following these tutorials for common application stack setups:

If you prefer building your apps with fully managed databases, check out the DigitalOcean offerings for managed MongoDB clusters, MySQL or PostgreSQL hosting, and managed Redis. You can also choose a popular database option for a 1-click installation in the DigitalOcean Marketplace.

With your newfound knowledge of databases, you can also continue your cloud journey with containers and security. If you haven’t yet, check out our introductory articles on cloud servers and web servers.

What is LAMP?

 LAMP refers to a collection of open-source software that is commonly used together to serve web applications. The term LAMP is an acronym that represents the configuration of a Linux operating system with an Apache web server, with site data stored in a MySQL database and dynamic content processed by PHP.

The LAMP stack represents one way to configure a web server, and is used in a number of large applications across the web.

How to install WordPress on Ubuntu 18.04 - DigitalOcean

 In this article, we will focus on how to install WordPress on Ubuntu 18.04. WordPress is a free and open-source content management platform based on PHP and MySQL. It’s the world’s leading blogging and content management system with a market share of over 60%, dwarfing its rivals such as Joomla and Drupal. WordPress was first released on May 27th, 2003 and powers over 60 million websites to date! So powerful and popular it has become that some major brands/companies have hosted their sites on the platform. These include Sony Music, Katy Perry, New York Post, and TED.

So why is WordPress this popular? Let’s briefly look into some of the factors that have led to the immense success of the platform.

Ease of Use

WordPress comes with a simple, intuitive and easy to use dashboard. The dashboard doesn’t require any knowledge in web programming languages like PHP, HTML5, and CSS3 and you can build a website with just a few clicks on a button. In addition, there are free templates, widgets, and plugins that come with the platform to help you get started with your blog or website.

Cost effectiveness

WordPress drastically saves you the agony of having to pay developer tonnes of cash to develop your website. All you have to do is to get a free WordPress theme or purchase one and install it. Once installed, you have the freedom to deploy whatever features that suit you and customize a myriad of features without running much code. What’s more, is that it takes a much shorter time to design your site that coding from scratch.

WordPress sites are Responsive

WordPress platform is inherently responsive and you do not have to stay awake worrying about your sites being able to fit across multiple devices. This benefit also adds to your site being ranked higher in Google’s SEO score!

WordPress is SEO ready

WordPress is built using well-structured, clean and consistent code. This makes your blog/site easily indexable by Google and other search engines thereby making your site rank higher. In addition, you can decide which pages rank higher or alternatively use SEO plugins like the popular Yoast plugin which enhances your site’s ranking on Google.

Easy to install and upgrade

It’s very easy to install WordPress on Ubuntu or any other operating system. There are so many open-source scripts to even automate this process. Many hosting companies provide a one-click install feature for WordPress to get you started in no time.

Install WordPress on Ubuntu 18.04

Before we begin, let’s update and upgrade the system. Login as the root user to your system and update the system to update the repositories.

apt update && apt upgrade

Outputupdate and upgrade the ubuntu systemNext, we are going to install the LAMP stack for WordPress to function. LAMP is short for Linux Apache MySQL and PHP.

Step 1: Install Apache

Let’s jump right in and install Apache first. To do this, execute the following command.

apt install apache2

OutputInstall Apache2To confirm that Apache is installed on your system, execute the following command.

systemctl status apache2

Outputhow to check apache2 statusTo verify further, open your browser and go to your server’s IP address.

https://ip-address

OutputApache Web Server Default Page

Step 2: Install MySQL

Next, we are going to install the MariaDB database engine to hold our Wordpress files. MariaDB is an open-source fork of MySQL and most of the hosting companies use it instead of MySQL.

apt install mariadb-server mariadb-client

OutputInstall MySQL Mariadb Server Mariadb ClientLet’s now secure our MariaDB database engine and disallow remote root login.

$ mysql_secure_installation

The first step will prompt you to change the root password to login to the database. You can opt to change it or skip if you are convinced that you have a strong password. To skip changing type n.Change The Root PasswordFor safety’s sake, you will be prompted to remove anonymous users. Type Y.Remove Anonymous UsersNext, disallow remote root login to prevent hackers from accessing your database. However, for testing purposes, you may want to allow log in remotely if you are configuring a virtual serverDisallow Root Login RemotelyNext, remove the test database.Remove Test DatabaseFinally, reload the database to effect the changes.Reload Privilege Table

Step 3: Install PHP

Lastly, we will install PHP as the last component of the LAMP stack.

apt install php php-mysql

OutputInstall PhpTo confirm that PHP is installed , created a info.php file at /var/www/html/ path

vim /var/www/html/info.php

Append the following lines:

<?php
phpinfo();
?>

Save and Exit. Open your browser and append /info.php to the server’s URL.

https://ip-address/info.php

OutputInfo Php Webpage

Step 4: Create WordPress Database

Now it’s time to log in to our MariaDB database as root and create a database for accommodating our WordPress data.

$ mysql -u root -p

OutputMysql Root LoginCreate a database for our WordPress installation.

CREATE DATABASE wordpress_db;

OutputCreate Wordpress DatabaseNext, create a database user for our WordPress setup.

CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'password';

OutputCreate User For Wordpress DatabaseGrant privileges to the user Next, grant the user permissions to access the database

GRANT ALL ON wordpress_db.* TO 'wp_user'@'localhost' IDENTIFIED BY 'password';

OutputGrant Privileges To Wp User On Wordpress DatabaseGreat, now you can exit the database.

FLUSH PRIVILEGES;

Exit;

Step 5: Install WordPress CMS

Go to your temp directory and download the latest WordPress File

cd /tmp && wget https://wordpress.org/latest.tar.gz

OutputDownload WordpressNext, Uncompress the tarball which will generate a folder called “wordpress”.

tar -xvf latest.tar.gz

OutputUncompress Wordpress TarballCopy the wordpress folder to /var/www/html/ path.

cp -R wordpress /var/www/html/

Run the command below to change ownership of ‘wordpress’ directory.

chown -R www-data:www-data /var/www/html/wordpress/

change File permissions of the WordPress folder.

chmod -R 755 /var/www/html/wordpress/

Create ‘uploads’ directory.

$ mkdir /var/www/html/wordpress/wp-content/uploads

Finally, change permissions of ‘uploads’ directory.

chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads/

Open your browser and go to the server’s URL. In my case it’s

https://server-ip/wordpress

You’ll be presented with a WordPress wizard and a list of credentials required to successfully set it up.install wordpress on ubuntu 18.04Fill out the form as shown with the credentials specified when creating the WordPress database in the MariaDB database. Leave out the database host and table prefix and Hit ‘Submit’ button.install wordpress on ubuntu 18.04If all the details are correct, you will be given the green light to proceed. Run the installation.Alright Sparky Run The InstallationFill out the additional details required such as site title, Username, and Password and save them somewhere safe lest you forget. Ensure to use a strong password.Welcome More Information NeededScroll down and Hit ‘Install WordPress’. If all went well, then you will get a ‘Success’ notification as shown.

Success installing WordPress
Sucess

Click on the ‘Login’ button to get to access the Login page of your fresh WordPress installation.Log In To WordpressProvide your login credentials and hit ‘Login’.wordpress dashboardVoila! there goes the WordPress dashboard that you can use to create your first blog or website! Congratulations for having come this far. You can now proceed to discover the various features, plugins, and themes and proceed setting up your first blog/website!

Linkedin profile: Nadah Feteih | Layoff message | Nov. 29, 2022

 After 2 internships, 2 years and 10 months, 2 promotions, and a multitude of projects and experiences - my time at Meta has come to an end. 


I was affected by the #metalayoffs and have taken the last few weeks to process and reflect on this situation. My ambition, drive, and purpose has been a strong driving force in the first few years of my career. My time at Meta was spent working on #privacy teams for two of the largest apps, Messenger and Instagram. I also worked with both the Faith and Charitable Giving teams as an engineer during the month of Ramadan to build features and also drive partnerships, delivering over 400 live-streaming cameras to mosques across the country. My most memorable experiences and contributions have gone beyond my immediate job title, and I’ll always remember the months I spent escalating content enforcement issues with other “internal activists” at the company. I have always prioritized meaningful work and am proud of what I accomplished in my short time here, and was ready to take on a new role at Meta. 

A day prior to the layoffs I had just signed a new offer with Meta to teach as part of the Engineer in Residence program and would have joined Georgia State University for a semester as a faculty member starting in January. The chance to give back by joining a minority serving institution and working with students again (as described in the “Why We Build” feature linked in the comments) was a dream of mine. However, due to the unfortunate timing of the layoff, the transition to this new role was deemed no longer possible which has made this situation the most difficult and disappointing. 

I know this will not be the first (or last) opportunity that aligns with my interests, values, and passion. I will be taking some time to figure out my next move and would love to connect with anyone in this industry, academia, or graduate school to hear your experiences and stories. And feel free to pass along any positions or roles that align with my background and passions. I’m looking forward to embracing the uncertainty that the future may bring, and I know that staying true to myself will only open doors to contribute to causes and take on a new role with an even greater purpose and mission.

#techlayoffs #softwareengineer  #opentowork

DigitalOcean | WordPress, Redis, cloud solution

  1.  15 globally distributed data centers
  2. 185 countries our customers build in
  3. >600K customers building with DigitalOcean
  4. 99.99% Uptime SLA for Droplets and storage

Do more with less complexity

Droplets

On-demand Linux virtual machines. Choose from shared CPU and dedicated CPU plans, with variable amounts of RAM, locally attached SSD storage, and generous transfer quotas. 



Installing a PHP extension on Windows

 On Windows, you have two ways to load a PHP extension: either compile it into PHP, or load the DLL. Loading a pre-compiled extension is the easiest and preferred way.

To load an extension, you need to have it available as a ".dll" file on your system. All the extensions are automatically and periodically compiled by the PHP Group (see next section for the download).

To compile an extension into PHP, please refer to building from source documentation.

To compile a standalone extension (aka a DLL file), please refer to building from source documentation. If the DLL file is available neither with your PHP distribution nor in PECL, you may have to compile it before you can start using the extension.

Where to find an extension? ¶

PHP extensions are usually called "php_*.dll" (where the star represents the name of the extension) and they are located under the "PHP\ext" folder.

PHP ships with the extensions most useful to the majority of developers. They are called "core" extensions.

However, if you need functionality not provided by any core extension, you may still be able to find one in » PECL. The PHP Extension Community Library (PECL) is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.

If you have developed an extension for your own uses, you might want to think about hosting it on PECL so that others with the same needs can benefit from your time. A nice side effect is that you give them a good chance to give you feedback, (hopefully) thanks, bug reports and even fixes/patches. Before you submit your extension for hosting on PECL, please read » PECL submit.

Which extension to download? ¶

Many times, you will find several versions of each DLL:

  • Different version numbers (at least the first two numbers should match)
  • Different thread safety settings
  • Different processor architecture (x86, x64, ...)
  • Different debugging settings
  • etc.

You should keep in mind that your extension settings should match all the settings of the PHP executable you are using. The following PHP script will tell you all about your PHP settings:

Example #1 phpinfo() call

<?php
phpinfo
();
?>

Or from the command line, run:

drive:\\path\to\php\executable\php.exe -i

Loading an extension ¶

The most common way to load a PHP extension is to include it in your php.ini configuration file. Please note that many extensions are already present in your php.ini and that you only need to remove the semicolon to activate them.

Note that, on PHP version 7.2.0 and up, the extension name may be used instead of the extension's file name. As this is OS-independent and easier, especially for newcomers, it becomes the recommended way of specifying extensions to load. File names remain supported for compatibility with prior versions.

;extension=php_extname.dll
extension=php_extname.dll
; On PHP version 7.2 and up, prefer :
extension=extname
zend_extension=another_extension

However, some web servers are confusing because they do not use the php.ini located alongside your PHP executable. To find out where your actual php.ini resides, look for its path in phpinfo():

Configuration File (php.ini) Path  C:\WINDOWS
Loaded Configuration File   C:\Program Files\PHP\5.2\php.ini

After activating an extension, save php.ini, restart the web server and check phpinfo() again. The new extension should now have its own section.

Resolving problems ¶

If the extension does not appear in phpinfo(), you should check your logs to learn where the problem comes from.

If you are using PHP from the command line (CLI), the extension loading error can be read directly on screen.

If you are using PHP with a web server, the location and format of the logs vary depending on your software. Please read your web server documentation to locate the logs, as it does not have anything to do with PHP itself.

Common problems are the location of the DLL and the DLLs it depends on, the value of the " extension_dir" setting inside php.ini and compile-time setting mismatches.

If the problem lies in a compile-time setting mismatch, you probably didn't download the right DLL. Try downloading again the extension with the right settings. Again, phpinfo() can be of great help.

How To Setup Redis Caching For WordPress In A Few Simple Steps

Here is the link. 

In this video, I show you how to install Redis on an Ubuntu server, install the #PHP extension to make #Redis talk to PHP, and finally install the #WordPress plugin that will tie it all together. Everything is done on Digital Ocean so you can easily follow along :) All the commands: https://gist.github.com/alexander-you... Digital Ocean 25$ promo: https://wpcasts.tv/go/digitalocean Sign up for the newsletter: https://wpcasts.tv *SOCIAL* Twitter: https://twitter.com/AlexanderBYoung Instagram: https://www.instagram.com/the_alex_young Facebook: https://www.facebook.com/WPCasts.tv/

Monday, November 28, 2022

Redis pipelining

Here is the link. 

How to optimize round-trip times by batching Redis commands

Redis pipelining is a technique for improving performance by issuing multiple commands at once without waiting for the response to each individual command. Pipelining is supported by most Redis clients. This document describes the problem that pipelining is designed to solve and how pipelining works in Redis.

Request/Response protocols and round-trip time (RTT)

Redis is a TCP server using the client-server model and what is called a Request/Response protocol.
This means that usually a request is accomplished with the following steps:

  • The client sends a query to the server, and reads from the socket, usually in a blocking way, for the server response.
  • The server processes the command and sends the response back to the client.

Clients and Servers are connected via a network link. Such a link can be very fast (a loopback interface) or very slow (a connection established over the Internet with many hops between the two hosts). Whatever the network latency is, it takes time for the packets to travel from the client to the server, and back from the server to the client to carry the reply.

This time is called RTT (Round Trip Time). It's easy to see how this can affect performance when a client needs to perform many requests in a row (for instance adding many elements to the same list, or populating a database with many keys). For instance if the RTT time is 250 milliseconds (in the case of a very slow link over the Internet), even if the server is able to process 100k requests per second, we'll be able to process at max four requests per second.

If the interface used is a loopback interface, the RTT is much shorter, typically sub-millisecond, but even this will add up to a lot if you need to perform many writes in a row.

Redis Pipelining

A Request/Response server can be implemented so that it is able to process new requests even if the client hasn't already read the old responses. This way it is possible to send multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step.

This is called pipelining, and is a technique widely in use for many decades. For instance many POP3 protocol implementations already support this feature, dramatically speeding up the process of downloading new emails from the server.

Redis has supported pipelining since its early days, so whatever version you are running, you can use pipelining with Redis. This is an example using the raw netcat utility: