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

waisttherapeuticΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

122 εμφανίσεις

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.

MySq
l

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 la
nguage (e.g. ASP, JavaScript)

with Bourne Shell type syntax.

PERL

started 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
-
con
fig
-
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.conf

is 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


S
tart the mysql daemon,

> /etc/init.d/mysqld start


then type

mysql


>
mysql


Chang
e the M
ySQL Root Password
,
th
e

default the root passwor
d
fo
r t
he
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 n
ew 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 Pass
word=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
ph
p
-
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:

C
reate a file named /var/www/html/test.php with the following phpinfo() function inside php quotes.


// test.php


<?p
hp


phpinfo();


?>


P
oint your browser to

http://ip.address/test.php


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:

http://ip.address/phpmyadmin


Common Errors
:
y
ou might encounter the following errors while conf
iguring phpmyadmin.


Forbidden
:
You don’t have permission to access /phpmyadmin/ on this server.

Edit the

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

and uncomment the line deny from all


vi

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

Order Deny,Allow

# Deny from all

Allow fr
om 127.0.0.1


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

Edit the
/usr/share/phpmyadmin/conf.inc.php

and specify any non
-
null password
:


vi

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

$cfg['blowfish_secret'] = 'mydemopass'; /* YO
U 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 free

server hosting

co
ntrol 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 th
e following location
and install

in
the
server.


w
get

http://prdownloads.sourceforge.net/webadmin/webmin
-
1.540
-
1.noarch.rpm

rpm
-

i webmin
-
1.410
-
1.noarch.rpm


webmin uses

port 10000 and should not be blocked by firewall.


Point your browser to:

http://ip.address:10000


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 usi
ng 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 UR
L
, http://192.168.1.100/cgi
-
bin/test/test.cgi
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>

);