The post Installing and Configuring OpenShift: A Step-by-Step Guide for Linux Experts with Terminal Code appeared first on Tech Blog.
]]>OpenShift is a powerful container application platform developed by Red Hat. It allows you to deploy and manage your applications at scale, with support for multiple languages and frameworks. In this blog post, we will explore the features and benefits of OpenShift, and show you how to get started with your own OpenShift deployment.
Features of OpenShift
- Docker-based Containers OpenShift is based on Docker containers, which provide a lightweight and portable way to package and distribute applications. Docker containers are fast, reliable, and easy to manage, making them an ideal platform for deploying applications at scale.
- Kubernetes Orchestration OpenShift uses Kubernetes to manage the deployment and scaling of containerized applications. Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. With Kubernetes, you can deploy and manage your applications with ease, without worrying about the underlying infrastructure.
- Support for Multiple Languages and Frameworks OpenShift supports a wide range of programming languages and frameworks, including Java, Python, Ruby, Node.js, and more. This makes it easy to deploy and manage applications written in your language of choice, without having to worry about compatibility issues or vendor lock-in.
- Web Console and Command-Line Tools OpenShift provides a web console and command-line tools for managing your applications and resources. The web console provides a graphical interface for deploying and managing applications, while the command-line tools provide a more flexible and powerful way to manage your OpenShift deployment.
Benefits of OpenShift
Scalability and Flexibility OpenShift is designed to scale to meet the needs of your application, from small development environments to large-scale production deployments. With OpenShift, you can easily scale your applications up or down as needed, without having to worry about the underlying infrastructure.
Security and Compliance OpenShift provides a secure and compliant platform for deploying and managing your applications. With built-in security features and support for compliance standards such as PCI-DSS and HIPAA, OpenShift makes it easy to meet your security and compliance requirements.
Developer Productivity OpenShift provides a streamlined and easy-to-use platform for deploying and managing your applications, which can help increase developer productivity. With OpenShift, developers can focus on writing code and building applications, without having to worry about the underlying infrastructure or deployment process.
To get started with OpenShift, you can deploy it on your own infrastructure using the OpenShift Container Platform or use a managed service like OpenShift Online. Here are the basic steps to deploy OpenShift on your own infrastructure:
OpenShift is a powerful container application platform developed by Red Hat that enables you to deploy and manage your applications at scale. If you are a Linux expert looking to install OpenShift on your system, this step-by-step guide with terminal code will help you get started.
There are two primary methods for installing OpenShift:
As a Linux expert, you may prefer to use OpenShift Origin as it gives you more control over the installation process. However, OpenShift Container Platform comes with support and additional features that may be beneficial for your organization.
Before you begin the installation process, make sure your system meets the minimum requirements for OpenShift. These requirements include:
You will also need to install Docker, Kubernetes, and other dependencies on your system. You can refer to the OpenShift documentation for a complete list of prerequisites and installation instructions.
Once your system is prepared, download the OpenShift installation package from the official website or from the OpenShift Origin GitHub repository. The installation package includes all the necessary files and scripts to install and configure OpenShift on your system.
You can use the following command to download the OpenShift Origin installation package:
$ wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
To install OpenShift, follow these steps:
$ tar -xvf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
$ cd openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/
$ export PATH=$PATH:`pwd`
$ oc cluster up
$ oc login -u system:admin
After installing OpenShift, you will need to configure it according to your needs. This may include setting up security settings, creating users and groups, configuring storage and network settings, and more.
You can use the OpenShift console or command-line tools to configure OpenShift. The OpenShift documentation provides detailed instructions for each configuration task.
Step 6: Deploy Applications
Once OpenShift is configured
Conclusion
OpenShift is a powerful container application platform that provides a flexible and scalable way to deploy and manage your applications. With support for multiple languages and frameworks, a secure and compliant platform, and powerful management tools, OpenShift is an ideal choice for organizations of all sizes. So why not give it a try and see how it can help you streamline your application deployment and management process?
The post Installing and Configuring OpenShift: A Step-by-Step Guide for Linux Experts with Terminal Code appeared first on Tech Blog.
]]>The post Sed Command in Linux with Practical Examples appeared first on Tech Blog.
]]>One of the most common uses of sed is to replace a specific word or phrase in a file. For example, let’s say we have a file called “example.txt” with the following contents:
This is the first line of the file.
This is the second line of the file.
This is the third line of the file.
If we want to replace the word “first” with “second” on the first line of the file, we can use the following sed command:
sed 's/first/second/' example.txt
This command tells sed to perform a substitution, replacing the first occurrence of “first” with “second” on the first line of the file. The output of this command will be:
This is the second line of the file.
This is the second line of the file.
This is the third line of the file.
We can also use sed to make changes to multiple lines. For example, if we want to replace the word “line” with “lines” throughout the entire file, we can use the following command:
sed 's/line/lines/g' example.txt
The “g” at the end of the command tells sed to perform the replacement globally, on all occurrences of the word “line” in the file. The output of this command will be:
This is the first lines of the file.
This is the second lines of the file.
This is the third lines of the file.
Sed can also be used to insert text, or even delete lines. For example, if we want to insert a new line after the second line of the file, we can use the following command:
sed '2a\
This is a new line.' example.txt
This command tells sed to insert the text “This is a new line.” after the second line of the file. The output of this command will be:
This is the first line of the file.
This is the second line of the file.
This is a new line.
This is the third line of the file.
As you can see, the sed command is a powerful tool that can be used to perform a wide variety of text transformations on a file. For more information on using sed, you can refer to the man pages or online resources.
The post Sed Command in Linux with Practical Examples appeared first on Tech Blog.
]]>The post Rsync Command uses with examples appeared first on Tech Blog.
]]>In this blog post, we’ll take a closer look at the rsync command, exploring its various options, use cases, and best practices.
Before we dive into the details of using rsync, let’s first make sure it’s installed on our system. Most modern Linux distributions should come with rsync pre-installed, but if you’re using an older or more minimalist distribution, you may need to install it manually.
To check if rsync is already installed on your system, you can run the following command:
sudo apt-get install rsync
Once rsync is installed, you’re ready to start using it.
The most basic usage of rsync is to copy files and directories from one location to another. The basic syntax for copying files with rsync is as follows:
rsync source destination
/path/to/source
to the directory /path/to/destination
, you would run the following command:rsync /path/to/source /path/to/destination
In addition to the basic usage described above, rsync offers a wide range of advanced options and features. Here are some of the most commonly used options:
-a
: This option stands for “archive” and is a shorthand for several other options that are commonly used when synchronizing files, including -r
(recursive), -l
(copy symlinks as symlinks), -p
(preserve permissions), and -t
(preserve modification times). This is typically the most useful option to use when synchronizing files.-v
: This option stands for “verbose” and causes rsync to output more detailed information about what it’s doing. This can be useful for debugging or just getting a better sense of what rsync is doing.-z
: This option stands for “compress” and causes rsync to compress data before sending it over the network. This can significantly speed up transfers over slow or congested networks.--delete
: This option causes rsync to delete files from the destination that do not exist in the source. This can be useful for keeping the destination in sync with the source.--exclude
: This option allows you to specify files or directories that should be excluded from the synchronization. You can use this option multiple times to exclude multiple files or directories.--progress
: This option causes rsync to output progress information during the transfer, including the percentage completed and the transfer speed.Let’s take a look at some real-world examples of how to use rsync.
Suppose you have a directory /path/to/local
on your local machine that you want to synchronize with a directory `/path
Suppose you have two directories on the same machine that you want to keep in sync, /path/to/source
and /path/to/destination
. To synchronize these directories, you can run the following command:
rsync -av /path/to/source/ /path/to/destination/
The -a
option ensures that rsync preserves all file attributes, including permissions, ownership, timestamps, and symlinks. The -v
option enables verbose output, so you can see which files are being transferred. The trailing slashes after the directory paths ensure that rsync copies the contents of the directories, rather than the directories themselves.
Suppose you have a directory on your local machine that you want to synchronize with a directory on a remote server. To do this, you can use the following command:
rsync -av /path/to/local user@remote:/path/to/remote
In this example, /path/to/local
is the source directory on your local machine, user
is the username for the remote server, remote
is the hostname or IP address of the remote server, and /path/to/remote
is the destination directory on the remote server. You’ll be prompted to enter the password for the remote user account.
Suppose you have a directory on a remote server that you want to synchronize with a directory on your local machine. To do this, you can use the following command:
rsync -av user@remote:/path/to/remote /path/to/local
In this example, user
is the username for the remote server, remote
is the hostname or IP address of the remote server, /path/to/remote
is the source directory on the remote server, and /path/to/local
is the destination directory on your local machine. You’ll be prompted to enter the password for the remote user account.
Suppose you want to synchronize a directory, but exclude certain files or directories from the transfer. To do this, you can use the --exclude
option. For example, to synchronize a directory /path/to/source
, but exclude all files with the extension .log
, you can use the following command:
rsync -av --exclude '*.log' /path/to/source/ /path/to/destination/
In this example, *.log
is a wildcard pattern that matches all files with the extension .log
. The --exclude
option tells rsync to exclude any files that match this pattern.
Before you perform an actual synchronization, it’s often a good idea to run a dry run to see what changes will be made. To do this, you can use the --dry-run
option, like this:
rsync -av --dry-run /path/to/source/ /path/to/destination/
This will show you a list of all the files that would be copied, deleted, or modified, without actually performing any changes.
#!/bin/bash # Set the source and destination directories src_dir="/path/to/source" dest_dir="/path/to/backup" # Set the name of the backup file backup_name="backup_$(date +%Y-%m-%d_%H-%M-%S)" # Use rsync to take an incremental backup of the source directory rsync -avz --delete --backup --backup-dir="$dest_dir/$backup_name" "$src_dir/" "$dest_dir/latest/" # Remove any old backups find "$dest_dir" -maxdepth 1 -type d -name "backup_*" -mtime +7 -exec rm -rf {} \;
To set up a weekly cron job to run this script automatically, follow these steps:
crontab -e
in the terminal.0 3 * * 0 /bin/bash /path/to/backup_script.sh
This cron job will run the backup script every Sunday at 3 AM. You can modify the cron schedule by changing the values in the cron expression (0 3 * * 0
), which represents the minute, hour, day of the month, month, and day of the week when the job will run. For example, to run the job every day at 3 AM, you could change the cron expression to 0 3 * * *
.
Note that you may need to modify the permissions of the backup script to make it executable using chmod +x backup_script.sh
.
These are just a few examples of how you can use rsync to synchronize files and directories. With its wide range of options and features, rsync is a versatile tool that can be used in many different scenarios.
The post Rsync Command uses with examples appeared first on Tech Blog.
]]>The post How to Install WordPress with Nginx on Ubuntu 22.04 appeared first on Tech Blog.
]]>In this tutorial, we will install WordPress on Ubuntu 22.04 LTS version with the Nginx web server. That gives you a feeling like a production environment while developing in the local environment.
WordPress is a free and open-source content management system mainly used to publish blogs on the internet. It is designed for those who don’t know how to code. WordPress makes it simple to create and maintain websites and blogs. Due to its popularity, over a third of websites, today are powered by WordPress. It is written in PHP and uses MariaDB and MySQL as a database backend
This tutorial has a video view here:
Before starting, the LEMP server must be installed on your server. If not installed, you can install it by running the following command:
apt install nginx mariadb-server php php-fpm php-curl php-mysql php-gd php-mbstring php-xml php-imagick php-zip php-xmlrpc
Once the LEMP server is installed, verify the PHP version using the following command:
php -v
You will get the PHP version in the following output:
nano /etc/php/8.1/fpm/php.ini
Change the following lines:
cgi.fix_pathinfo=0 upload_max_filesize = 128M post_max_size = 128M memory_limit = 512M max_execution_time = 120
Save and close the file when you are finished.
WordPress uses a database to store its content. So you will need to create a database and user for WordPress.
First, log in to the MariaDB shell with the following command:
mysql
Once you are logged in, create a database and user with the following command:
MariaDB [(none)]> CREATE DATABASE wpdb;
MariaDB [(none)]> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your password';
Next, grant all the privileges to the WordPress database using the following command:
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'localhost';
Next, flush the privileges and exit from the MariaDB with the following command:
MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
Once you are finished, you can proceed to the next step.
First, navigate to the Nginx web root directory and download the latest version of WordPress using the following command:
cd /var/www/html wget https://wordpress.org/latest.tar.gz
Once the WordPress is downloaded, extract the downloaded file with the following command:
tar -zxvf latest.tar.gz
Save and close the file when you are finished. Next, set proper permission and ownership to the WordPress directory:
chown -R www-data:www-data /var/www/html/wordpress chmod -R 755 /var/www/html/wordpress
Next, you will need to create an Nginx virtual host configuration file to serve WordPress over the internet.
nano /etc/nginx/conf.d/wordpress.conf
Add the following configuration:
server { listen 80; root /var/www/html/wordpress; index index.php index.html index.htm; server_name wordpress.example.com; client_max_body_size 500M; location / { try_files $uri $uri/ /index.php?$args; } location = /favicon.ico { log_not_found off; access_log off; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Save and close the file then verify the Nginx configuration using the following command:
nginx -t
You will get the following output:
After getting the output that your syntax is ok one more thing you need to do. Create a local domain resolver by editing your hosts
file:
sudo nano /etc/hosts
Add the following record at the end of the file:
127.0.0.1 wordpress.example.com
Next, restart the Nginx and PHP-FPM services to apply the changes.
systemctl restart nginx systemctl restart php8.1-fpm
Now, open your web browser and access the WordPress installation wizard using the URL http://wordpress.example.com. You will be redirected to the following page:
Hit on lets Go Button:
Fill in all credentials and necessary info and hit on submit button.
Click on the run installation button.
Congratulations! you have successfully installed WordPress with Nginx on Ubuntu 22.04. You can now install your preferred themes, and plugins and start building your own website and start blogging.
The post How to Install WordPress with Nginx on Ubuntu 22.04 appeared first on Tech Blog.
]]>The post Install React JS on Ubuntu 22.04 LTS appeared first on Tech Blog.
]]>React was created by Jordan Walke, a software engineer at Facebook, who released an early prototype of React called “FaxJS”. It was first deployed on Facebook’s News Feed in 2011 and later on Instagram in 2012. And finally, it was open-sourced at JS Conference US in May 2013. And as a result, the Reacts first release was published in 2013.
In this tutorial, you will learn to install and create React Application on a Ubuntu Linux system.
View on Youtube:
install some necessary utility packages so Install the following dependencies required by this tutorial like software-properties-common ca-certificates lsb-release apt-transport-https
etc.
Well, by default Node. js version comes with Ubuntu 22.04 LTS is 12.22.9, but we currently want the latest version 16.15. So, we need to add PPA sources which are required to be able to install NodeJS 16 on your Ubuntu 22.04 LTS.
Add the Node.js 16 (current stable version) PPA to your Ubuntu system
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
sudo apt update
Node.js is required to create and run a React.js application. The following steps will install Node.js 16 on your Ubuntu system. or click here to choose your desired version. Next, run the following command to install the Node.js to your system:
sudo apt install -y nodejs
Check the currently active version of Node.js
node --version
Also, you can check npm version using.
npm --version
Also, you can check npx version using.
npx --version
You need to install create-react-app
a utility package in your system.
sudo npm -g install create-react-app
create-react-app myapp
On successful application creation, you will see a long result on the screen. In the end, you will find the result like below with some useful commands.
Once you have created your React application. This will create a folder in the current directory with the project name. Switch to that project and run yarn start
to start the application.
cd myapp
npm start
The default reacts application starts on port 3000. Access your React application using 3000 port with the system IP address. For local machines use “localhost” followed by port.
Let’s create an awesome user interface with React.
In this tutorial, you have learned, how to set up the React.js development environment and access the application in a web browser. Additionally, you found instructions to create a production build of your React application.
The post Install React JS on Ubuntu 22.04 LTS appeared first on Tech Blog.
]]>The post How to Install Django on Ubuntu 22.04 LTS appeared first on Tech Blog.
]]>Django is a full-featured Python web framework for developing dynamic websites and applications. Using Django, you can quickly create Python web applications.
In this guide, you will get Django up and running on an Ubuntu 22.04 server. After installation, you will start a new project to use as the basis for your site.
So, there are different ways to install Django, depending upon your needs and how you want to configure your development environment.
Here we are going to install Django in a self-contained environment using tools like venv
and virtualenv
. A virtual environment allows you to install Django in a project directory without affecting the larger system. You can therefore select Python packages on a per-project basis, regardless of conflicts with other projects’ requirements. This is typically the most practical and recommended approach to working with Django.
Before you begin, you should have a non-root user with sudo privileges available on your Ubuntu 22.04 server.
Let’s begin by refreshing the local package index: let’s open a terminal and type
sudo apt update
Before instal Django, let’s check for the python installed in your system. Actually, ubuntu Jammy Jellyfish by default comes with python version 3.10.
python3 -V
Next, let’s install pip and venv from the Ubuntu repositories: use the following command.
sudo apt install python3-pip python3-venv
Now, whenever you start a new project, you can create a virtual environment for it. Start by creating and moving into my new project directory: My Django Project.
mkdir ~/myDjangoproject cd ~/myDjangoproject
Next, create a virtual environment within the project directory using the python command compatible with your Python version.
python3 -m venv my_env
We will call our virtual environment is my_env, you can name it something descriptive related to your project:
This will install standalone versions of Python and pip into an isolated directory structure within your project directory. A directory will be created with the name you select, which will hold the file hierarchy where your packages will be installed.
To install packages into the isolated environment, you must activate it by typing:
source my_env/bin/activate
Your prompt should change to reflect that you are now in your virtual environment.
Note: To leave your virtual environment, you need to issue the deactivate command from anywhere on the system.
deactivate
Now it’s time to install Django. Type command pip install Django.
pip install django
Let’s check my Django admin version so type:
django-admin --version
To build your project, you can use Django-admin with the star project command. We will call our project djangoproject, but you can replace this with a different name.
django-admin startproject djangoproject .
To avoid having too many nested directories, let’s tell Django to place the management script and inner directory in the current directory using the ending dot.
startproject will create a directory within your current working directory that includes: A management script manage dot py. And A directory that includes the actual project code.
Now its time to migrate the database. let’s use the migrate command with manage.py.
python manage.py migrate
Finally, create an administrative user so that you can use the Djano admin interface. Let’s do this with the create super user command:
python manage.py createsuperuser
This will prompt for user name, if you left it blank then it will grab the ubuntu default username as you can see here my username is techblog. Lets set my user name admin.
Putting an email and password for my admin account.
Once you have a user, you can start up the Django development server using forllowng command:
python manage.py runserver localhost:8000 or python manage.py runserver 0.0.0.0:8000
Now open up a web browser and here we go it working. And here you see the log reflection while accessing the server.
http://your_server_ip:8000
Now open admin dashboard using slash admin followed by our ip or localhost. Login using your credential and here is your admin panel.
http://your_server_ip:8000/admin
So, guys finally we deployed Django in Ubuntu 22.04 LTS server, hope this article is helpful to you Thank you.
The post How to Install Django on Ubuntu 22.04 LTS appeared first on Tech Blog.
]]>The post Laravel Mongodb Integration appeared first on Tech Blog.
]]>MongoDB’s document model makes it a great database choice for web applications because its flexible schema structure will easily evolve to meet your growing needs.
curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - sudo apt update sudo apt install mongodb
Before we can install the MongoDB libraries for Laravel, we need to install the PHP extension for MongoDB. Run the following command:
sudo pecl install mongodb
You will also need to ensure that the MongoDB extension is enabled in your php.ini file. The location of your php.ini file will vary depending on your operating system. Add the following line to your php.ini file:
extension="mongodb.so"
Now check your MongoDB status whether it’s running or not?
service mongodb status
Once you have PHP and Composer installed, you can install Laravel. From a terminal window, enter the following command:
composer create-project laravel/laravel mongodb cd mongodb/ php artisan serve --host=0.0.0.0 --port=8000
Open .env
file from your laravel application directory and Configure MongoDB Database
DB_CONNECTION=mongodb DB_HOST=127.0.0.1 DB_PORT=27017 DB_DATABASE=myappdb DB_USERNAME= DB_PASSWORD=
In order for Laravel to communicate with your MongoDB database, you will need to add your database connection information to the config\database.php file under the “connections” object in your Laravel project as shown in this example:
'connections' => [..... ....... 'mongodb' => [ 'driver' => 'mongodb', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', 27017), 'database' => env('DB_DATABASE', 'myappdb'), 'username' => env('DB_USERNAME', ''), 'password' => env('DB_PASSWORD', '') ], ........
Make sure to include the correct authentication information.
Set the default database connection name in config\database.php at top section
/* |-------------------------------------------------------------------------- | Default Database Connection Name |-------------------------------------------------------------------------- | | Here you may specify which of the database connections below you wish | to use as your default connection for all database work. Of course | you may use many connections at once using the Database library. | */ 'default' => env('DB_CONNECTION', 'mongodb'),
In order to make connections with MongoDB you need Jenssegers Library:
composer require jenssegers/mongodb
If your Laravel project does not load dependencies automatically, you may also need to add the following to the provider’s section in your app.php file:
'providers' => [ /* * Laravel Framework Service Providers... */ Jenssegers\Mongodb\MongodbServiceProvider::class,
Now install auth functionality to your application, here I am going to use vue js framework for front end. So you can choose angular, react also
composer require laravel/ui php artisan ui vue --auth
You can see that authentication scaffolding generated. Also, you need to run the npm install and run dev in order to make it fully functional with compiling all js and CSS files. Npm stands for Node package manager It puts modules in place so that node can find them, and manages dependency conflicts intelligently. If npm not installed in your system then first install npm:
sudo apt install npm
Just go ahead and type npm install. It will install all required dependency script automatically.
npm install
After that use npm run dev command to compile all js and css file for your application.
npm run dev
Now finaly migurate your table to database
php artisan migrate
<?php namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Jenssegers\Mongodb\Auth\User as Authenticatable; //<--- Add This Line //use Illuminate\Foundation\Auth\User as Authenticatable; //--> Commentout this line use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable;
Crate model post with model and migration
php artisan make:model Post -mc
Creating Web Routs at Routs\web.php
Route::get('/post/{slug}', 'PostController@show'); Route::post('/post', 'PostController@store'); Route::get('/displayform', 'PostController@displayForm');
Edit Post Model as below:
use Jenssegers\Mongodb\Eloquent\Model; class Post extends Model { protected $connection = 'mongodb'; }
Add following function at Post Controller:
public function displayForm(){ return view('form'); } public function show($slug){ return view('post',['post'=>Post::where('slug','=', $slug)->first()]); } public function store(Request $request){ $post = new Post; $post->title = $request->title; $post->body = $request->body; $post->slug = $request->slug; $post->save(); return response()->json(["result" => "ok"], 201); } public function destroy($postId) { $post = Post::find($postId); $post->delete(); return response()->json(["result" => "ok"], 201); } public function update(Request $request, $postId) { $post = Post::find($postId); $post->title = $request->title; $post->body = $request->body; $post->slug = $request->slug; $post->save(); return response()->json(["result" => "ok"], 201); }
Add views form and post inside resourse directory:
resource\view\form.blade.php
<!DOCTYPE html> <html> <body> <h2>HTML Forms to test mongodb</h2> {!! Form::open(['route' => 'post', 'id' => 'action_form']) !!} <label for="fname">Title:</label><br> <input type="text" id="title" name="title" ><br> <label for="lname">body:</label><br> <input type="text" id="body" name="body" ><br><br> <label for="lname">slug:</label><br> <input type="text" id="slug" name="slug" ><br><br> <input type="submit" value="Submit"> {!! Form::close() !!} <p>If you click the "Submit" button, the form-data will be sent to mongodb".</p> </body> </html>
resource\view\post.blade.php
<!DOCTYPE html> <html> <head> <title>MyBlog</title> </head> <body> <h1>{{$post->title}}</h1> <div>{{$post->body}}</div> </body> </html>
In this tutorial, we were able to connect a Laravel website to a MongoDB server. As we saw, the integration is simple and seamless.
Unlike relational databases like MySQL, you don’t need to worry about creating and maintaining database migrations. You can use the same Eloquent model functionality that you may already be familiar with. You can also take advantage of the additional querying capabilities that MongoDB provides.
The post Laravel Mongodb Integration appeared first on Tech Blog.
]]>The post How to Install PHP 8 on Ubuntu 20.04 LTS Server appeared first on Tech Blog.
]]>At the time of writing this guide, the latest version of PHP is PHP 8.0. It was released on November 26, 2020. It boasts of new features and optimizations such as union types, named arguments, null safe operator, match expression, JIT, and improvements in error handling and consistency.
By default, Ubuntu 20.04 Lts does not come with PHP 8.0 version in its default repository So, you need to add from the ondrej/php PPA repository. This tutorial is also applicable to Ubuntu 18.04.
Note: If you are going to upgrading your existing live server, Before upgrading to or installing PHP 8, make sure that your applications support it and make complete backup your existing environment to avoid any data losses.
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update
Execute the following command to install PHP 8
sudo apt install php8.0
After the installation has been completed, you can confirm the installation using the following command
php -v
Now, install the required PHP modules for your application. Use the following command to search all available PHP 8.0 modules.
sudo apt search php8.0-*
Then install the required PHP modules. The following command will install some frequently used PHP modules on your system.
sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip -y
You can choose exact extensions as per your requirement from the search list.
Apache is a popular web server widely used for deploying PHP web applications. On Debian-based systems, this is available with the name “apache2”.
An Apache module is available to integrate PHP. For PHP 8.0 install the following Apache module
sudo apt install libapache2-mod-php8.0
Then enable PHP 8 module
sudo a2enmod php8.0
There is no official PHP module for the Nginx server. In that case, we will use PHP-FPM to deploy PHP applications over Nginx web servers.
So, first, install PHP fpm on your system.
sudo apt install php8.0-fpm
Once the installation is finished, enable and start the service.
sudo systemctl enable php8.0-fpm
sudo systemctl start php8.0-fpm
Next, update the Nginx server block configuration with the following code.
server { # server block code ... location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; } }
The above code instructs the Nginx server to process all files with the “.php” extension using PHP-fpm.
Finally, restart the Nginx webserver to apply the changes.
sudo systemctl restart nginx
You can easily switch between multiple PHP versions installed on any system. Execute the following command on the terminal:
sudo update-alternatives --config php
This system has PHP 8.0 and PHP 7.4 installed. Select a PHP version on our choice.
There are 2 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.0 80 auto mode 1 /usr/bin/php7.4 74 manual mode 2 /usr/bin/php8.0 80 manual mode Press to keep the current choice[*], or type selection number: [ENTER CHOICE HERE]
To test whether the web server is configured properly for PHP processing, create a new file named info.php
inside the /var/www/html
directory with the following code:
/var/www/html/info.php
<?php
phpinfo();
Save the file, open your browser, and visit: http://your_server_ip/info.php
.
You’ll see information about your PHP configuration similar to the following:
Hope this tech article is helpfull for you while you want to install PHP 8.0 and comfortably integrate it with either Apache or Nginx web servers. Awaited your feedback because it makes us more perfect.
The post How to Install PHP 8 on Ubuntu 20.04 LTS Server appeared first on Tech Blog.
]]>The post Screen Command in Linux appeared first on Tech Blog.
]]>Have you ever faced a situation where you perform a long-running task on a remote machine, and suddenly your connection drops, the SSH session is terminated, and your work is lost. Well, it has happened to all of us at some point, hasn’t it? Luckily, there is a utility called screen that allows us to resume the sessions.
More specifically we are going to discuss the following topic:
Screen or GNU Screen is a terminal multiplexer. In other words, it means that you can start a screen session and then open any number of windows (virtual terminals) inside that session. Processes running in Screen will continue to run when their window is not visible even if you get disconnected.
it’s easy to install like anything else. It’s in the repos of every linux, so you have to do nothing special, you know, just type apt install screen. If you logged in with sudo user then use sudo before the command.
Installation of screen command: To install the screen command simply go to the terminal and type the following command:
sudo apt install screen
I have installed a screen in my system.
Syntax:
screen [-opts] [cmd [args]]
Options:
Shortcut keys Options:
Generally, to start a screen session you can simply type the screen on the terminal it will start a screen session for you. Here you can see their screen starting with some information like its version license details etc.
you can continue reading documentation by pressing the space bar or pressing the enter key to start the screen.
If you do screen -ls
then it will display all available screen sessions running in your system.
Actually screen has an option dash S. Using this you can name a screen session as you wish. For example, I am going to give it my session name “config”. ie. screen -S config
Now we reattach our running screen. So, the command is screen -R <screen ID>
. this will bring you your running screen. So every time you just need to put Screen ID after flag R.
Let’s assume that you are in a situation where you need to monitor the running process in your system while at the same time you need to keep eye on your network traffic. and the other hand you need to install some script.
And you can detach the entire screen any time and if you left the system still the process is running as usual in the background. You can resume screen any time as I earlier mentioned. And this way the screen becomes a very useful tool in Linux. So, guys hope this article is helpful to you, Thank you.
The post Screen Command in Linux appeared first on Tech Blog.
]]>The post Install and config Brotli Compression with Apache appeared first on Tech Blog.
]]>Just like Gzip, Brotli is also a generic-purpose compression algorithm developed by Google. It compresses data using a combination of modern technologies and algorithms. It is similar in speed to deflate but provides higher compression. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, Edge.
In this Article we are going to configure Brotli Compressor Mechanism with Apache Web Server.
Well, at this point we understand that Brotli can help you to speed up your heavy website, and save your bandwidth also. And eventually, it helps optimization on SEO ranking in the competition market.
We assume that you have an existing web server with Apache in order to do the experiment, and if you are in a production environment then I strongly recommend to make a backup your files before that. You can also check out this video how to setup Apache Vhost above here.
Go ahead and open terminal type :
sudo apt install brotli
So, after install Brotli, enable the module in Apache.
sudo a2enmod brotli
Now You need to restart Apache2 in order to make module effective.
sudo systemctl restart apache2
Now, open up Apache Vhost config file. go ahead and type nano /etc/apache2/site-available/<your config file>
.
Inside your config file place cursor after directory tag and put an If Module.
<VirtualHost *:80> ServerName myapp1.com ServerAdmin [email protected] DocumentRoot /var/www/html/wordpress/ <Directory /var/www/html/wordpress> Options Indexes MultiViews AllowOverride All Require all granted </Directory> /////////////////////////////// Add this config to your Vhost file //////////////////////////// <IfModule mod_brotli.c> AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript </IfModule> /////////////////////////////////////////////////////////////////////////////////////////////// ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Inside If Module add output filter type Brotli Compress, and then put your file type you want to compress. So, here is put html, css, Js etc.
After that save the configuration and exit. And again, restart the Apache service in order to make effect in your website.
sudo systemctl restart apache2
Now open up the browser and load the page in another tab, it will be bit faster than previous. You could check whether your Brotli Compressor work or not, using Curl command. So, open a local terminal and type the following command.
curl -I -H 'Accept-Encoding: br' http://myapp1.com
You can see the output that content encoding Brotli is working fine for me.
HTTP/1.1 200 OK Date: Mon, 09 Aug 2021 06:50:56 GMT Server: Apache/2.4.41 (Ubuntu) Link: <http://myapp1.com/index.php?rest_route=/>; rel="https://api.w.org/" Vary: Accept-Encoding Content-Encoding: br Content-Length: 1 Content-Type: text/html; charset=UTF-8
So, guys hope this article helpful to you, Thank you.
The post Install and config Brotli Compression with Apache appeared first on Tech Blog.
]]>