Monthly Archives: January 2020

Execute Perl/PHP scripts from the command line

Executing PHP/Perl scripts from the command line is a very easy task. Executing scripts from the command line can be very useful when troubleshooting cron jobs.

For PHP, just use the php command:

root@web [/backup]# php /home/manus/public_html/phpscript.php
I am a PHP script ... :)
root@web [/backup]#

For Perl, we will use the perl command:

root@web [/backup]# perl /home/manus/public_html/perlscript.pl
Hi
I'm a PERL script.
root@web [/backup]#

For specific command options run php -h and perl -h.

As you see, when using the commands without any options, the output will be printed on the terminal.

Share this post:

Download files from the command line in Linux

There are man times when you will have to download files from the command line. In most distributions, you have two tools – wget and curl.

wget

This a very powerful command to simply download a file. Just use wget URL to download the file to the current location:

root@web [/]# wget  https://ip.plothost.com/test
--2020-01-19 06:11:50--  https://ip.plothost.com/test
Resolving ip.plothost.com (ip.plothost.com)... 104.10.10.155
Connecting to ip.plothost.com (ip.plothost.com)|104.10.10.155|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 94371840 (90M)
Saving to: 'test'

100%[==============================================================================================================================>] 94,371,840  11.2MB/s   in 8.3s

2020-01-19 06:11:58 (10.9 MB/s) - 'test' saved [94371840/94371840]

root@web [/]#

To use a custom filename, the command is wget URL -O filename.

curl

With the curl command, you can get the file content or download a file. To get file content, use curl URL:

root@web [~]# curl https://ip.plothost.com/testfile.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>Test file PlotHost.com</TITLE>
</HEAD>


<BODY bgcolor="#EFEFEF">
Testing ...
</BODY></HTML>
root@web [~]#

To download a file, curl URL -o filename

root@web [/]# curl https://ip.plothost.com/test -o test_file
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 90.0M  100 90.0M    0     0  10.5M      0  0:00:08  0:00:08 --:--:-- 11.1M
root@web [/]#

Resources:
wget man page
curl man page

Share this post:

How to show line numbers in vi/vim?

For displaying line numbers in vi/vim we will need to set the number flag.

Necessary steps to display the line numbers in vi/vim:

1. Edit your file with vi <filename>

2. Press the : (colon sign). The sign will appear the bottom-left of your screen

3. Enter the command for setting the number flag

set number

4. Now you will see the line numbers for your file.

Line numbers in vi/vim

To hide line numbers, press : (colon) and enter:

set nonumber


Notice that the vi/vim will not save your option to display the line numbers.

To automatically display line numbers:

1. Navigate to your home directory.

2. Create a file named .exrc

3. Edit the file and add the line:

set number

From now on, the vi/vim editor will display line numbers by default.

Resources:
How to install vim
How to install nano
Show line numbers in nano

Share this post:

Download files from the command line in Windows

Probably you will not need too often to download files from the command line/PowerShell, but in case you need, we will show here how you can archive this task.

In Linux, we have two commands to download files – wget and curl. Windows OS has the curl command. The curl command came to Windows in 2008.

To get the file content from the command line/PowerShell use curl URL

C:\Users\Web>curl plothost.com/kb
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://plothost.com/kb/">here</a>.</p>
</body></html>

C:\Users\Web>

To save the file on the local disk use curl URL -o local_filename

C:\Users\Web>curl http://plothost.com/test_file -o test_file.test
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2054k  100 2054k    0     0   342k      0  0:00:06  0:00:06 --:--:--  420k

C:\Users\Web>

The -o option will output the content to a file instead of the terminal.

-o, –output Write to file instead of stdout

curl –help

To see all curl options, use curl –help.

If you are using Windows PowerShell, you can also use the Invoke-WebRequest command.

The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service. It parses the response and returns collections of links, images, and other significant HTML elements.

Invoke-WebRequest Doc

PS C:\Users\Web> Invoke-WebRequest http://plothost.com/test_file -o test_file.test
PS C:\Users\Web>

Related articles:
Download files in Linux

Resources:
Invoke-WebRequest

Share this post:

How to create phpinfo pages

Do you want to know PHP/Apache information? The easiest way is to use the phpinfo() function.

1. Log in to your control panel (cPanel, DirectAdmin, CWP etc)

2. Go to the File Manager and create a new file – phpinfo.php – in your public directory (where your site’s files are)

3. Edit this file and put the text:

<?php
phpinfo();
?>

4. Access the newly created file – https://yourdomain.com/phpinfo.php

phpinfo() output

If you are an admin you can easily create such a file for the specific user:
1. navigate to the specific directory:

cd /home/username/public_html/

2. create a phpinfo file, edit it with the vi/nano editor and add the above PHP code:

touch phpinfo.php
nano phpinfo.php

3. modify phpinfo.php file permissions:

chmod 644 phpinfo.php
chown <username>:<username> phpinfo.php

4. access the file phpinfo.php in your web browser or send the link to the client.


Notice that on some servers the phpinfo() function is disabled. In this case, you may need to use other functions like ini_get(). A simple PHP file to get the most common PHP values is here https://github.com/plothost/php-list-values

Resources:
phpinfo() help

Share this post:
Page 1 of 4
1 2 3 4