ow do I read an IP address of remove system or browser using PHP server side programming language? How can I get client IP address and store it to the variable called $ip using php+apache?
Q. How do I run a shell script from a web server or a web page under Apache or Lighttpd websever?
A. In order to run a shell script from a web page you need Apache web server configured with cgi access. Apache CGI allows documents/files in cgi-bin directory treated as application and run by server when requested rather than as documents sent to the client.. It means if you put shell script in cgi-bin directory then you are able to execute them from a web page. However, you cannot simply run shell script from a web. You need to send or print the MIME type before outputting data to the web browser from shell script. You need to add following line to script before you get output back to browser:
echo "Content-type: text/html"
Here is the script that can displays today’s date and other information related to your shell script:
# get today's date
# You must add following two lines before
# outputting data to the web browser from shell
echo "Content-type: text/html"
echo "Today is $OUTPUT <br>"
echo "Current directory is $(pwd) <br>"
echo "Shell Script name is $0"
Save the script in your cgi-bin directory and execute it from web page.
=> For more examples see how to: Run Linux / UNIX commands from a web page.
Q. How Can I send html email from cgi perl program under UNIX / Linux and Apache web sever?
A. Sending HTML email is an easy task with MIME::Lite CPAN module. It is a low-calorie MIME generator.
It can be use to send html emails, graphics file email attachments as a single-part or multi-part message. Here is simple perl script that sends html email.
Install Perl MIME::Lite
If you do not have MIME::Lite module, install using following command (login as a root user):
# cpan -i MIME::Lite
Perl script code
Script to send html email from perl:
# SendTo email id
my $email = 'firstname.lastname@example.org';
# create a new MIME Lite based email
my $msg = MIME::Lite->new
Subject => "HTML email test",
From => 'YOU@somewhere.com',
To => $email,
Type => 'text/html',
Data => '<H1>Hello</H1><br>This is a test email.
Please visit our site <a href="http://cyberciti.biz/">online</a><hr>'
Save the script and execute it. Here is an email (sample) send by above script:
Read man page of MIME::Lite for more information:
am a new Linux server sysadmin. How do I protect a directory in Apache web-server on a Linux operating systems?
How do I find out Perl version by running a cgi script from a webbrowser? How do I find out perl version from a command prompt under Windows or Linux / UNIX operating systems?
The CGI is acronym for Common Gateway Interface. It is a standard for interfacing external applications with Apache Web servers. A CGI program is executed in real-time, so that it can output dynamic information. It can be written in Perl, Php, Bash, C/C++ or other programming languages. But how do I find the url for my cgi-bin? It’s not in my /var/www/ directory.
Apache web server use ScriptAlias directive defines cgi-bin directory that contain server scripts. You can use open Apache web server configuration file using text editor such as vi and look for ScriptAlias directive:
httpd.conf file location:
$ vi /etc/apache-perl/httpd.conf
Red Hat/ Fedora Core Linux:
$ vi /etc/httpd/conf/httpd.conf
$ vi /usr/local/etc/httpd.conf
You can also use grep command as follows to find out your cgi-bin directory:
$ grep 'ScriptAlias' /etc/httpd/conf/httpd.conf
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
/usr/lib/cgi-bin/ is cgi-bin directory. If you have public_htm directory then cgi-bin directory should be inside this directory. Once you located cgi-bin directory you can use it.
Default cgi-bin directory locations:
- Red Hat Linux: /var/www/cgi-bin/
- Fedora Linux: /var/www/cgi-bin/
- Debian Linux: /usr/lib/cgi-bin/
- FreeBSD: /usr/local/www/cgi-bin/
Finally your url location depends upon directory location. You can use http://ip-address/cgi-bin or http://ip-address/~yourname/cgi-bin (replace ip-address with your domain name)
MySQL is open source database server. It is reliable and widely used by web developers around the world. You can use PHP or Perl scripting to access a MySQL database. However, thousands of ready to use application available for MySQL, here is list of some of the most popular application (written in PHP [PHP (Hypertext Preprocessor) is a widely used, general-purpose scripting language that is especially suited for web development and can be embedded into HTML]):
- Guestbook software
- Forum software
- Content management system
- Blog software
- Photo Gallery
Once you are, experienced user, you may also use MySQL to create dynamic web pages or software(s) for yourself. For more information see: