One place for hosting & domains

      How To Install Linux, Apache, MariaDB, PHP (LAMP) stack on Debian 9


      Introduction

      A “LAMP” stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server. The site data is stored in a MariaDB database, and dynamic content is processed by PHP.

      In this guide, we will install a LAMP stack on a Debian 9 server.

      Prerequisites

      In order to complete this tutorial, you will need to have a Debian 9 server with a non-root sudo-enabled user account and a basic firewall. This can be configured using our initial server setup guide for Debian 9.

      Step 1 — Installing Apache and Updating the Firewall

      The Apache web server is among the most popular web servers in the world. It’s well-documented and has been in wide use for much of the history of the web, which makes it a great default choice for hosting a website.

      Install Apache using Debian’s package manager, apt:

      • sudo apt update
      • sudo apt install apache2

      Since this is a sudo command, these operations are executed with root privileges. It will ask you for your regular user’s password to verify your intentions.

      Once you’ve entered your password, apt will tell you which packages it plans to install and how much extra disk space they’ll take up. Press Y and hit ENTER to continue, and the installation will proceed.

      Next, assuming that you have followed the initial server setup instructions by installing and enabling the UFW firewall, make sure that your firewall allows HTTP and HTTPS traffic.

      When installed on Debian 9, UFW comes loaded with app profiles which you can use to tweak your firewall settings. View the full list of application profiles by running:

      The WWW profiles are used to manage ports used by web servers:

      Output

      Available applications: . . . WWW WWW Cache WWW Full WWW Secure . . .

      If you inspect the WWW Full profile, it shows that it enables traffic to ports 80 and 443:

      • sudo ufw app info "WWW Full"

      Output

      Profile: WWW Full Title: Web Server (HTTP,HTTPS) Description: Web Server (HTTP,HTTPS) Ports: 80,443/tcp

      Allow incoming HTTP and HTTPS traffic for this profile:

      • sudo ufw allow in “WWW Full”

      You can do a spot check right away to verify that everything went as planned by visiting your server's public IP address in your web browser:

      http://your_server_ip
      

      You will see the default Debian 9 Apache web page, which is there for informational and testing purposes. It should look something like this:

      Debian 9 Apache default

      If you see this page, then your web server is now correctly installed and accessible through your firewall.

      If you do not know what your server's public IP address is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.

      There are a few different ways to do this from the command line. First, you could use the iproute2 tools to get your IP address by typing this:

      • ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's//.*$//'

      This will give you two or three lines back. They are all correct addresses, but your computer may only be able to use one of them, so feel free to try each one.

      An alternative method is to use the curl utility to contact an outside party to tell you how it sees your server. This is done by asking a specific server what your IP address is:

      • sudo apt install curl
      • curl http://icanhazip.com

      Regardless of the method you use to get your IP address, type it into your web browser's address bar to view the default Apache page.

      Step 2 — Installing MariaDB

      Now that you have your web server up and running, it is time to install MariaDB. MariaDB is a database management system. Basically, it will organize and provide access to databases where your site can store information.

      MariaDB is a community-built fork of MySQL. In Debian 9, the default MySQL server is MariaDB 10.1, and the mysql-server package, which is normally used to install MySQL, is a transitional package that will actually install MariaDB. However, it’s recommended that you install MariaDB using the program’s actual package, mariadb-server.

      Again, use apt to acquire and install this software:

      • sudo apt install mariadb-server

      Note: In this case, you do not have to run sudo apt update prior to the command. This is because you recently ran it in the commands above to install Apache, and the package index on your computer should already be up-to-date.

      This command, too, will show you a list of the packages that will be installed, along with the amount of disk space they'll take up. Enter Y to continue.

      When the installation is complete, run a simple security script that comes pre-installed with MariaDB which will remove some insecure default settings and lock down access to your database system. Start the interactive script by running:

      • sudo mysql_secure_installation

      This will take you through a series of prompts where you can make some changes to your MariaDB installation’s security options. The first prompt will ask you to enter the current database root password. This is an administrative account in MariaDB that has increased privileges. Think of it as being similar to the root account for the server itself (although the one you are configuring now is a MariaDB-specific account). Because you just installed MariaDB and haven’t made any configuration changes yet, this password will be blank, so just press ENTER at the prompt.

      The next prompt asks you whether you'd like to set up a database root password. Type N and then press ENTER. In Debian, the root account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Later, we will cover how to optionally set up an additional administrative account for password access if socket authentication is not appropriate for your use case.

      From there, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MariaDB immediately respects the changes you have made.

      In new installs on Debian systems, the root MariaDB user is set to authenticate using the unix_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) administrative rights.

      Because the server uses the root account for tasks like log rotation and starting and stopping the server, it is best not to change the root account's authentication details. Changing the account credentials in the /etc/mysql/debian.cnf may work initially, but package updates could potentially overwrite those changes. Instead of modifying the root account, the package maintainers recommend creating a separate administrative account if you need to set up password-based access.

      To do so, we will be creating a new account called admin with the same capabilities as the root account, but configured for password authentication. To do this, open up the MariaDB prompt from your terminal:

      Now, we can create a new user with root privileges and password-based access. Change the username and password to match your preferences:

      • GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

      Flush the privileges to ensure that they are saved and available in the current session:

      Following this, exit the MariaDB shell:

      Now, any time you want to access your database as your new administrative user, you’ll need to authenticate as that user with the password you just set using the following command:

      At this point, your database system is set up and you can move on to installing PHP, the final component of the LAMP stack.

      Step 3 — Installing PHP

      PHP is the component of your setup that will process code to display dynamic content. It can run scripts, connect to your MariaDB databases to get information, and hand the processed content over to your web server to display.

      Once again, leverage the apt system to install PHP. In addition, include some helper packages this time so that PHP code can run under the Apache server and talk to your MariaDB database:

      • sudo apt install php libapache2-mod-php php-mysql

      This should install PHP without any problems. We'll test this in a moment.

      In most cases, you will want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell the web server to prefer PHP files over others, so make Apache look for an index.php file first.

      To do this, type this command to open the dir.conf file in a text editor with root privileges:

      • sudo nano /etc/apache2/mods-enabled/dir.conf

      It will look like this:

      /etc/apache2/mods-enabled/dir.conf

      <IfModule mod_dir.c>
          DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
      </IfModule>
      

      Move the PHP index file (highlighted above) to the first position after the DirectoryIndex specification, like this:

      /etc/apache2/mods-enabled/dir.conf

      <IfModule mod_dir.c>
          DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
      </IfModule>
      

      When you are finished, save and close the file by pressing CTRL+X. Confirm the save by typing Y and then hit ENTER to verify the file save location.

      After this, restart the Apache web server in order for your changes to be recognized. Do this by typing this:

      • sudo systemctl restart apache2

      You can also check on the status of the apache2 service using systemctl:

      • sudo systemctl status apache2

      Sample Output

      ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2018-09-04 18:23:03 UTC; 9s ago Process: 22209 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS) Process: 22216 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 22221 (apache2) Tasks: 6 (limit: 4915) CGroup: /system.slice/apache2.service ├─22221 /usr/sbin/apache2 -k start ├─22222 /usr/sbin/apache2 -k start ├─22223 /usr/sbin/apache2 -k start ├─22224 /usr/sbin/apache2 -k start ├─22225 /usr/sbin/apache2 -k start └─22226 /usr/sbin/apache2 -k start

      To enhance the functionality of PHP, you have the option to install some additional modules. To see the available options for PHP modules and libraries, pipe the results of apt search into less, a pager which lets you scroll through the output of other commands:

      Use the arrow keys to scroll up and down, and press Q to quit.

      The results are all optional components that you can install. It will give you a short description for each:

      Output

      Sorting... Full Text Search... bandwidthd-pgsql/stable 2.0.1+cvs20090917-10 amd64 Tracks usage of TCP/IP and builds html files with graphs bluefish/stable 2.2.9-1+b1 amd64 advanced Gtk+ text editor for web and software development cacti/stable 0.8.8h+ds1-10 all web interface for graphing of monitoring systems cakephp-scripts/stable 2.8.5-1 all rapid application development framework for PHP (scripts) ganglia-webfrontend/stable 3.6.1-3 all cluster monitoring toolkit - web front-end haserl/stable 0.9.35-2+b1 amd64 CGI scripting program for embedded environments kdevelop-php-docs/stable 5.0.3-1 all transitional package for kdevelop-php kdevelop-php-docs-l10n/stable 5.0.3-1 all transitional package for kdevelop-php-l10n … :

      To learn more about what each module does, you could search the internet for more information about them. Alternatively, look at the long description of the package by typing:

      There will be a lot of output, with one field called Description which will have a longer explanation of the functionality that the module provides.

      For example, to find out what the php-cli module does, you could type this:

      Along with a large amount of other information, you'll find something that looks like this:

      Output

      … Description: command-line interpreter for the PHP scripting language (default) This package provides the /usr/bin/php command interpreter, useful for testing PHP scripts from a shell or performing general shell scripting tasks. . PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. . This package is a dependency package, which depends on Debian's default PHP version (currently 7.0). …

      If, after researching, you decide you would like to install a package, you can do so by using the apt install command like you have been doing for the other software.

      If you decided that php-cli is something that you need, you could type:

      If you want to install more than one module, you can do that by listing each one, separated by a space, following the apt install command, like this:

      • sudo apt install package1 package2 ...

      At this point, your LAMP stack is installed and configured. Before making any more changes or deploying an application, though, it would be helpful to proactively test out your PHP configuration in case there are any issues that should be addressed.

      Step 4 — Testing PHP Processing on your Web Server

      In order to test that your system is configured properly for PHP, create a very basic PHP script called info.php. In order for Apache to find this file and serve it correctly, it must be saved to a very specific directory called the web root.

      In Debian 9, this directory is located at /var/www/html/. Create the file at that location by running:

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

      This will open a blank file. Add the following text, which is valid PHP code, inside the file:

      /var/www/html/info.php

      <?php
      phpinfo();
      ?>
      

      When you are finished, save and close the file.

      Now you can test whether your web server is able to correctly display content generated by this PHP script. To try this out, visit this page in your web browser. You'll need your server's public IP address again.

      The address you will want to visit is:

      http://your_server_ip/info.php
      

      The page that you come to should look something like this:

      Debian 9 default PHP info

      This page provides some basic information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.

      If you can see this page in your browser, then your PHP is working as expected.

      You probably want to remove this file after this test because it could actually give information about your server to unauthorized users. To do this, run the following command:

      • sudo rm /var/www/html/info.php

      You can always recreate this page if you need to access the information again later.

      Conclusion

      Now that you have a LAMP stack installed, you have many choices for what to do next. Basically, you've installed a platform that will allow you to install most kinds of websites and web software on your server.



      Source link

      How To Install Nginx on Debian 9


      Introduction

      Nginx is one of the most popular web servers in the world and responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or reverse proxy.

      In this guide, we’ll discuss how to install Nginx on your Debian 9 server.

      Prerequisites

      Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server and an active firewall. You can learn how to set these up by following our initial server setup guide for Debian 9.

      When you have an account available, log in as your non-root user to begin.

      Step 1 – Installing Nginx

      Because Nginx is available in Debian’s default repositories, it is possible to install it from these repositories using the apt packaging system.

      Since this is our first interaction with the apt packaging system in this session, let’s also update our local package index so that we have access to the most recent package listings. Afterwards, we can install nginx:

      • sudo apt update
      • sudo apt install nginx

      After accepting the procedure, apt will install Nginx and any required dependencies to your server.

      Step 2 – Adjusting the Firewall

      Before testing Nginx, the firewall software needs to be adjusted to allow access to the service.

      List the application configurations that ufw knows how to work with by typing:

      You should get a listing of the application profiles:

      Output

      Available applications: ... Nginx Full Nginx HTTP Nginx HTTPS ...

      As you can see, there are three profiles available for Nginx:

      • Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
      • Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
      • Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

      It is recommended that you enable the most restrictive profile that will still allow the traffic you've configured. Since we haven't configured SSL for our server yet in this guide, we will only need to allow traffic on port 80.

      You can enable this by typing:

      • sudo ufw allow 'Nginx HTTP'

      You can verify the change by typing:

      You should see HTTP traffic allowed in the displayed output:

      Output

      Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Nginx HTTP ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Nginx HTTP (v6) ALLOW Anywhere (v6)

      Step 3 – Checking your Web Server

      At the end of the installation process, Debian 9 starts Nginx. The web server should already be up and running.

      We can check with the systemd init system to make sure the service is running by typing:

      Output

      ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2018-09-04 18:15:57 UTC; 3min 28s ago Docs: man:nginx(8) Process: 2402 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 2399 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 2404 (nginx) Tasks: 2 (limit: 4915) CGroup: /system.slice/nginx.service ├─2404 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; └─2405 nginx: worker process

      As you can see above, the service appears to have started successfully. However, the best way to test this is to actually request a page from Nginx.

      You can access the default Nginx landing page to confirm that the software is running properly by navigating to your server's IP address. If you do not know your server's IP address, try typing this at your server's command prompt:

      • ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's//.*$//'

      You will get back a few lines. You can try each in your web browser to see if they work.

      When you have your server's IP address, enter it into your browser's address bar:

      http://your_server_ip
      

      You should see the default Nginx landing page:

      Nginx default page

      This page is included with Nginx to show you that the server is running correctly.

      Step 4 – Managing the Nginx Process

      Now that you have your web server up and running, let's review some basic management commands.

      To stop your web server, type:

      • sudo systemctl stop nginx

      To start the web server when it is stopped, type:

      • sudo systemctl start nginx

      To stop and then start the service again, type:

      • sudo systemctl restart nginx

      If you are simply making configuration changes, Nginx can often reload without dropping connections. To do this, type:

      • sudo systemctl reload nginx

      By default, Nginx is configured to start automatically when the server boots. If this is not what you want, you can disable this behavior by typing:

      • sudo systemctl disable nginx

      To re-enable the service to start up at boot, you can type:

      • sudo systemctl enable nginx

      Step 5 – Setting Up Server Blocks

      When using the Nginx web server, server blocks (similar to virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain from a single server. We will set up a domain called example.com, but you should replace this with your own domain name. To learn more about setting up a domain name with DigitalOcean, see our introduction to DigitalOcean DNS.

      Nginx on Debian 9 has one server block enabled by default that is configured to serve documents out of a directory at /var/www/html. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html, let's create a directory structure within /var/www for our example.com site, leaving /var/www/html in place as the default directory to be served if a client request doesn't match any other sites.

      Create the directory for example.com as follows, using the -p flag to create any necessary parent directories:

      • sudo mkdir -p /var/www/example.com/html

      Next, assign ownership of the directory with the $USER environment variable:

      • sudo chown -R $USER:$USER /var/www/example.com/html

      The permissions of your web roots should be correct if you haven't modified your umask value, but you can make sure by typing:

      • sudo chmod -R 755 /var/www/example.com

      Next, create a sample index.html page using nano or your favorite editor:

      • nano /var/www/example.com/html/index.html

      Inside, add the following sample HTML:

      /var/www/example.com/html/index.html

      <html>
          <head>
              <title>Welcome to Example.com!</title>
          </head>
          <body>
              <h1>Success!  The example.com server block is working!</h1>
          </body>
      </html>
      

      Save and close the file when you are finished.

      In order for Nginx to serve this content, it's necessary to create a server block with the correct directives. Instead of modifying the default configuration file directly, let’s make a new one at /etc/nginx/sites-available/example.com:

      • sudo nano /etc/nginx/sites-available/example.com

      Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:

      /etc/nginx/sites-available/example.com

      server {
              listen 80;
              listen [::]:80;
      
              root /var/www/example.com/html;
              index index.html index.htm index.nginx-debian.html;
      
              server_name example.com www.example.com;
      
              location / {
                      try_files $uri $uri/ =404;
              }
      }
      

      Notice that we’ve updated the root configuration to our new directory, and the server_name to our domain name.

      Next, let's enable the file by creating a link from it to the sites-enabled directory, which Nginx reads from during startup:

      • sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

      Two server blocks are now enabled and configured to respond to requests based on their listen and server_name directives (you can read more about how Nginx processes these directives here):

      • example.com: Will respond to requests for example.com and www.example.com.
      • default: Will respond to any requests on port 80 that do not match the other two blocks.

      To avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file. Open the file:

      • sudo nano /etc/nginx/nginx.conf

      Find the server_names_hash_bucket_size directive and remove the # symbol to uncomment the line:

      /etc/nginx/nginx.conf

      ...
      http {
          ...
          server_names_hash_bucket_size 64;
          ...
      }
      ...
      

      Save and close the file when you are finished.

      Next, test to make sure that there are no syntax errors in any of your Nginx files:

      If there aren't any problems, you will see the following output:

      Output

      nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

      Once your configuration test passes, restart Nginx to enable your changes:

      • sudo systemctl restart nginx

      Nginx should now be serving your domain name. You can test this by navigating to http://example.com, where you should see something like this:

      Nginx first server block

      Step 6 – Getting Familiar with Important Nginx Files and Directories

      Now that you know how to manage the Nginx service itself, you should take a few minutes to familiarize yourself with a few important directories and files.

      Content

      • /var/www/html: The actual web content, which by default only consists of the default Nginx page you saw earlier, is served out of the /var/www/html directory. This can be changed by altering Nginx configuration files.

      Server Configuration

      • /etc/nginx: The Nginx configuration directory. All of the Nginx configuration files reside here.
      • /etc/nginx/nginx.conf: The main Nginx configuration file. This can be modified to make changes to the Nginx global configuration.
      • /etc/nginx/sites-available/: The directory where per-site server blocks can be stored. Nginx will not use the configuration files found in this directory unless they are linked to the sites-enabled directory. Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory.
      • /etc/nginx/sites-enabled/: The directory where enabled per-site server blocks are stored. Typically, these are created by linking to configuration files found in the sites-available directory.
      • /etc/nginx/snippets: This directory contains configuration fragments that can be included elsewhere in the Nginx configuration. Potentially repeatable configuration segments are good candidates for refactoring into snippets.

      Server Logs

      • /var/log/nginx/access.log: Every request to your web server is recorded in this log file unless Nginx is configured to do otherwise.
      • /var/log/nginx/error.log: Any Nginx errors will be recorded in this log.

      Conclusion

      Now that you have your web server installed, you have many options for the type of content you can serve and the technologies you can use to create a richer experience for your users.



      Source link

      How To Install MariaDB on Debian 9


      Introduction

      MariaDB is an open-source database management system, commonly installed in place of MySQL as part of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data. MariaDB was forked from MySQL in 2009 due to licensing concerns.

      The short version of the installation is simple: update your package index, install the mariadb-server package (which points to MariaDB), and then run the included security script.

      • sudo apt update
      • sudo apt install mariadb-server
      • sudo mysql_secure_installation

      This tutorial will explain how to install MariaDB version 10.1 on a Debian 9 server.

      Prerequisites

      To follow this tutorial, you will need:

      Step 1 — Installing MariaDB

      On Debian 9, MariaDB version 10.1 is included in the APT package repositories by default. It is marked as the default MySQL variant by the Debian MySQL/MariaDB packaging team.

      To install it, update the package index on your server with apt:

      Then install the package:

      • sudo apt install mariadb-server

      This will install MariaDB, but will not prompt you to set a password or make any other configuration changes. Because this leaves your installation of MariaDB insecure, we will address this next.

      Step 2 — Configuring MariaDB

      For fresh installations, you'll want to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users.

      Run the security script:

      • sudo mysql_secure_installation

      This will take you through a series of prompts where you can make some changes to your MariaDB installation’s security options. The first prompt will ask you to enter the current database root password. Since we have not set one up yet, press ENTER to indicate "none".

      The next prompt asks you whether you'd like to set up a database root password. Type N and then press ENTER. In Debian, the root account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Later, we will cover how to optionally set up an additional administrative account for password access if socket authentication is not appropriate for your use case.

      From there, you can press Y and then ENTER to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MariaDB immediately respects the changes you have made.

      Step 3 — (Optional) Adjusting User Authentication and Privileges

      In Debian systems running MariaDB 10.1, the root MariaDB user is set to authenticate using the unix_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) administrative rights.

      Because the server uses the root account for tasks like log rotation and starting and stopping the server, it is best not to change the root account's authentication details. Changing the account credentials in the /etc/mysql/debian.cnf may work initially, but package updates could potentially overwrite those changes. Instead of modifying the root account, the package maintainers recommend creating a separate administrative account if you need to set up password-based access.

      To do so, we will be creating a new account called admin with the same capabilities as the root account, but configured for password authentication. To do this, open up the MariaDB prompt from your terminal:

      Now, we can create a new user with root privileges and password-based access. Change the username and password to match your preferences:

      • GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

      Flush the privileges to ensure that they are saved and available in the current session:

      Following this, exit the MariaDB shell:

      Finally, let's test the MariaDB installation.

      Step 4 — Testing MariaDB

      When installed from the default repositories, MariaDB should start running automatically. To test this, check its status.

      • sudo systemctl status mariadb

      You'll see output similar to the following:

      Output

      ● mariadb.service - MariaDB database server
         Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
         Active: active (running) since Tue 2018-09-04 16:22:47 UTC; 2h 35min ago
        Process: 15596 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSIT
        Process: 15594 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
        Process: 15478 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   
        Process: 15474 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITI
        Process: 15471 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysql
       Main PID: 15567 (mysqld)
         Status: "Taking your SQL requests now..."
          Tasks: 27 (limit: 4915)
         CGroup: /system.slice/mariadb.service
                 └─15567 /usr/sbin/mysqld
      
      Sep 04 16:22:45 deb-mysql1 systemd[1]: Starting MariaDB database server...
      Sep 04 16:22:46 deb-mysql1 mysqld[15567]: 2018-09-04 16:22:46 140183374869056 [Note] /usr/sbin/mysqld (mysqld 10.1.26-MariaDB-0+deb9u1) starting as process 15567 ...
      Sep 04 16:22:47 deb-mysql1 systemd[1]: Started MariaDB database server.
      

      If MariaDB isn't running, you can start it with sudo systemctl start mariadb.

      For an additional check, you can try connecting to the database using the mysqladmin tool, which is a client that lets you run administrative commands. For example, this command says to connect to MariaDB as root and return the version using the Unix socket:

      You should see output similar to this:

      Output

      mysqladmin Ver 9.1 Distrib 10.1.26-MariaDB, for debian-linux-gnu on x86_64 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Server version 10.1.26-MariaDB-0+deb9u1 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 2 hours 44 min 46 sec Threads: 1 Questions: 36 Slow queries: 0 Opens: 21 Flush tables: 1 Open tables: 15 Queries per second avg: 0.003

      If you configured a separate administrative user with password authentication, you could perform the same operation by typing:

      • mysqladmin -u admin -p version

      This means MariaDB is up and running and that your user is able to authenticate successfully.

      Conclusion

      You now have a basic MariaDB setup installed on your server. Here are a few examples of next steps you can take:



      Source link