3 Aug 2021

How to know all last modified files in your cPanel?

Follow the steps to know  all last modified files in your cPanel:

Step::1 Login to cPanel and open File Manager section

Step::2 Go inside your root directory i.e public_html

Step::3 Create a new php file named test.php 

Step::4 Copy the code from the below


<?php

            $edited_files = shell_exec(' find /home/cpanel_username/public_html/ -type f -mtime -2 ');

            echo "This is string : <br> <pre>$edited_files</pre>";

            //Convert to Array

            $edited_files = preg_split('/\s+/', trim($edited_files));

            echo "<pre>";

            print_r($edited_files);

            echo "</pre>";

?>

Step::5 Paste this code in the test.php file

Step::6 Finally click over Save Changes.

Step::7 Now open your browser and hit this test.php and see the result

You will be able to see the last modified files in your cPanel.


How to take mysql database backup using cron job in cpanel

1. Login into cpanel and you know the database name, user name password.

2. Go to Cpanel home page/dashboard.

3. In "ADVANCED" section click on "Cron Jobs"

4. Go to "Add New Cron Job" section

5. In "Comman Setting" select Cron Job occurrence nature

i.e. If you want to execute cron job for database backup every minute then select "Once Per Minute" option

6. /home/eduhubindia/db_`date +\%Y\%m\%d\%H\%M`.sql

a. Above is the path of output file,2nd parameter is username of cpanel, which you can find at top right of cpanel

b. Name of DB backup file is db_`date +\%Y\%m\%d\%H\%M`.sql

above code is added in file name so that timestamp can be added in dbbackup file name


7.  mysqldump -u Current User -p'Password' eduhubin_web_db > /home/cpanel-username/db_`date +\%Y\%m\%d\%H\%M`.sql

Add above command In command line


8. Click on "Add New Cron Job" button

9. Go to Cpanel home page/dashboard

10. Click on File Manager

11. Check databack file is created

14 Jun 2021

How to install NextCloud on Ubuntu 20 LTS WSL Windows 10 OS | Part -1

Requirements :

The system requirements of NextCloud are not much high even we can run it on Raspberry pi 2.

  • Linux WSL App on WIndows- Ubuntu 20.04 LTS or later version such as Ubuntu 18.04 LTS
  • WSL should be enabled on your Windows 10 system.
  • Nextcloud needs a minimum of 128MB RAM  or recommended 512MB on your Server or Desktop,


For this tutorial, we will install the following things needed by the personal cloud server application.

  • Database: MySQL 5.7+ or MariaDB 10.2 or PostgreSQL 9.5+
  • Webserver: Apache with mod_php or php-fpm or nginx with php-fpm
  • Php: 7.3+

Steps to install Nextcloud on WSL Ubuntu 20 LTS on Windows 

Step 1. Enable WSL and install Ubuntu 20.04 App

    Go to Windows 10 search and type “Turn Windows features on or off“, as it appears, click on it to run. There scroll down and check the box given for “Windows subsystem for Linux” option and click the OK button. After enabling, the setup will ask to restart the system do it.



Now, go to open Microsoft Store on Windows 10 or use this Link to download Ubuntu 20.04 LTS Linux App.

Step 2. Install Apache web server on WSL

    Now, in the Windows 10 search box, type Ubuntu and run it.

As we know installing Apache is not a Sisyphean task on Ubuntu and the same goes for Ubuntu 20.xx Linux app running on Windows subsystem for Linux. Just run the single Linux command given below:

sudo apt install apache2
Once the installation is completed, enable and check the Apache web server status. When it asks you to allow the Apache access through Windows 10 firewall, give it.

sudo service apache2 start

sudo service apache2 status


To check whether you can access the static page of Apache on Windows 10, open your browser and type: http://127.0.0.1


Step 3. Install PHP on WSL (Windows 10)

The NextCloud is a PHP-based application, thus we also need to set up it along with some extensions which are required for the proper working server-side application.

By default, the PHP version available to install on via the official repository on Ubuntu 20.04 LTS is the latest stable version i.e PHP 7.4. Thus, here is the command which you need to execute.

sudo apt install php php-common php-curl php-gd
sudo apt install php-json php-mbstring php-xml
sudo apt install php-zip
Some other Extensions for server performance including LDAP integration and external user authentication

sudo apt install php-ldap php-imap php-apcu php-memcached php-redis

If you are planning to use MySQL like we are going to do here then install its supported PHP extension:

sudo apt install php-mysql

In the same way, those who are planning to use PostgreSQL database they need this extension:

sudo apt install php-pgsql

Step 4. Download NextCloud

By the time, we are writing this article the latest version of the Nextcloud server edition available to download was 18.04, thus we get the same for installation.

Visit the Download page, right-click on the Download button and copy the link.

Now, on your Ubuntu terminal type wget give space and paste the copied link. After hitting the enter button to download the NexxtCloud latest server version.

For example:
wget https://download.nextcloud.com/server/releases/nextcloud-x.x.xzip

Step 5. Extract Downloaded zipped file

The downloaded file of our was in zipped format thus, we also need a small program for that:

sudo apt install unzip

Now,
sudo unzip nextcloud*.zip
After inflating, move the file to Apache public folder

sudo mv nextcloud /var/www/html/nextcloud/

Create a data folder inside the copied folder

sudo mkdir /var/www/html/nextcloud/data

Set the permissions for the copied Nextcloud directory


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


Step 6. Create nextCloud configuration file for Apache

By default, Apache has the configuration file that points it to use the files available under /var/www/html folder, we can edit that file to point it to our nextcloud directory inside the HTML folder. However, it is a better idea to create a separate configuration file, in case you are planning to host multiple websites.

sudo nano /etc/apache2/sites-available/nextcloud.conf
Copy-paste the following lines in that file.

Note: If you are want to use a custom domain then replaced your.server.com in the following with your domain name and update the DNS record for the same.


<VirtualHost *:80>
ServerAdmin localhost
DocumentRoot /var/www/html/nextcloud/

ServerName example.com
ServerAlias www.example.sam

<Directory /var/www/html/nextcloud/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


To save and exit the above nano editor, first press CTRL+O and then CTRL+X.


Enable the newly created site:

sudo service apache2 reload
sudo a2ensite nextcloud.conf

Enable Apache Modules for Nextcloud
    However, in most of the cases the following modules will automatically get enabled, yet to confirm run the below command:


sudo a2enmod rewrite headers env dir setenvif mime

 

Step 7. Restart Apache

By default, Apache has the configuration file that points it to use the
sudo service apache2 stop
sudo service apache2 start


Step 8. Login Nextcloud

    Finally, enter the username and password you want to register as an ADMIN account for NextCloud and then furnish the Database details. Last, click on the Finish Setup.

Change Data Folder (Optional step)
By Default, whatever data we upload to NextCloud will go to its data folder that is at /var/www/html/nextcloud/data, it is in the root directory; so, Ubuntu WSL is in the C drive of Windows 10, therefore NextCloud will consume your C: Drive to store all the uploaded files. However, we can change that.

Here, I am going to move the data folder from my C: Drive to G: Drive of the system, so that, all the uploaded files will consume my G: Drive Space, and C: drive will remain free.


Open File Explorer.

Type \\wsl$ in the address bar.


Continue to Part-2........







11 Jan 2020

How to generate a PDF in laravel | TCPDF in laravel

Use composer:

 composer require elibyy/tcpdf-laravel

Or use package

Requirements

To use TCPDF in Laravel, we are going to include the tcpdf-laravel package in our project. You can add the package to your project adding the following line in your composer.json file :
 {
    "require": {
        "elibyy/tcpdf-laravel": "5.2.*"
    }
}

Implementation

Now that the library is included in your project, you need to enable it in your service provider.

Go to your app.php file (yourapp/config/app.php) and add the Laravel TCPDF service provider :

'providers' => [
    //...
    Elibyy\TCPDF\ServiceProvider::class,
]



Using TCPDF with an alias
You can define an alias (whatever you want) for TCPDF to prevent the direct declaration of a new class element and use the TCPDF::Method syntax without instantiation.

Go to your app.php file (yourapp/config/app.php) and add the alias for the class :

'aliases' => [
    //...
    'PDF' => Elibyy\TCPDF\Facades\TCPDF::class
]


Now, TCPDF has an alias as PDF and you'll be able to generate PDF's in your controller using :

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use PDF;
class DefaultController extends Controller
{
    public function index()
    {
        $html = '<h1>Hello World</h1>';
     
        PDF::SetTitle('Hello World');
        PDF::AddPage();
        PDF::writeHTML($html, true, false, true, false, '');
        PDF::Output('hello_world.pdf');
    }
}




Is a good practice to handle the HTML content in a view instead of manipulate it manually in the controller.

You can draw your PDF content as html in a template, retrieve the html generated by the view and write into the PDF :

<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Elibyy\TCPDF\Facades\TCPDF;
class DefaultController extends Controller
{
    public function index()
    {
        $view = \View::make('myview_name');
        $html = $view->render();
     
        $pdf = new TCPDF();
        $pdf::SetTitle('Hello World');
        $pdf::AddPage();
        $pdf::writeHTML($html, true, false, true, false, '');
        $pdf::Output('hello_world.pdf');
    }
}

21 Oct 2019

how to add custom field in custom post type wordpress

This is the hardest of the lot. It’s not really hard though, just alot of HTML to make the meta boxes. You can put any HTML you like in meta boxes, I just like to keep mine looking like standard WP fields:


<?php
/**
 * Add cafe custom fields
 */
function add_cafe_meta_boxes() {
 add_meta_box("cafe_contact_meta", "Contact Details", "add_contact_details_cafe_meta_box", "cafes", "normal", "low");
}
function add_contact_details_cafe_meta_box()
{
 global $post;
 $custom = get_post_custom( $post->ID );
 
 ?>
 <style>.width99 {width:99%;}</style>
 <p>
  <label>Address:</label><br />
  <textarea rows="5" name="address" class="width99"><?= @$custom["address"][0] ?></textarea>
 </p>
 <p>
  <label>Website:</label><br />
  <input type="text" name="website" value="<?= @$custom["website"][0] ?>" class="width99" />
 </p>
 <p>
  <label>Phone:</label><br />
  <input type="text" name="phone" value="<?= @$custom["phone"][0] ?>" class="width99" />
 </p>
 <?php
}
/**
 * Save custom field data when creating/updating posts
 */
function save_cafe_custom_fields(){
  global $post;
 
  if ( $post )
  {
    update_post_meta($post->ID, "address", @$_POST["address"]);
    update_post_meta($post->ID, "website", @$_POST["website"]);
    update_post_meta($post->ID, "phone", @$_POST["phone"]);
  }
}
add_action( 'admin_init', 'add_cafe_meta_boxes' );
add_action( 'save_post', 'save_cafe_custom_fields' );


Custom Templates

You may want your new post type to look different from standard posts. This can be done using custom templates. The WordPress codex cover custom post type templates nicely but I’ll quickly go over what I did for completeness. I’m using twentytwelve theme in my demo but this should apply for most themes.
  1. Duplicate single.php into single-<post type>.php
  2. Replace
    <?php get_template_part( 'content', get_post_format() ); ?>
    with
    <?php get_template_part( 'content', '<post type>' ); ?>
  3. Duplicate content.php into content-<post type>.php and modify however you like




Reference Links: