LAMP Knowledge

apache work with php:
1. cgi(too old)
2. fastcgi (socket)
3. module

php work with mysql: mysql driver / protocol through 3306 port

L: Linux
A: Apache
M: Mysql
P: Php

Program: command + data

Whole process: client --> index.php / http --> apache (httpd) --> fastcgi php web sever --> mysql client / drive --> mysql (script) --> mysql database

Website infrastructure:
2003 taobao lamp in one server -->after half year,  la in one server; p in one server; m in one server

module: lap + m / lamp
fastcgi: la + m + p / lam + p / lap +m / lamp

yum install lamp (module) + wordpress
php only can work in perfork mode
1. yum install httpd
2. yum install php
3. create php page
<html>
    <body>
        <?php
            phpinfo();
        ?>
    </body>
</html>
4. yum install mysql
5. yum install mysql-server
6. /usr/bin/mysql_secure_installation
7. yum install php-mysql
8. Upload wordpress to /var/www/html
9. unzip the file
10. login mysql create wordpress database
11. mv wp-config-sample.php wp-config.php
12. visit http://192.168.192.128/wordpress and input mysql information

binary install lamp + fastcgi 
httpd2.2: by default no fastcgi module; 
httpd2.4: by default has fastcgi module: mod_proxy_fcgi;

One server: httpd / mysql / php 
1. yum install gcc pcre-devel openssl-devel

2. tar xvf apr-1.5.0.tar.bz2
./configure --prefix=/usr/local/apr
make && make install

3. tar xvf apr-util-1.5.3.tar.bz2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

4. tar xvf httpd-2.4.9.tar.bz2
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install

5. Install mysql
tar  xf  mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mariadb-5.5.36-linux-x86_64  mysql

bin  二进制程序
data  数据存放目录
scripts/mysql_install_db   mysql初始化脚本
support-file    样例文件
其中国有样例配置文件,但是提供了不同的版本
huge  海量内存
large  服务器硬件叫充分
small  较少的内存
mysql.server  服务脚本

groupadd  -r  mysql
useradd -g mysql -r mysql 
mkdir -p /mydatad/data
chown -R mysql:mysql  /mydata/data

cd /usr/local/mysql
scripts/mysql_install_db --datadir=/mydata/data  --user=mysql  
mkdir /etc/mysql
cp  support-file/my-large.cnf  /etc/mysql/my.cnf

vim /etc/mysql/my.cnf
add: datadir=/mydata/data

cp support-file/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
service mysqld start

vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/mysql.sh

6. Install PHP
yum install libxml2-devel  libmcrypt-devel(epel源中)  bzip2-devel
tar  xf php-5.4.26
./configure --prefix=/usr/local/php  --with-mysql=/usr/local/mysql  --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config  --enable-mbstring  --with-freetype-dir --with-jpeg-dir --with-png-dir  --with-zlib  --with-libxml-dir=/usr  --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php/php.d/
make && make  install

7. PHP Config:
php的配置文件:php.ini
php的守护进程配置文件:fpm.conf

mkdir -pv /etc/php/php.d
cd /tmp/php-5.4.25
cp php.ini-production /etc/php/php.ini
cp sapi/fpm/init.d.php-fpm   /etc/rc.d/init.d/php-fpm
cd /usr/local/php/etc
mv php-fpm.conf.default php-fpm.conf
cd /etc/rc.d/init.d
chmod +x php-fpm
chkconfig --add php-fpm

vim /usr/local/php/etc/php-fpm.conf
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1

8. httpd Config:
vim  /etc/httpd/httpd.conf
LoadModule proxy_module  modeles/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 

AddType  application/x-httpd-php  .php
AddType  application/x-httpd-php-source  .phps

关闭正向代理
ProxyRequests Off 
ProxyPassMatch ^/(.*\.php)$  fcgi://127.0.0.1:9000/usr/local/httpd/htdocs/$1

9. Test php
index.php
<?php
    phpinfo();
?>

conn.php
<?php
        $conn = mysql_connect ('127.0.0.1','root','123456');
        if ($conn)
                echo "succ";
        else
                echo "faiure";

        mysql_close();
?>

10. install wordpress
unzip wordpress...
mv wordpress /usr/local/httpd/htdocs

create wordpress databsae in mysql

vim /etc/httpd/httpd.conf

Change from 
DirectoryIndex index.html
to 

DirectoryIndex index.html index.php


cd /usr/local/httpd/htdocs
mv wp-config-sample.php wp-config.php

Three server installation
Server 1(Apache): httpd + apr + apr_util
Server 2(php): php + php-mysql + fastcgi
Server 3(Mysql): mysql-server

Server 1
1. yum install gcc pcre-devel openssl-devel

2. tar xvf apr-1.5.0.tar.bz2
./configure --prefix=/usr/local/apr
make && make install

3. tar xvf apr-util-1.5.3.tar.bz2
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

4. tar xvf httpd-2.4.9.tar.bz2
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install

5. httpd Config:
vim  /etc/httpd/httpd.conf
LoadModule proxy_module  modeles/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 

AddType  application/x-httpd-php  .php
AddType  application/x-httpd-php-source  .phps

关闭正向代理
ProxyRequests Off 
ProxyPassMatch ^/(.*\.php)$  fcgi://12.11.0.102:9000/var/log/php/$1


6. Test php
index.php
<?php
    phpinfo();
?>

conn.php
<?php
        $conn = mysql_connect ('12.11.0.103','root','123456');
        if ($conn)
                echo "succ";
        else
                echo "faiure";

        mysql_close();
?>

7. install wordpress
unzip wordpress...
mv wordpress /usr/local/httpd/htdocs

vim /etc/httpd/httpd.conf

Change from 
DirectoryIndex index.html
to 
DirectoryIndex index.html index.php

Server 3
1. Install mysql
tar  xf  mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mariadb-5.5.36-linux-x86_64  mysql

bin  二进制程序
data  数据存放目录
scripts/mysql_install_db   mysql初始化脚本
support-file    样例文件
其中国有样例配置文件,但是提供了不同的版本
huge  海量内存
large  服务器硬件叫充分
small  较少的内存
mysql.server  服务脚本

groupadd  -r  mysql
useradd -g mysql -r mysql 
mkdir -p /mydatad/data
chown mysql:mysql  /mydata/data

cd /usr/local/mysql
scripts/mysql_install_db --datadir=/mydata/data  --user=mysql  
mkdir /etc/mysql
cp  support-file/my-large.cnf  /etc/mysql/my.cnf

vim /etc/mysql/my.cnf
add: datadir=/mydata/data

cp support-file/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
service mysqld start

vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
. /etc/profile.d/mysql.sh

create wordpress databsae in mysql

Server 2
1. Install mysql
tar  xf  mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mariadb-5.5.36-linux-x86_64  mysql

2. Install PHP
yum install libxml2-devel  libmcrypt-devel(epel源中)  bzip2-devel gcc openssl-devel 
tar  xf php-5.4.26
./configure --prefix=/usr/local/php  --with-mysql=/usr/local/mysql  --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config  --enable-mbstring  --with-freetype-dir --with-jpeg-dir --with-png-dir  --with-zlib  --with-libxml-dir=/usr  --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php/php.d/
make && make  install

3. PHP Config:
php的配置文件:php.ini
php的守护进程配置文件:fpm.conf

mkdir -pv /etc/php/php.d
cd /tmp/php-5.4.25
cp php.ini-production /etc/php/php.ini
cp sapi/fpm/init.d.php-fpm   /etc/rc.d/init.d/php-fpm
cd /usr/local/php/etc
mv php-fpm.conf.default php-fpm.conf
cd /etc/rc.d/init.d
chmod +x php-fpm
chkconfig --add php-fpm

vim /usr/local/php/etc/php-fpm.conf
listen = 12.11.0.102:9000
listen.allowed_clients = 12.11.0.101

4. install wordpress
unzip wordpress...
mv wordpress /var/log/php

cd /var/log/php
mv wp-config-sample.php wp-config.php

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error