Ratkaisut pohjautuvat Tero Karvisen mainioon oppaaseen, joka löytyy täältä:
Karvinen: Build Web Interface to Database - LAMP Linux Apache MySQL PHP
Aloitin työskentelyn käynnistämällä komentokehoitteen - eli
painamalla hiiren oikeanpuoleista korvaa
ja valitsemalla painalluksen jälkeen avautuvasta
ponnahdusvalikosta "new terminal".
toimeksiannon mukaiset harjoitteet, joiden tulokset näkyvät alla.
Suoritin kaikki harjoitukseen kuuluvat tehtävät onnistuneesti. Aikaa harjoituksen tekoon kului noin 1 tunti dokumentointi mukaanluettuna.
## install httpd
[mika@nemesis ~]$ su -
Password:
[root@nemesis ~]#
[root@nemesis ~]# yum install httpd
Setting up Install Process
Setting up Repos
base 100% |=========================| 1.1 kB 00:00
updates-released 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
base : ################################################## 2852/2852
updates-re: ################################################## 945/945
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for httpd to pack into transaction set.
httpd-2.0.52-3.1.x86_64.r 100% |=========================| 58 kB 00:00
---> Package httpd.x86_64 0:2.0.52-3.1 set to be updated
--> Running transaction check
--> Processing Dependency: httpd-suexec for package: httpd
--> Processing Dependency: libapr-0.so.0()(64bit) for package: httpd
--> Processing Dependency: libaprutil-0.so.0()(64bit) for package: httpd
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for apr-util to pack into transaction set.
apr-util-0.9.4-17.x86_64. 100% |=========================| 5.2 kB 00:00
---> Package apr-util.x86_64 0:0.9.4-17 set to be updated
---> Downloading header for httpd-suexec to pack into transaction set.
httpd-suexec-2.0.52-3.1.x 100% |=========================| 18 kB 00:00
---> Package httpd-suexec.x86_64 0:2.0.52-3.1 set to be updated
---> Downloading header for apr to pack into transaction set.
apr-0.9.4-24.2.x86_64.rpm 100% |=========================| 6.9 kB 00:00
---> Package apr.x86_64 0:0.9.4-24.2 set to be updated
--> Running transaction check
Dependencies Resolved
Transaction Listing:
Install: httpd.x86_64 0:2.0.52-3.1 - updates-released
Performing the following to resolve dependencies:
Install: apr.x86_64 0:0.9.4-24.2 - updates-released
Install: apr-util.x86_64 0:0.9.4-17 - base
Install: httpd-suexec.x86_64 0:2.0.52-3.1 - updates-released
Total download size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): apr-util-0.9.4-17. 100% |=========================| 55 kB 00:00
(2/4): httpd-suexec-2.0.5 100% |=========================| 25 kB 00:00
(3/4): httpd-2.0.52-3.1.x 100% |=========================| 938 kB 00:08
(4/4): apr-0.9.4-24.2.x86 100% |=========================| 96 kB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: apr 100 % done 1/4
Installing: apr-util 100 % done 2/4
Installing: httpd 100 % done 3/4
Installing: httpd-suexec 100 % done 4/4
Installed: httpd.x86_64 0:2.0.52-3.1
Dependency Installed: apr.x86_64 0:0.9.4-24.2 apr-util.x86_64 0:0.9.4-17 httpd-suexec.x86_64 0:2.0.52-3.1
Complete!
[root@nemesis ~]#
[root@nemesis ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@nemesis ~]# chkconfig httpd on
[root@nemesis ~]#
## testasin toimiiko web server
==> avasin firefoxilla sivun http://127.0.0.1 ja sivun http://localhost
==> molemmat sivut toimivat, joten voimme todeta että httpd-palvelun asennus onnistui !!
## muokkaa testisivun sisältöä
echo "powered by linux" > /var/www/html/index.html
## salli käyttäjien luoda omia kotisivujaan
vi /etc/httpd/conf/httpd.conf
[root@nemesis conf]# vi httpd.conf
poista kommenttimerkki rivin "UserDir public_html"-edestä ja käynnistä httpd-palvelu uudestaan.
[root@nemesis conf]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
Koska ylläoleva muutos ei vielä saanut kotisivuja näkymään, piti lisäksi tehdä vielä seuraava muutos:
[root@nemesis conf]# vi httpd.conf
Etsi httpd.conf tiedostosta rivi
<Directory /home/*/public_html>
ja poista kommentit aina riviin
</Directory>
asti ja käynnistä httpd-palvelu uudestaan.
[root@nemesis conf]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@nemesis conf]#
[mika@nemesis ~]$ pwd
/home/mika
[mika@nemesis ~]$ ls
Desktop teht2 teht3 teht4.txt
[mika@nemesis ~]$ mkdir public_html
[mika@nemesis ~]$ echo "mikas testhomepage" > public_html/index.html
[mika@nemesis ~]$ chmod a+x public_html/
[mika@nemesis ~]$ chmod a+r public_html/index.html
[mika@nemesis ~]$
Tässä vaiheessa kotisivu ei vielä näkynyt, siispä testasin oikeuksien säätämistä
hiukan lisää...
Lopputulos oli, että vasta SELinuxin enforcen poistaminen auttoi asiaan ja
käyttäjän kotisivu tuli näkyviin
## Asenna PHP
[mika@nemesis ~]$ su -
Password:
[root@nemesis ~]# yum install php
Setting up Install Process
Setting up Repos
http://fedora-mirror.dkuug.dk/linux/core/3/x86_64/os/repodata/repomd.xml: [Errno 4] IOError: HTTP Error 404: Not Found
Trying other mirror.
base 100% |=========================| 1.1 kB 00:00
updates-released 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
base : ################################################## 2852/2852
updates-re: ################################################## 945/945
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php to pack into transaction set.
php-4.3.11-2.4.x86_64.rpm 100% |=========================| 20 kB 00:00
---> Package php.x86_64 0:4.3.11-2.4 set to be updated
--> Running transaction check
--> Processing Dependency: php-pear for package: php
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-pear to pack into transaction set.
php-pear-4.3.11-2.4.x86_6 100% |=========================| 34 kB 00:00
---> Package php-pear.x86_64 0:4.3.11-2.4 set to be updated
--> Running transaction check
Dependencies Resolved
Transaction Listing:
Install: php.x86_64 0:4.3.11-2.4 - updates-released
Performing the following to resolve dependencies:
Install: php-pear.x86_64 0:4.3.11-2.4 - updates-released
Total download size: 1.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): php-4.3.11-2.4.x86 100% |=========================| 1.4 MB 00:16
(2/2): php-pear-4.3.11-2. 100% |=========================| 329 kB 00:03
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-pear 100 % done 1/2
Installing: php 100 % done 2/2
Installed: php.x86_64 0:4.3.11-2.4
Dependency Installed: php-pear.x86_64 0:4.3.11-2.4
Complete!
[root@nemesis ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@nemesis ~]#
## Luo normaalina käyttäjänä php-sivu
vi public_html/hello.php
<?php echo "Hello PHP World, 2+2 is " . (2+2); ?>
:wq
==> selaimella avataan sivu http://localhost/~mika/hello.php
==> sivulla näkyy :
Hello PHP World, 2+2 is 4
## Asenna mysql ja luo mallikanta sekä taulut
[root@nemesis ~]# yum install mysql-server mysql
Setting up Install Process
Setting up Repos
base 100% |=========================| 1.1 kB 00:00
updates-released 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
base : ################################################## 2852/2852
updates-re: ################################################## 945/945
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mysql-server to pack into transaction set.
mysql-server-3.23.58-16.F 100% |=========================| 20 kB 00:00
---> Package mysql-server.x86_64 0:3.23.58-16.FC3.1 set to be updated
---> Downloading header for mysql to pack into transaction set.
mysql-3.23.58-16.FC3.1.x8 100% |=========================| 36 kB 00:00
---> Package mysql.x86_64 0:3.23.58-16.FC3.1 set to be updated
---> Downloading header for mysql to pack into transaction set.
mysql-3.23.58-16.FC3.1.i3 100% |=========================| 36 kB 00:01
---> Package mysql.i386 0:3.23.58-16.FC3.1 set to be updated
--> Running transaction check
--> Processing Dependency: perl-DBI for package: mysql
--> Processing Dependency: libreadline.so.4 for package: mysql
--> Processing Dependency: perl-DBD-MySQL for package: mysql
--> Processing Dependency: libncurses.so.5 for package: mysql
--> Processing Dependency: perl(DBI) for package: mysql
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for perl-DBD-MySQL to pack into transaction set.
perl-DBD-MySQL-2.9003-5.x 100% |=========================| 5.3 kB 00:00
---> Package perl-DBD-MySQL.x86_64 0:2.9003-5 set to be updated
---> Downloading header for ncurses to pack into transaction set.
ncurses-5.4-13.i386.rpm 100% |=========================| 273 kB 00:02
---> Package ncurses.i386 0:5.4-13 set to be updated
---> Downloading header for readline to pack into transaction set.
readline-4.3-13.i386.rpm 100% |=========================| 7.4 kB 00:00
---> Package readline.i386 0:4.3-13 set to be updated
---> Downloading header for perl-DBI to pack into transaction set.
perl-DBI-1.40-5.x86_64.rp 100% |=========================| 11 kB 00:00
---> Package perl-DBI.x86_64 0:1.40-5 set to be updated
--> Running transaction check
Dependencies Resolved
Transaction Listing:
Install: mysql.i386 0:3.23.58-16.FC3.1 - updates-released
Install: mysql.x86_64 0:3.23.58-16.FC3.1 - updates-released
Install: mysql-server.x86_64 0:3.23.58-16.FC3.1 - updates-released
Performing the following to resolve dependencies:
Install: ncurses.i386 0:5.4-13 - base
Install: perl-DBD-MySQL.x86_64 0:2.9003-5 - base
Install: perl-DBI.x86_64 0:1.40-5 - base
Install: readline.i386 0:4.3-13 - base
Total download size: 10 M
Is this ok [y/N]: y
Downloading Packages:
(1/7): mysql-server-3.23. 100% |=========================| 1.5 MB 00:52
(2/7): perl-DBD-MySQL-2.9 100% |=========================| 112 kB 00:01
(3/7): ncurses-5.4-13.i38 100% |=========================| 1.5 MB 00:14
(4/7): readline-4.3-13.i3 100% |=========================| 175 kB 00:01
(5/7): mysql-3.23.58-16.F 100% |=========================| 3.2 MB 01:54
(6/7): perl-DBI-1.40-5.x8 100% |=========================| 467 kB 00:04
(7/7): mysql-3.23.58-16.F 100% |=========================| 3.3 MB 03:15
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: perl-DBI 100 % done 1/7
Installing: readline 100 % done 2/7
Installing: ncurses 100 % done 3/7
Installing: mysql 100 % done 4/7
Installing: perl-DBD-MySQL 100 % done 5/7
Installing: mysql-server 100 % done 6/7
Installing: mysql 100 % done 7/7
Installed: mysql.i386 0:3.23.58-16.FC3.1 mysql.x86_64 0:3.23.58-16.FC3.1 mysql-server.x86_64 0:3.23.58-16.FC3.1
Dependency Installed: ncurses.i386 0:5.4-13 perl-DBD-MySQL.x86_64 0:2.9003-5 perl-DBI.x86_64 0:1.40-5 readline.i386 0:4.3-13
Complete!
[root@nemesis ~]# /etc/init.d/mysqld start
Initializing MySQL database: [ OK ]
Starting MySQL: [ OK ]
[root@nemesis ~]# chkconfig mysqld on
[root@nemesis ~]#
[root@nemesis ~]# mysqlshow
+-----------+
| Databases |
+-----------+
| mysql |
| test |
+-----------+
[root@nemesis ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 3.23.58
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use test;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> CREATE TABLE persons( name VARCHAR(50), email VARCHAR(50) );
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| persons |
+----------------+
1 row in set (0.00 sec)
mysql> desc persons;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(50) | YES | | NULL | |
| email | varchar(50) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> insert into persons values ('Matti Meikalainen','mm at-sign noaddr.inv');
Query OK, 1 row affected (0.00 sec)
mysql> select * from persons;
+-------------------+-----------------------+
| name | email |
+-------------------+-----------------------+
| Matti Meikalainen | mm at-sign noaddr.inv |
+-------------------+-----------------------+
1 row in set (0.00 sec)
mysql> insert into persons values ('Hessu Hopo','hessu.hopo at-sign duckburg.invalid');
Query OK, 1 row affected (0.00 sec)
mysql> select * from persons;
+-------------------+-------------------------------------+
| name | email |
+-------------------+-------------------------------------+
| Matti Meikalainen | mm at-sign noaddr.inv |
| Hessu Hopo | hessu.hopo at-sign duckburg.invalid |
+-------------------+-------------------------------------+
2 rows in set (0.00 sec)
mysql> quit;
Bye
[root@nemesis ~]#
## Asennetaan php-mysql moduli
[root@nemesis ~]# yum install php-mysql
Setting up Install Process
Setting up Repos
base 100% |=========================| 1.1 kB 00:00
updates-released 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
base : ################################################## 2852/2852
updates-re: ################################################## 945/945
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-mysql to pack into transaction set.
php-mysql-4.3.11-2.4.x86_ 100% |=========================| 16 kB 00:00
---> Package php-mysql.x86_64 0:4.3.11-2.4 set to be updated
--> Running transaction check
Dependencies Resolved
Transaction Listing:
Install: php-mysql.x86_64 0:4.3.11-2.4 - updates-released
Total download size: 35 k
Is this ok [y/N]: y
Downloading Packages:
(1/1): php-mysql-4.3.11-2 100% |=========================| 35 kB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-mysql 100 % done 1/1
Installed: php-mysql.x86_64 0:4.3.11-2.4
Complete!
[root@nemesis ~]#
[root@nemesis ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@nemesis ~]#
## Luodaan testisivu database.php käyttäjän kotihakemistoon
[mika@nemesis ~]$ cd public_html/
[mika@nemesis public_html]$ ls
hello.php index.html
[mika@nemesis public_html]$ vi database.php
ja kokeillaan miltä www-sivu database.php näyttää...
PHP database example - http://iki.fi/karvinen.
Connected successfully
Matti Meikalainen mm at-sign noaddr.inv
Hessu Hopo hessu.hopo at-sign duckburg.invalid
==> kaikki toimii kuten pitääkin ;)
Mika
Karjalainen / a0300187
Copyright (c) 2005 Mika Karjalainen.
Permission is granted to copy,
distribute and/or modify this document under the terms of the GNU Free
Documentation License, Version 1.2 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no
Back-Cover Texts.