<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oyolola toni</title>
    <description>The latest articles on DEV Community by Oyolola toni (@oyololatoni).</description>
    <link>https://dev.to/oyololatoni</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1555508%2Fe65bb339-b1a5-44a6-ab7f-840f50d5e9f2.jpg</url>
      <title>DEV Community: Oyolola toni</title>
      <link>https://dev.to/oyololatoni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oyololatoni"/>
    <language>en</language>
    <item>
      <title>LAMP docker installation automation script in bash</title>
      <dc:creator>Oyolola toni</dc:creator>
      <pubDate>Fri, 02 Aug 2024 12:12:18 +0000</pubDate>
      <link>https://dev.to/oyololatoni/lamp-docker-installation-automation-script-in-bash-2e54</link>
      <guid>https://dev.to/oyololatoni/lamp-docker-installation-automation-script-in-bash-2e54</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F6614%2F1%2AW00YcGweoCZjeryfYB_i4g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F6614%2F1%2AW00YcGweoCZjeryfYB_i4g.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to automate the process of installing all web applications required to run a LAMP server, the following script is writing for that exact purpose.&lt;/p&gt;

&lt;p&gt;The docker container used is the official Ubuntu image, version 24.10 aka noble.&lt;/p&gt;

&lt;p&gt;Both the Dockerfile and installation script are contained in this [github repository](&lt;a href="https://github.com/oyololatoni/docker-LAMP-install-script%5C" rel="noopener noreferrer"&gt;https://github.com/oyololatoni/docker-LAMP-install-script\&lt;/a&gt;). The first step would be to update your host machine and install git if you are using a Linux based machine with the following command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update &amp;amp;&amp;amp; apt-get -y install git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next clone the &lt;a href="http://com/oyololatoni/docker-LAMP-install-script" rel="noopener noreferrer"&gt;github repository&lt;/a&gt; from github into your prefered folder on your Linux machine using the following command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/oyololatoni/docker-LAMP-install-script
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next change directory to the cloned folder and change the ownership of the shell script downloaded such that it is executable&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd docker-LAMP-install-script &amp;amp;&amp;amp; chmod 755 /*.sh 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;While still in the cloned folder, run the following command to build the Ubuntu docker image from the dockerfile which will also run the automate the installation of the LAMP applications by executing the LAMPinstall.sh file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t [TAG] .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;The content of the installation script:&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
# Update the package lists for upgrades and new package installations
apt-get update 

# Install MySQL server and client, Expect, Apache2, PHP, and various PHP extensions
apt install -y mysql-server mysql-client expect apache2 php libapache2-mod-php php-mysql php8.2 php8.2-curl php8.2-dom php8.2-xml php8.2-mysql php8.2-sqlite3 php8.3 php8.3-curl php8.3-dom php8.3-xml php8.3-mysql php8.3-sqlite3

# Add the PPA repository for PHP maintained by Ondřej Surý
add-apt-repository -y ppa:ondrej/php

# Update the package lists again to include packages from the new repository
apt-get update

# Start the MySQL service
service mysql start

# Start the Apache2 service
service  apache2 start

# Start the MySQL secure installation process
# The expect command is used to automate responses to interactive prompts
expect &amp;lt;&amp;lt;EOF
spawn mysql_secure_installation

# Set the timeout for expect commands
set timeout 1

# Handle the password validation prompt. If not present, skip.
expect {
    "Press y|Y for Yes, any other key for No:" {
        send "y\r"
        expect "Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:"
        send "0\r"
    }
    "The 'validate_password' component is installed on the server." {
        send_user "Skipping VALIDATE PASSWORD section as it is already installed.\n"
    }
}

expect "Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:"
send "0\r"

expect "Remove anonymous users? (Press y|Y for Yes, any other key for No) :"
send "y\r"

expect "Disallow root login remotely? (Press y|Y for Yes, any other key for No) :"
send "n\r"

expect "Remove test database and access to it? (Press y|Y for Yes, any other key for No) :"
send "y\r"

expect "Reload privilege tables now? (Press y|Y for Yes, any other key for No) :"
send "y\r"

expect eof
EOF

echo "MySQL secure installation setup complete."

# Ensure MySQL service is started
service mysql start

# Execute MySQL commands to create the database, user, and grant privileges
mysql -uroot &amp;lt;&amp;lt;MYSQL_SCRIPT
CREATE DATABASE IF NOT EXISTS webserver;
CREATE USER IF NOT EXISTS 'User1'@'localhost' IDENTIFIED BY 'Password123';
GRANT ALL PRIVILEGES ON webserver.your_table TO 'User1'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MYSQL_SCRIPT

echo "Database and user created."


# Enable the Apache mod_rewrite module
a2enmod rewrite
service apache2 restart

# Create the directory for the new virtual host
mkdir -p /var/www/demo.com

# Change the ownership of the directory to the current user
chown -R $USER:$USER /var/www/demo.com

# Set permissions for the directory
chmod -R 755 /var/www/demo.com

# Create an index.html file with a simple HTML content and save it in the relevant file
bash -c 'cat &amp;lt;&amp;lt;EOF &amp;gt; /var/www/demo.com/index.html
&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;Welcome to Your_domain!&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;Success! The your_domain virtual host is working!&amp;lt;/h1&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
EOF'

echo "HTML file created at /var/www/demo.com/index.html"

# Create the virtual host configuration file for 'demo.com'
bash -c 'cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apache2/sites-available/demo.com.conf
&amp;lt;VirtualHost *:80&amp;gt;
    ServerAdmin webmaster@localhost
    ServerName demo.com
    ServerAlias www.demo.com
    DocumentRoot /var/www/demo.com
    ErrorLog \${APACHE_LOG_DIR}/error.log
    CustomLog \${APACHE_LOG_DIR}/access.log combined
&amp;lt;/VirtualHost&amp;gt;
EOF'

echo "Virtual hosting configured"

# Enable the new virtual host configuration
a2ensite demo.com.conf

# Disable the default virtual host configuration
a2dissite 000-default.conf

# Set the server name to the loopback IP address (127.0.0.1) to avoid AH00558 error
echo -e "\n# vim: syntax=apache ts=4 sw=4 sts=4 sr noet\nServerName 127.0.0.1" | tee -a /etc/apache2/apache2.conf

# Restart Apache2 service to apply the changes
service apache2 restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To verify that it was successful and run the image, run:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -it -p 80:80 --name dockerLAMP [TAG] bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>linux</category>
      <category>docker</category>
      <category>webdev</category>
      <category>php</category>
    </item>
    <item>
      <title>Automating the installation of a LAMP stack on Ubuntu 22.04</title>
      <dc:creator>Oyolola toni</dc:creator>
      <pubDate>Mon, 10 Jun 2024 09:09:26 +0000</pubDate>
      <link>https://dev.to/oyololatoni/automating-the-installation-of-a-lamp-stack-on-ubuntu-2204-4419</link>
      <guid>https://dev.to/oyololatoni/automating-the-installation-of-a-lamp-stack-on-ubuntu-2204-4419</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AsTzU-9NgNMNcxrD34XxNig.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AsTzU-9NgNMNcxrD34XxNig.jpeg" alt="LAMP"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A LAMP stack is a combination of at least 4 different technologies used in tandem to create a fully functioning web server or web application.&lt;/p&gt;

&lt;p&gt;The complete components of a LAMP stack include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Linux machine (Ubuntu)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache web server&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MySQL database&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PHP&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The installation of this stack will be done using a executable bash script that can be used on any debian based linux distro.&lt;/p&gt;

&lt;p&gt;First create a file named LAMP.sh which is the file where our bash script will be stored, and will also be later executed.&lt;/p&gt;

&lt;p&gt;Next make the file executable by going to the folder where the file is located and execute the following command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod -x LAMP.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can now begin scripting the installation file by editing the LAMP.sh file. You can do this using a cli based file editor such as vim or nano, or you can use a gui based text editor (recommended for beginners).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Update the package lists for upgrades and new package installations
sudo apt-get update 

# Install MySQL server and client, Expect, Apache2, PHP, and various PHP extensions
sudo apt install -y mysql-server mysql-client expect apache2 php libapache2-mod-php php-mysql php8.2 php8.2-curl php8.2-dom php8.2-xml php8.2-mysql php8.2-sqlite3 php8.3 php8.3-curl php8.3-dom php8.3-xml php8.3-mysql php8.3-sqlite3

# Add the PPA repository for PHP maintained by Ondřej Surý
sudo add-apt-repository -y ppa:ondrej/php

# Update the package lists again to include packages from the new repository
sudo apt-get update


echo "Done with installations"

# Start the MySQL service
sudo systemctl start mysql.service

# Start the Apache2 service
sudo systemctl start apache2.service

# Start the MySQL secure installation process
# The expect command is used to automate responses to interactive prompts
sudo expect &amp;lt;&amp;lt;EOF
spawn mysql_secure_installation

# Set the timeout for expect commands
set timeout 1

# Handle the password validation prompt. If not present, skip.
expect {
    "Press y|Y for Yes, any other key for No:" {
        send "y\r"
        expect "Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:"
        send "0\r"
    }
    "The 'validate_password' component is installed on the server." {
        send_user "Skipping VALIDATE PASSWORD section as it is already installed.\n"
    }
}

expect "Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:"
send "0\r"

expect "Remove anonymous users? (Press y|Y for Yes, any other key for No) :"
send "y\r"

expect "Disallow root login remotely? (Press y|Y for Yes, any other key for No) :"
send "n\r"

expect "Remove test database and access to it? (Press y|Y for Yes, any other key for No) :"
send "y\r"

expect "Reload privilege tables now? (Press y|Y for Yes, any other key for No) :"
send "y\r"

expect eof
EOF

echo "MySQL secure installation setup complete."

# Ensure MySQL service is started
sudo systemctl start mysql

# Execute MySQL commands to create the database, user, and grant privileges
sudo mysql -uroot &amp;lt;&amp;lt;MYSQL_SCRIPT
CREATE DATABASE IF NOT EXISTS webserver;
CREATE USER IF NOT EXISTS 'User1'@'localhost' IDENTIFIED BY 'Password123';
GRANT ALL PRIVILEGES ON webserver.your_table TO 'User1'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
MYSQL_SCRIPT

echo "Database and user created."

# Enable the Apache mod_rewrite module
sudo a2enmod rewrite

# Create the directory for the new virtual host
sudo mkdir -p /var/www/demo.com

# Change the ownership of the directory to the current user
sudo chown -R $USER:$USER /var/www/demo.com

# Set permissions for the directory
sudo chmod -R 755 /var/www/demo.com

# Create an index.html file with a simple HTML content and save it in the relevant file
sudo bash -c 'cat &amp;lt;&amp;lt;EOF &amp;gt; /var/www/demo.com/index.html
&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;Welcome to Your_domain!&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;Success! The your_domain virtual host is working!&amp;lt;/h1&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
EOF'

echo "HTML file created at /var/www/demo.com/index.html"

# Create the virtual host configuration file for 'demo.com'
sudo bash -c 'cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apache2/sites-available/demo.com.conf
&amp;lt;VirtualHost *:80&amp;gt;
    ServerAdmin webmaster@localhost
    ServerName demo.com
    ServerAlias www.demo.com
    DocumentRoot /var/www/demo.com
    ErrorLog \${APACHE_LOG_DIR}/error.log
    CustomLog \${APACHE_LOG_DIR}/access.log combined
&amp;lt;/VirtualHost&amp;gt;
EOF'

echo "Virtual hosting configured"

# Enable the new virtual host configuration
sudo a2ensite demo.com.conf

# Disable the default virtual host configuration
sudo a2dissite 000-default.conf

# Restart Apache2 service to apply the changes
sudo systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Execute the script using this command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./LAMP.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;or using&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash LAMP.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>linux</category>
      <category>apache</category>
      <category>sql</category>
      <category>php</category>
    </item>
    <item>
      <title>Step-by-step guide for how to install an SQL server on Ubuntu 22.04</title>
      <dc:creator>Oyolola toni</dc:creator>
      <pubDate>Wed, 05 Jun 2024 21:06:43 +0000</pubDate>
      <link>https://dev.to/oyololatoni/step-by-step-guide-for-how-to-install-an-sql-server-on-ubuntu-2204-2ahk</link>
      <guid>https://dev.to/oyololatoni/step-by-step-guide-for-how-to-install-an-sql-server-on-ubuntu-2204-2ahk</guid>
      <description>&lt;h2&gt;
  
  
  Step-by-step guide for how to install an SQL server on Ubuntu 22.04
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGh5dwceD6hf17r58tRZ9Tw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGh5dwceD6hf17r58tRZ9Tw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Installing the SQL server&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Firstly update your desktop and install the SQL server&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update

sudo apt-get install mysql-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Verify that the server is running with the following command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl start mysql.service

sudo systemctl status mysql.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The result should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGh5dwceD6hf17r58tRZ9Tw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AGh5dwceD6hf17r58tRZ9Tw.png" alt="live MySQL server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure MySQL
&lt;/h2&gt;

&lt;p&gt;You will need to set the password for the root account if you are running the installation on an Ubuntu machine because authentication is deactivated on Ubuntu by default. So as to avoid an error, you’ll need to configure the root account authentication method&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Change the password for root using ALTER USER:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Exit after making this change&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; exit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Secure your MySQL root user account
&lt;/h2&gt;

&lt;p&gt;In securing your server, you will need to execute the following command to setup your password policy&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mysql_secure_installation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The password policy given will apply to subsequent users accounts created.&lt;/p&gt;

&lt;p&gt;The next is to authenticate using the root user’s password:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -u root -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This command gives the root user access to the MySQL cli, and also to interact directly with the MySQL server.&lt;/p&gt;

&lt;p&gt;Then go back to using the default authentication method using this command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will allow you connect using the sudo mysql command again.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Creating default/new MySQL user and its privileges&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is bad OpSec to use the root account to perform regular day-to-day action on the database. The best option is to create a user account with limited privileges.&lt;/p&gt;

&lt;p&gt;This is first done by logging in as root with the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Alternatively, if you have previously set a password for the root account use this instead:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -u root -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next create a new user:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; CREATE USER 'username'@'host' IDENTIFIED WITH authentication_plugin BY 'password';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After entering the command, follow the prompt and fill in your username, hostname (localhost if you’re using Ubuntu).&lt;/p&gt;

&lt;p&gt;For authentication, you have the options of using auth_socket plugin which provides string security without requiring a password but has a shortcoming of preventing remote connections,authentication_plugin plugin, caching_sha2_password which is the default MySQL plugin, but its shortfall is that some versions of PHP are not compatible with it or mysql_native_password plugin.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; CREATE USER 'jack'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can also alter an existing user using:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; ALTER 'jack'@'hostname' IDENTIFIED WITH mysql_native_password BY 'password';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Assigning privileges
&lt;/h2&gt;

&lt;p&gt;After creating the user, you can assign it with privileges with the following syntax.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; GRANT PRIVILEGE ON database.table TO 'username'@'host';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Using GRANT ALL PRIVILEGES instead will give the user superuser privileges similar to that of root. Such flag will otherwise defeat the purpose of creating a separate user account from root.&lt;/p&gt;

&lt;p&gt;The PRIVILEGE variable represents what action a user is allowed to perform. Global privileges can also be granted by replacing database.table with *.&lt;/p&gt;

&lt;p&gt;Below we will be granting user permissions to create, modify, delete, insert, select, update and delete data from a table by using CREATE, ALTER, DROP, INSERT, SELECT, UPDATE and DELETE respectively.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT on *.* TO 'jack'@'hostname' WITH GRANT OPTION;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The WITH GRANT OPTION flag allows the user to grant privileges it has to other users.&lt;/p&gt;

&lt;p&gt;Next we will use the FLUSH PRIVILEGES command to empty the cache and free up memory:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; FLUSH PRIVILEGES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After you can exit the MySQL cli&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; exit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can now log in back using your credentials&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql -u jack -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Testing the MySQL server
&lt;/h2&gt;

&lt;p&gt;You can now verify that the MySQL server is running with the following command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl status mysql.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Alternatively, you can connect to the MySQL database using the administrative command tool mysqladmin.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mysqladmin -p -u jack version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>mysql</category>
      <category>linux</category>
      <category>ubuntu</category>
      <category>devops</category>
    </item>
    <item>
      <title>How to setup an Apache server on Ubuntu 22.04.4 LTS with Virtual hosting</title>
      <dc:creator>Oyolola toni</dc:creator>
      <pubDate>Fri, 31 May 2024 15:45:40 +0000</pubDate>
      <link>https://dev.to/oyololatoni/how-to-setup-an-apache-server-on-ubuntu-22044-lts-with-virtual-hosting-1mnm</link>
      <guid>https://dev.to/oyololatoni/how-to-setup-an-apache-server-on-ubuntu-22044-lts-with-virtual-hosting-1mnm</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdXU1djueJapzeCDXKq2jzA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AdXU1djueJapzeCDXKq2jzA.jpeg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apache is a popular open source web server that is widely used to host web pages.&lt;/p&gt;

&lt;p&gt;In this tutorial, you’ll be creating a virtual host environment to run multiple websites with Apache on your Ubuntu 22.04.4 LTS server allowing you to add several domains hosted on just 1 IP address.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Apache
&lt;/h2&gt;

&lt;p&gt;We’ll begin by updating the local repository with the following command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, install the Apache server&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Run this command to start the Apache server&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl start apache2.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Run this command to verify that Apache is running&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl status apache2.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can test if your Apache server is live by typing your public IP address in your web server, you should get the following result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKSdvA3MKETakRXlOn4iElA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKSdvA3MKETakRXlOn4iElA.png" alt="apache home page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Your Own Website
&lt;/h2&gt;

&lt;p&gt;Apache by default is setup to serve documents from **/var/&lt;a href="http://www" rel="noopener noreferrer"&gt;www&lt;/a&gt;. **So you will need to create store your webpage directory in this folder. We will be using demo.com here as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir -p /var/www/demo.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You will need to modify the ownership of this directory so as to be accessible and executable by your user account. This is done by executing the following:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chown -R $USER:$USER /var/www/demo.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next you will change the permission settings of the directory to allow everyone to have read and execute permissions while the $USER has read, write and execute permissions&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chmod -R 755 /var/www/demo.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next create an &lt;strong&gt;index.html&lt;/strong&gt; file that will be used to host your site’s html code&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vim /var/www/demo.com/index.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Insert the following code in the &lt;strong&gt;index.html **file by pressing **i **to write the file. And to save it press **ESQ **t&lt;/strong&gt;o exit insert mode, *&lt;em&gt;and *&lt;/em&gt;:wq **after to save and quit the the file editor&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;Welcome to Your_domain!&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;Success!  The your_domain virtual host is working!&amp;lt;/h1&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Setting up the VirtualHost Configuration File
&lt;/h2&gt;

&lt;p&gt;The next step is to setup the configuration file for the webserver in the &lt;strong&gt;/etc/apache2&lt;/strong&gt; folder — which is where the Apache configuration file is located. The file also uses the **.conf **extension. Create the configuration file using the following command&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo vim /etc/apache2/sites-available/demo.com.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Insert this code into the file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
    ServerAdmin webmaster@localhost
    ServerName demo.com
    ServerAlias www.demo.com
    DocumentRoot /var/www/demo.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Save and close the file&lt;/p&gt;

&lt;h2&gt;
  
  
  Activating VirtualHost file
&lt;/h2&gt;

&lt;p&gt;After setting up the website, the next step is to activate the virtual host file. Do that by running the following commands&lt;/p&gt;

&lt;p&gt;First enable the file with the **a2ensite **command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo a2ensite demo.com.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then disable the default configuration file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo a2dissite 000-default.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Check for configuration errors using the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apache2ctl configtest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The output of that command should be “ Syntax OK” to indicate that it is properly configured&lt;/p&gt;

&lt;p&gt;Restart the Apache server to implement the changes&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Congrats! Your website is now hosted on your machine. To view the website navigate to &lt;a href="http://demo.com" rel="noopener noreferrer"&gt;http://demo.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>apache</category>
      <category>devops</category>
      <category>ubuntu</category>
      <category>selfhosting</category>
    </item>
  </channel>
</rss>
