Linux + Apache + MySQL + PHP/Perl (LAMP Server)

LAMP servers are common website configurations using LINUX, Apache webserver, MySQL database supported by PHP imbedded page scripting and/or PERL CGI scripting.

Apache is an Open Source web server.

MySql is (was) the Open Source relational database from Sun Corp (Solaris, Java, Openffice) that served as low-end competition for Oracle and Microsoft SQL databases; now owned by Oracle (yikes!).

PHP is a Server Side HTML dynamic content imbedded scripting language (e.g. ASP, JavaScript) with Bourne Shell type syntax.

PERLstarted as a UNIX sysadmin scripting language; later evolving into one of the primary CGI scripting languages.

HowTO:

Install Apache

yum install httpd httpd-tools httpd-devel system-config-httpd

Notes: httpd-devel libraries are required to compile and install other modules from the source.

Debian / Ubuntu apt-get uses binaries name “apache”.

/etc/httpd/conf/httpd.confis the Apache configuration file location (See the Apache web page)

Start Apache.

/etc/init.d/httpd start

Install MySQL Database Server

yum install mysql mysql-server mysql-libs

Start the mysql daemon,

> /etc/init.d/mysqld start

then type “mysql”

mysql

Change the MySQL Root Password, thedefault the root password for the for mysql database.

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;

once done, check by logging in

> mysql -u root -p
Enter Password:

Create a new MySQL User: To create a new mysql user ‘guest’ with ‘all privileges’ on database ‘demo’

mysql –u root –p –e ‘create database demo’
mysql –u root –p

mysql >GRANT ALL PRIVILEGES ON demo.* TO 'guest'@'localhost' IDENTIFIED BY 'guest'\

WITH GRANT OPTION;
mysql> UPDATE user SET Password=PASSWORD('guest') WHERE user='guest';

The MySql root password is also used with phpmyadmin

LAMP Server

Install PHP Scripting Language

with necessary modules configured for both apache and mysql environment.

yum install php php-mysql php-pear php-common php-gd php-mbstring php-mcrypt php-xml php-cli php-devel

Restart the apache to load php.

/etc/init.d/httpd restart

Test PHP: Create a file named /var/www/html/test.php with the following phpinfo() function inside php quotes.

// test.php

<?php

phpinfo();

?>

Point your browser to

Install phpMyAdmin

phpMyAdmin is a free web based MySQL database Administration Tool. Without phpMyAdmin it is almost impossible to mysql db operations in the command line. phpMyAdmin has become so convenient and it is absolutely sought by most webmasters to be present along with mysql server.

yum install phpmyadmin

Point your browser to:

Common Errors: you might encounter the following errors while configuring phpmyadmin.

Forbidden: You don’t have permission to access /phpmyadmin/ on this server.
Edit the/etc/httpd/conf.d/phpmyadmin.confand uncomment the line deny from all

vi /etc/httpd/conf.d/phpmyadmin.conf

Order Deny,Allow
# Deny from all
Allow from 127.0.0.1

Error: The configuration file now needs a secret passphrase (blowfish_secret)

Edit the /usr/share/phpmyadmin/conf.inc.phpand specify any non-null password:

vi /usr/share/phpmyadmin/conf.inc.php

$cfg['blowfish_secret'] = 'mydemopass'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Login the phpmyadmin with mysql root password we changed while installing the mysql database.

LAMP Server

Install Webmin (Optional)

Webmin a freeserver hostingcontrol panel for linux servers. It is a web based hosting administration tool and can be handy to tweak settings in your server if you are beginner to linux! You can download webmin here. webmin cannot be installed using yum, download a RPM package from the following location and installin the server.

wget
rpm - i webmin-1.410-1.noarch.rpm

webmin uses port 10000 and should not be blocked by firewall.

Point your browser to:

You should see a webmin login. But we dont know the login and password yet! To setup webmin password run the script below…

/usr/libexec/webmin/changepass.pl /etc/webmin admin

login with admin username and new webmin password!
To uninstall webmin, just run/etc/webmin/uninstall.sh

Final Steps

We want the apache and mysql to be loaded every boot so we switch them on using chkconfig

> chkconfig httpd on
> chkconfig mysqld on

Common Gateway Interface (CGI) with PERL

Apache can trigger the execution of programs theu the Common Gateway Interface (CGI) scripts. CGI scripts can be written in a variety of languages, including PERL and PHP, and can be used to do such things as generate new Web page output or update data files. A Web page's Submit button usually invokes the CGI program. By default, Apache CGI scripts are placed in the /var/www/cgi-bin/ directory as defined by the ScriptAlias directive in the httpd.conf file:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

In the default case, any URL with the string /cgi-bin/ will trigger Apache to search for an equivalent executable file in this directory. So, for example, the URL, actually executes the script file /var/www/cgi-bin/test/test.cgi. In the example case, the PERL script test.cgi placed in /test/was created to display the word "Success" on the screen of your Web browser.

#!/usr/bin/perl

# CGI Script "test.cgi"

print qq(

<html>

<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html">

<title>Linux Home Networking</title>

</head>

<body>

Success!

</body>

</html>

);