1. Introduction
This document introduces how to build a LAMP Server .
LAMP means Linux ,Apache,MySQL and PHP.
2. Environment
2.1 System environment
>> cat /etc/issue
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
3. Initial Steps
3.1 Log in as root
>> su – root
3.2 Remove RPM Versions of the Applications
3.2.1 To find out what PRMs are already installed
>> rpm -qa | grep -i apache
>> rpm -qa | grep -i httpd
>> rpm -qa | grep -i php
>> rpm -qa | grep -i mysql
3.2.2 To remove the RPMs generated by these commands
>> rpm -e filename
3.3 Prepare the Source Code for all applications
3.3.1 We want to put all our source code someplace central.
>> mkdir /usr/local/mytools
>> mkdir /usr/local/mytools/src
3.3.2 Download the source
Php 5.2.5: http://www.php.net/downloads.php
Httpd-2.2.8 http://apache.oregonstate.edu/httpd/
MySQL-5.0.51a http://dev.mysql.com/downloads/mysql/5.0.html#source
3.3.3 Unpack the source code
>> tar zxf httpd-2.2.8.tar.gz
>> tar zxf mysql-5.0.51a.tar.gz
>> tar zxf php-5.2.5.tar.gz
3.3.4 We want to install all our applications someplace central
>> mkdir /usr/local/mytools/repository
3.4 MySQL
3.4.1 Make a user and group for MySQL
>> groupadd mysql
>> useradd –g mysql –d /xxx/mysql mysql
3.4.2 Build and install
>> cd /usr/local/mytools/src/mysql-5.0.51a
>> chown -R root.root *
>> ./configure --prefix=/usr/local/mytools/repository/mysql-5.0.51a /
--localstatedir=/usr/local/mytools/repository/mysql-5.0.51a/data /
--with-mysqld-user=mysql /
--with-unix-socket-path=/usr/local/mytools/repository/mysql-5.0.51a/tmp/mysql.sock
>> make
>> make install
3.4.3 Configure
First run the script which actually sets up MySQL’s internal database:
>> /usr/local/mytools/src/mysql-5.0.51a/scripts/mysql_install_db
>> chown -R root.mysql /usr/local/mytools/repository/mysql-5.0.51a
>> chown -R mysql.mysql /usr/local/mytools/repository/mysql-5.0.51a/data/
>> cp /usr/local/mytools/src/mysql-5.0.51a/support-files/my-medium.cnf /etc/my.cnf
>> chown root:sys /etc/my.cnf
>> chown 644 /etc/my.cnf
>> cp /usr/local/mytools/src/mysql-5.0.51a/support-files/mysql.server /
/etc/rc.d/init.d/mysql
>> chmod +x /etc/rc.d/init.d/mysql
>> /sbin/chkconfig --level 3 mysql on
>> /etc/rc.d/init.d/mysql start
3.4.4 Test
>> /usr/local/mytools/repository/mysql-5.0.51a/bin/mysqladmin -u root password new-password
>> /usr/local/mytools/repository/mysql-5.0.51a/bin/mysqladmin -u root -p version
>> /usr/local/mytools/repository/mysql-5.0.51a/bin/mysql -u root -p
mysql> use mysql;
mysql> show tables;
3.5 Build and Install Apache
>> cd /usr/local/mytools/src/httpd-2.2.8
>> chown -R root.root *
>> ./configure --prefix=/usr/local/mytools/repository/httpd-2.2.8 -enable-module=so
>> make
>> make install
3.6 Build and Install PHP
>> cd /usr/local/mytools/src/php-5.2.5
>> chown -R root.root *
>> ./configure –prefix=/usr/local/mytools/repository/php-5.2.5 /
--with-mysql=/usr/local/mytools/repository/mysql-5.0.51a /
--with-apxs2=/usr/local/mytools/repository/httpd-2.2.8/bin/apxs
>> make
>> make install
>> cp php.ini-dist /usr/local/mytools/repository/php-5.2.5/lib/php.ini
Keep config files all together in /etc.
>> ln -s /usr/local/mytools/repository/php-5.2.5/lib/php.ini /etc/php.ini
3.7 Edit the Apache Configuration File(httpd.conf)
>> mkdir /usr/local/www
>> groupadd httpd
>> useradd - g httpd - d /xxx/ httpd httpd
>> chmod 777 /usr/local/www
>> chown httpd.httpd /usr/local/www
>> ln -s /usr/local/mytools/repository/httpd-2.2.8/conf/httpd.conf /etc/httpd.conf
>> vi /etc/httpd.conf
Add:
AddType application/x-httpd-php .php .htm .html
AddType application/x-httpd-php-source .phps
ServerName 172.24.61.58:80
Add “index.php”:
<IfModule dir_module>
DirectoryIndex index.html index.php index.html
</IfModule>
change:
DocumentRoot "/usr/local/www"
<Directory "/usr/local/www">
User httpd
Group httpd
3.8 Start Apache
>> ln -s /usr/local/mytools/repository/httpd-2.2.8/bin/apachectl /etc/rc.d/init.d/apache
>> ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache
>> /etc/rc.d/init.d/apache start
3.9 Advance
3.9.1 Stow
Download:
stow-1.3.3.tar.gz http://www.gnu.org/order/ftp.html
>> cd /usr/local/mytools/src
>> tar zxf stow-1.3.3.tar.gz
>> cd /usr/local/mytools/src/stow-1.3.3
>> ./configure –prefix=/usr/local/mytools/repository/stow-1.3.3
>> make clean
>> make
>> make install
>> cd /usr/local/mytools/repository
>> ./stow-1.3.3/bin/stow stow-1.3.3
>> export PATH=/usr/local/mytools/bin:$PATH
>> stow mysql-5.0.51a/
>> stow httpd-2.2.8/
>> stow php-5.2.5/
3.9.2 PhpMyAdmin
download:
phpMyAdmin-2.11.4 http://www.phpmyadmin.net/home_page/downloads.php
>> su - httpd
>> cd /usr/local/www
>> tar zxf phpMyAdmin-2.11.4-all-languages.tar.gz
>> cp config.sample.inc.php config.inc.php
>> vi config.inc.php
Write a string here:
$cfg['blowfish_secret'] = 'ehasofheuoi';
3.10 MySQL Synchronization
Suppose there are two Mysql servers, the database name is gisus_cxu:
172.24.61.58 (master)
172.24.61.134 (slave)
3.10.1 Edit /etc/my.cnf of Master
Add:
log-bin=mysql-bin
server-id = 1
slave-skip-errors=all
innodb_flush_log_at_trx_commit=1
sync_binlog=1
3.10.2 Edit /etc/my.cnf of Slave
Add:
server-id = 2
master-host = 172.24.61.58
log-bin
binlog-do-db=gisus_cxu
master-user = root
master-password = 'xxxx'
master-port = 3306
master-connect-retry = 10
replicate-do-db = gisus_cxu
replicate-ignore-table = gisus_cxu.authorization
log-slave-updates
slave-skip-errors=all
3.10.3 Allow Slave to connect to the Master mysql server
Go to Master server.
>> mysql -u root -p
>> GRANT REPLICATION SLAVE ON *.* TO 'root'@'172.24.61.134' IDENTIFIED BY '123456';
3.10.4 Restart the service of Master and Slave
>> mysqladmin -u root -p shutdown
>> mysqld_safe --user=root &
3.10.5 Test Command
mysql> show slave status/G ;
You can get:
Slave_IO_State: Waiting for master to send event
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
3.11 Setup Rsync
Suppose sync the data from 172.24.61.58 to 172.24.61.134.
3.11.1 Generate the keys in 172.24.61.134
>> su -
>> mkdir /root/.ssh
>> cd /root/.ssh
>> ssh_keygen -d (don’t enter the password)
There will generate two files: id_dsa, id_dsa.pub .
3.11.2 Transfer id_dsa.pub to 172.24.61.58
>> scp id_dsa.pub 172.24.61.58:/root/.ssh/authorized_keys
3.11.3 Test
>> ssh 172.24.61.58
If no need to enter the password, then test is ok.
3.11.4 Create crontab
>> vi rsync
rsync -avlR --delete -e ssh 172.24.61.58:/rsync_data /rsync_data
>> contrab -e
Add:
1-59 * * * * /rsync