Latest LAMP Interview Questions
1. Please state how to submit a form without using a Submit button ?
We can submit a form without using a submit button by having a JavaScript code linked to any event trigger of a form field. And just add the code document.form.submit() function to submit the form when the event is triggered.
2. State the main difference between mysql_fetch_array and mysql_fetch_object ?
Mysql_fetch_array will fetch all the matching records, whereas mysql_fetch_object will only fetch the first record that matches the query.
3. State the main difference between $message and $$message ?
$message is a name of a variable, whereas $$message is a variable with its name stored inside $message.
For example if $message=”var”, then $$message is the same as $var
4. State the main difference between require and include, include_once ?
The main difference is that when using require, it will throw a fatal error when a file is not found, whereas include and include_once will show a warning and continue to load the page.
5. What is the difference between the functions unlink and unset?
The Unlink() function deletes the file whereas Unset() makes a set variable as undefined.
6. How you will define a Session ?
A Session is a method to store some data to be used across multiple pages. In technical terms it is a logical object that is stored in the server to help you store data and can be accessed across multiple HTTP requests. Session is always temporary based on the session timeout set in your Apache Server.
7. How do you register the variables into a session ?
To register variables in a session, you need to use the session_register() function
Ex: session_register($login_id)
8. How you will find the number of elements present in an array ?
To find the no. of elements in an array, you can either use count() or sizeof() function
Ex: count($array) or sizeof($array).
9. Can you encrypt your password in PHP and how to do it ?
Yes, you can encrypt passwords and all kinds of data in PHP using md5() or sha() functions.
10. What is a trigger and does MySQL support triggers ?
A trigger is a database object that is associated with a particular table in a database. It gets activated automatically and performs when either INSERT, UPDATE, DELETE action occurs on the table.
MySQL supports triggers from MySQL 5.0.2 version.
11. State the main difference between mysql_connect and mysql_pconnect ?
With mysql_connect, you open a database connection each time when the page loads, whereas with mysql_pconnect, connection gets established only once and provides access to the database across multiple requests.
12. How to repair a table in MySQL ?
To repair a table in MySQL you need to use the following query:
REPAIR TABLE {table name}
REPAIR TABLE {table name} QUICK / EXTENDED
MySQL will do a repair of only the index tree, If QUICK is given
MySQL will create index row by row, If EXTENDED is given.
13. Is PHP a case sensitive programming language ?
It is partially case sensitive, where we can use function and class names in case sensitive manner but variables need to be used in a case sensitive manner.
14. How can one handle loops in PHP ?
In PHP, you the looping statements like while, do while, for and for each.
15. Can you execute a PHP script in command line ?
Yes, we can execute a PHP script in command line with the following command line argument
# php yourscript.php
Where php is the command to execute the php script in a Command Line Interface (CLI)
16. What is nl2br() ?
nl2br() function inserts HTML line breaks before each newline in a string.
For example nl2br(“How are you”) will return strings added with HTML line breaks before all new lines in a string, and the output will be like:
How
are
you
17. How can we encrypt and decrypt a data present in a mysql table using mysql ?
To encrypt data in a mysql table, you can use the following: AES_ENCRYPT () and AES_DECRYPT ()
18. What are the types of errors in PHP and explain each one of them ?
The types of errors in PHP are Notices, Warnings & Fatal Errors.
Notices are less important errors that you don’t want to give much importance to it. Like errors that occur, when you try to access a variable that is not defined. If you change the notice errors to be not displayed, you won’t see these kinds of errors at all.
Warnings are errors of some serious nature that demand your attention. Even though these errors are displayed to the user, the script will not terminated. Example of this error includes accessing a file that doesn’t exist.
Fatal Errors are mission critical errors that result in immediate termination of your script. Examples of these errors include, calling an object of a non-existent class etc.
19. What is htmlentities and what is their functionality ?
Htmlentities() just converts the characters into HTML entities.
20. What is urlencode() and urldecode() ?
urlencode() converts special characters into characters that are safe to be used in URL’s. Mostly they are converted into % signs along with 2 hex digits.
For ex: urlencode(“20:00%) is converted into “25%2E00%25?”
urldecode() does the opposite and returns the decoded string..
21. What php image functions do you use to get the properties of an image ?
There are various php images functions that deals with images and you can use:
exif_imagetype() – To get the type of the image
getimagesize() – To get the size of the image
imagesx() – To get the width of the image
imagesy() – To get the height of the image
22. Can you increase the execution time of a php script ?
Yes, we can use the max_execution_time variable to set the desired time you needed for executing a php script.
23. Can you increase the maximum upload size in PHP ?
Yes, we can use the upload_max_filesize variable to change the maximum size of a file you can upload.
24. Please state how can you take a backup of the whole database in mysql ?
You can use the command line utility to take a backup of all the mysql table or a specific mysql table easily with the following:
mysqldump –-user [user_name] –-password=[password] [database_name] > [dump_file_name]
25. How to destroy a session variable ?
Session_unregister() Unregister a global variable from the current session
26. How can we unset the variable of a session ?
With the session_unset($variable_name) function, one can clear the session variable.
27. How to destroy a cookie ?
You just need to set the cookie to a previous date or time.
28. Please explain what is wrong with this query “Select * from table_name” ?
You should never select all columns of a table unless needed and specify the columns only required in the query. The reason is that it will use a lot of memory to fetch the data, if the records are huge, when you are going to use only 2 or 3 fields from the table.
29. What is SQL Injection and how do you deal with that ?
SQL injection is a technique utilized by hackers to get access into your database by using malicious SQL statements. Using this, anyone can gain complete access to your database without any authorization or permission.
To start with one need to use mysql_real_escape_string() to filter the user input data, before passing onto the sql statement.
30. Please explain the output of the code provided below and explain the reasoning ?
$a = 012; echo $a / 4;
The answer is 2.5.
In PHP, whenever a number is prefixed with 0, it will be considered as an octal number, and hence the 012 octal number is equivalent to the decimal number 10, and so 10/4 is 2.5
Why LAMP?
A. only professionals can work with other alternatives
B. there are no alternative
C. it’s flexible, productive, widespread and low cost (all components can be downloaded for free from Internet)
D. all servers work under Linux
Ans: C
What is SESSION in PHP?
A. a record in config file
B. a file in the cloud
C. a text file
Ans: C
What has a higher priority: a record from the hosts file or a record from the DNS-server?
A. a record from the hosts file
B. nothing
C. both
D. a record from the DNS-server
Ans: A
Which of the following are VALID SELinux (Security Enhanced Linux) security policies?
A. httpd_enable_cgi
B. httpd_enable_homedirs
C. httpd_ssi_exec
D. All of the options are valid
Ans: D
Which of the following is NOT a main apache directory?
A. logs
B. conf
C. htdocs
D. apps
Ans: D
Which of the following represents root directory?
A. “\”
B. “/”
C. “\*”
D. “*/”
Ans: B
Which PHP extension is required for work with MySQL?
A. php_msql
B. php_my_sql
C. php_db
D. php_mysql
Ans: D
An alternate name for a host is…
A. AlternatePath
B. AnotherServer
C. ServerAlias
D. SecondServer
Ans: C
What is HTTP?
A. nothing
B. Home Television Transfer Protocol
C. HyperThreading Transfer Protocol
D. Hypertext Transfer Protocol
Ans: D
What is the name of a superuser in Linux?
A. admin
B. administrator
C. linus
D. root
Ans: D
The name of a web-based interface for work with databases is called…
A. webDBadmin
B. myadmin
C. mysqladmin
D. phpmyadmin
Ans: D
What’s LAMP (in the most cases)?
A. Linux + ASP+MySQL +Python
B. Linux + Apache+MySQL +Python
C. Linux + Apache+MySQL +PHP
D. Linux + Apache+MySQL +Perl
Ans: C
What domain name will have the following address – 127.0.0.1?
A. localhost
B. test
C. there is no name for this address
D. home
Ans: A
What’s the name of Apache configuration file?
A. config.ini
B. httpd.conf
C. https.conf
D. config.conf
Ans: B
Are there any variations of LAMP for other platforms?
A. yes [WAMP, WIMP (for Windows), MAMP (Mac OS), BAMP (BSD)]
B. no
Ans: A
How can you block users by IP address or by domain?
A. this is impossible
B. using a .htaccess file
C. using a php.ini file
D. .htpasswd
Ans: B
What language should you use for writing a queries for database?
A. Python
B. Java
C. PHP
D. SQL
Ans: D
What is GNU Linux?
A. the name of penguin
B. programming language
C. operating system
D. the nickname of Linus Torvalds
Ans: C
You do not have to specify a length with which of the following MySQL datatypes?
A. MEDIUMBLOB
B. TINYTEXT
C. All of the options are valid
D. TINYBLOB
Ans: C
What is a superuser in mysql usually called ?
A. root
B. admin
C. mysql
D. user
Ans: A
Which of the following Linux command can be used to change file owner and group ?
A. chggrp
B. chown
C. chwn
D. chgowner
Ans: B
What will this command cp file1 file2 do?
A. Will make a copy of file1 in the current working directory and call it file2 and will delete file1
B. Will make a copy of file1 in the root directory and call it file2 and will delete file1
C. Will make a copy of file1 in the root directory and call it file2
D. Will make a copy of file1 in the current working directory and call it file2
Ans: D
What is MySQL?
A. it’s a database server
B. it’s a variation of a structured query language
C. it’s a programming language
D. it’s a PHP interpreter
Ans: A
Where hosts file (on *nix systems) is usually located?
A. /usr/etc/hosts
B. /etc/hosts
C. /var/www/hosts
D. /root/hosts
Ans: B
Which of the following apache directory has all server configuration files?
A. htdocs
B. logs
C. conf
D. cgi-bin
Ans: C
How can you start a session in PHP script?
A. session_begin()
B. sessionstart()
C. session_start()
D. start_ session()
Ans: C
Which of the following is not a valid directive of Apache Control Command (apachectl)?
A. status
B. kill
C. stop
D. start
Ans: B
What will be the output of command mysqladmin -u root -p drop TEST?
A. It will drop TEST user
B. It will drop TEST table
C. Invalid Command
D. It will drop TEST database
Ans: D
Which of the following is the main Apache configuration file?
A. /etc/srm.conf
B. /etc/apache.conf
C. /etc/httpd/conf/httpd.conf
D. /etc/httpd/config.ini
Ans: C
How to see information about PHP configuration from a script?
A. phpinfo()
B. phpconfig()
C. php_info()
D. php_config()
Ans: A
What will be the output of this command : ls list* ?
A. This will list all files in the current directory ending with list
B. This will list all files in the current directory starting with list
C. This will list all files in the root directory ending with list
D. This will list all files in the root directory starting with list
Ans: B
What does “.” (DOT) signify in Unix?
A. Root Directory
B. Current directory
C. Parent Directory
D. It is not supported
Ans: B
Which of the following Linux command can be used to change the group ownership of files ?
A. chgrp
B. chggroup
C. changegrp
D. chggrp
Ans: A
What’s the name of file, where user’s information can be stored?
A. config
B. cookie
C. biscuit
D. php.ini
Ans: B
To quote a string within a string, which of the following can you use?
A. ‘This is the quoted” message”‘
B. ‘This is the “quoted” message’
C. This is the “quoted” message
Ans: B
What does the following error “Access denied for user ‘root’@’localhost’ (using password: YES)” mean?
A. wrong password
B. wrong database name
C. wrong username
D. wrong password and username
Ans: A
Which of the following is a way to restart Apache on *nix system?
A. apache reboot
B. apache restart
C. httpd restart
D. httpd reboot
Ans: C
What’s the name of a time-based job scheduler in *nix systems?
A. shell
B. chronos
C. cron
D. crontab
Ans: C
Directive for definition a hostname is called…
A. Host
B. Hostel
C. NameOfTheHost
D. ServerName
Ans: D
What will be the ouput of this command: head -5 test.txt
A. It will create a new file with first 5 lines from test.txt
B. It will write the last 5 lines of test.txt to the screen
C. It will create a new file with last 5 lines from test.txt
D. It will write the first 5 lines of test.txt to the screen
Ans: D
Which of the following Linux command outputs the available free space in local hard-disk partitions?
A. free
B. df
C. fdisk
D. du
Ans: B
Which of the following statement tells the server to reload the grant tables?
A. RELOAD PRIVILEGES
B. FLUSH PRIVILEGES
C. UPDATE PRIVILEGES
D. REFRESH PRIVILEGES
E. RESET PRIVILEGES
Ans: B
What port does squid listen, by default?
A. 4322
B. 7334
C. 3128
D. 2314
Ans: C
What is the size limit for strings in php?
A. There is no limit (hardware limit)
B. 100Mbytes
C. 256Kbytes
D. 1024bytes
Ans: A
When will a PHP session be closed?
A. when the browser is closed
B. after a span of user inactivity
C. every 15 minutes
D. when the browser is closed or after a span of user inactivity
Ans: D
What will be the output of command mysqladmin -u root -p create TEST?
A. It will create a new user TEST
B. It will create a new database TEST
C. It will create a new table TEST
D. Invalid Command
Ans: B
Which ID always has a *nix superuser ?
A. 0
B. 10
C. 1
D. 100
Ans: A
How to use other/additional extensions/file types for PHP scripts, instead of using just .php?
A. use AddType directive in httpd.conf
B. edit the extensions in php.ini
C. None of the above
D. edit the ‘extension’ directive in php.ini
Ans: A
Which of the following is an INVALID column in user table in mysql database?
A. Truncate_priv
B. Select_priv
C. Delete_priv
D. Insert_priv
Ans: A
What will be the output of the following code?
A. None of the above
B. Nothing
C. 1
D. Syntax error
Ans: B
Which of the following Apache Control Command: apachectl directive restarts the Apache httpd daemon?
A. start
B. Both graceful and restart
C. restart
D. graceful
Ans: B
Which of the following command can be used to get the value of env variables?
A. echo
B. env
C. Both env and printenv
D. printenv
Ans: C
Are the IOT (Index Organized Tables) supported by MySQL?
A. the support will be added in the next (6) version
B. yes
C. no [it’s the Oracle’s type]
Ans: C
Where can you set up a server’s name?
A. httpd.conf
B. php.ini
C. /etc/hosts
Ans: A
Which of the following file is a MySQL configuration file?
A. /etc/conf/mysql.cnf
B. /etc/my.cnf
C. /etc/mysql.cnf
D. /etc/conf/my.cnf
Ans: B
What is the year range for MySQL datatype YEAR (2)?
A. 1970 to 2069
B. 1099 to 2099
C. 1900 to 2099
D. 1969 to 2070
Ans: A
Which of the following is TRUE about Inetd?
A. UNIX handles many of its services through the internet daemon (inetd), as opposed to a constantly running daemon
B. Inetd is a super server that listens to the various ports and handles connection requests as it receives them
C. (neither is correct)
D. (both are correct)
Ans: D
One advantage of hard links over symbolic links is:
A. A hard link can span different filesystems
B. You can determine the inode used by a hard link, but not for a symbolic link
C. A hard link allows you to change the permissions on the underlying file
D. A hard link does not become disconnected from the underlying file if the file is moved
Ans: D
In which tcp_wrappers file can you specify all connections from all hosts?
A. /etc/hosts.deny
B. /etc/tcp.conf
C. /etc/hosts
D. /etc/hosts.allow
Ans: D
The command “service httpd ______” allows users to check the syntax of Apache’s configuration files.
A. configchk
B. chkconfig
C. configtest
D. testconfig
Ans: C
Which of the following is not a VALID MySQL datatype?
A. DATE
B. DOUBLE
C. STRING
D. DATETIME
Ans: C
The SELinux (Security Enhanced Linux) security policies are enabled/disabled through which file?
A. /etc/selinux/conf.d
B. /etc/selinux/conf/httpd.conf
C. /etc/selinux/httpd.conf
D. /etc/selinux/config
Ans: D
What will happen if AUTO INCREMENT field reaches its maximum value?
A. error message will appear
B. None of the above
C. everything will start again from 1
D. everything will start again from 0
Ans: A
Who clears a session files on server?
A. garbage cleaner daemon
B. Apache
C. no one
D. PHP [Garbage Collector]
Ans: D
What is the output of the command “service httpd configtest” if no errors are found in Apache’s configuration file?
A. Syntax OK
B. *.conf files OK
C. configtest OK
D. Config OK
Ans: A
Which of the following command can be used to shutdown an already running MySQL server?
A. ./mysqladmin -u root -p kill
B. ./mysqld -u root -p shutdown
C. ./mysqladmin -u root -p shutdown
D. ./safe_mysqld -u root -p shutdown
Ans: C
Which of the following Linux command outputs the processor architecture ?
A. procarch
B. info
C. arch
D. proc
Ans: C
Which of the following Linux command can be used to output the shared library dependencies ?
A. ldd
B. libdd
C. ld
D. libd
Ans: A
Which of the following is NOT a valid unix env variable?
A. ARCH
B. HOME
C. USR
D. HOST
Ans: C
What output will be If you try to perform an arithmetic operation on a column containing NULL values?
A. None of the above
B. 0
C. Cannot be determined
D. An error will be generated
Ans: A
Which of the following commands can be used for setting attributes on files/folders?
A. setattr
B. attr
C. chmod
D. chattr
Ans: D
The default PHP session lifetime is…
A. 30 min
B. 24 min
C. there is no lifetime
D. 60 min
Ans: B
Which of the following commands will match commands with keyword(s) on their main pages?
A. head
B. whatis
C. man
D. apropos
Ans: D
At login which of the following is first read by C shell?
A. .profile
B. .cshrc
C. Both .cshrc and .login
D. .login
Ans: B
Which of the following commands can be used to set stick bit on a file?
A. chmod 2644 file
B. chmod 1645 file
C. chmod 1455 file
D. set 466 file
Ans: B
Which of the following holds environment variables used when starting Apache?
A. /etc/httpd/conf/httpd.conf
B. /etc/sysconfig/httpd
C. /etc/httpd/conf.d
D. /etc/httpd/conf.d/application.conf
Ans: B
What is the maximum allowable length of MySQL datatype VARCHAR?
A. There is no limit
B. 256
C. 1000
D. 2000
Ans: D
What is the precision limit for MySQL datatype DOUBLE?
A. 62
B. 53
C. 54
D. 59
Ans: B