天天看點

lnmp

lnmp

 linux + nginx + mysql + php

 nginx = engine x

 lamp工作流程:

  index.php --> apache ---> libphp.so ---> apache ---> client

 lnmp工作流程

   index.php --> nginx --tcp/ip或socket-> php-cgi --> nginx --> client

1、安裝mysql

# useradd -s /sbin/nologin mysql

# tar xvf mysql-5.1.54.tar.gz -c /usr/src

# ./configure --prefix=/usr/local/mysql --enable-assembler --enable-profiling --enable-local-infile --with-charset=utf8 --with-extra-charsets=gbk,gb2312 --with-pthread --with-low-memory --with-big-tables --with-plugins=innobase,heap,innodb_plugin --with-mysqld-ldflags='-all-static'

# make && make install

# vim /etc/my.cnf

[mysqld]

datadir=/data

user=mysql

socket=/data/mysqld.sock

port=3306

server-id=1

log-bin=/data/mysqld-bin

log-bin-index=/data/mysqld-bin-index

[mysqld_safe]

log-error=/data/mysqld.err

pid-file=/data/mysqld.pid

# mkdir /data

# chown mysql:mysql /data

# cd /usr/local/mysql

# ./bin/mysql_install_db --datadir=/data

installing mysql system tables...

ok

filling help tables...

...

# /usr/local/mysql/bin/mysqld_safe &

建議:如果一開始是用mysqld_safe啟動,那麼以後堅持使用該方式啟動。

# mysqladmin -u root -s /data/mysqld.sock password '123'

# mysqladmin -u root -h dev.upl.com password '123'

2、php的一些功能包

# yum install freetype libjpeg libpng libxml2 fontconfig -y

libmcrypt-2.5.8.tar.gz

# tar xvf libmcrypt-2.5.8.tar.gz -c /usr/src

# ./configure  && make && make install

# cd libltdl/

# ./configure --enable-ltdl-install && make && make install

mhash

# vim /etc/ld.so.conf

/usr/local/lib/  《--新添加一行

# ldconfig

mcrypt-2.6.8

libiconv-1.13.tar.gz

# ./configure --prefix=/usr/local/  && make && make install

gd-2.0.35.tar.gz

# ./configure --prefix=/usr/local/ --with-png --with-jpeg --with-freetype --with-fontconfig

安裝對應版本mysql的開發庫包

# rpm -ivh --force mysql-shared-compat-5.1.54-1.rhel5.i386.rpm

3、編譯php

# tar xvf php-5.2.13.tar.gz  -c /usr/src

給php源碼包打更新檔,讓其支援直接使用腳本平滑的啟動php和重載php

# gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d /usr/src/php-5.2.13 -p1

# ./configure --enable-fastcgi --enable-force-cgi-redirect --enable-fpm --with-config-file-scan-dir=/usr/local/etc --with-libxml-dir --with-openssl --with-zlib --enable-bcmath --with-curl --with-curlwrappers --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring  --with-mcrypt --with-mhash --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-ncurses --enable-pcntl --enable-soap --enable-sysvsem --with-iconv-dir=/usr/local --enable-zip  --disable-rpath

# make zend_extra_libs='-liconv'

# make install

4、安裝php的擴充子產品

1)

memcache用戶端

# cd /usr/src/memcache-2.2.5

# /usr/local/bin/phpize

# ./configure --with-php-config=/usr/local/bin/php-config  && make && make install

子產品安裝之後儲存的路徑

installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

2) eaccelerator-0.9.6.tar.bz2

拷貝php模闆配置檔案

# cp /usr/src/php-5.2.13/php.ini-recommended  /usr/local/etc/php.ini

# vim /usr/local/etc/php.ini

找到

extension_dir = "./"

修改:

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"

extension = "memcache.so"

zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"

eaccelerator.shm_size="16"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

# chmod 777 /tmp/eaccelerator

驗證子產品是否正确調用

# php -m

5、編譯nginx

1) pcre-8.01

# ./configure --prefix=/usr && make && make install

2)

# tar xvf  nginx-0.8.54.tar.gz -c /usr/local/

# ./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --user=daemon --group=daemon

整個架構的配置:

1)配置并且啟動php-cgi

php-cgi配置檔案:php.ini

使用fpm腳本啟動,而fpm腳本是有配置檔案

# vim /usr/local/etc/php-fpm.conf

<value name="listen_address">127.0.0.1:9000</value>

<value name="user">daemon</value>

<value name="group">daemon</value>

<value name="style">static</value>

<value name="max_children">32</value>  啟動多少個php-cgi程序

<value name="rlimit_files">204800</value>

<value name="max_requests">65535</value> 《---最大的并發請求

啟動php-cgi程序

# php-fpm start

2)配置nginx

# vim /usr/local/nginx/conf/nginx.conf

user  daemon;

worker_processes  4;

error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {

    worker_connections  65535;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  www.upl.com;

        root   /www/www.upl.com/;

        index  index.html index.htm index.php;

        location ~ .*\.php$ {

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            include        fastcgi.conf;

        }

    }

3)啟動

# ulimit -shn 65535

# /usr/local/nginx/sbin/nginx

# lsof -i:80

關閉服務

# /usr/local/nginx/sbin/nginx -s stop

繼續閱讀