centos6.2 64位LNMP(linux+nginx+mysql+php)實現

    現在nginx運用越來越廣泛。這是因爲NGINX在某些方面優於apache。並且NGINX在web服務當中佔有一定的比例,我們有必要了解和學習。下面步入正題,看LNMP架構怎麼搭建。
      首先,分析下LAMP架構的安裝。在LAMP架構中mysql,apache是可以單獨安裝不需要關聯其他兩個,而PHP即要關聯MYSQL,又要關聯apache,所以,裝PHP是關鍵。那麼,在LNMP架構中,也一樣。關鍵的地方是讓NGINX來支持PHP。那怎麼讓NGINX來支持PHP呢?這就用到了,PHP中的fastcgi跟fpm這兩個東東,在正常情況下Nginx和PHP他倆之間是一點感覺沒有的。在之前,很多朋友都搭建過Apache+PHP,Apache+PHP編譯後生成的是模塊文件,而Nginx+PHP需要PHP生成可執行文件纔可以,所以要利用fastcgi技術來實現Nginx與PHP的整合,這個只要我們安裝是啓用FastCGI即可。此次我們安裝PHP不僅使用了FastCGI,而且還使用了PHP-FPM這麼一個東東,PHP-FPM說白了是一個管理FastCGI的一個管理器。
       好了,現在明白了。那麼,就動手吧。首先,安裝MYSQL和NGINX,

[root@localhost mysql-5.5.22]# useradd mysql -s /sbin/nologin [root@localhost mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 [root@localhost mysql-5.5.22]# gmake && make install [root@localhost mysql-5.5.22]# chown mysql. -R /usr/local/mysql [root@localhost mysql-5.5.22]# cd support-files/ [root@localhost support-files]# cp my-huge.cnf /etc/my.cnf [root@localhost mysql-5.5.22]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ [root@localhost mysql-5.5.22]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost mysql-5.5.22]# chkconfig --add mysqld [root@localhost mysql-5.5.22]# service mysqld start

 最後添加環境變量到系統

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

然後安裝nginx,安裝nginx比較簡單了,直接運行

[root@shiyan1 nginx-1.2.6]#./configure --prefix=/usr/local/nginx [root@shiyan1 nginx-1.2.6]# make && make install

nginx完了,就裝PHP,這個是關鍵

[root@localhost libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt   [root@localhost libmcrypt-2.5.7]# make && make install [root@localhost php-5.3.10]# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-curl --with-libxml-dir --with-config-file-path=/usr/local/php5/etc --enable-ftp --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-zip  --with-mcrypt=/usr/local/libmcrypt  --with-gd --enable-soap --enable-fpm --enable-fastcgi

 運行完會提示,找不到參數enable-fastcgi.這個不用理會。直接make && make install

    [root@localhost php-5.3.10]# cp php.ini-production /usr/local/php5/etc/php.ini      [root@localhost php-5.3.10]# cd /usr/local/php5/etc/      [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf      [root@localhost etc]# vim php-fpm.conf      [global]      ; Pid file      ; Note: the default prefix is /usr/local/php5/var      ; Default Value: none      pid = run/php-fpm.pid      ; Error log file      ; If it's set to "syslog", log is sent to syslogd instead of being written      ; in a local file.      ; Note: the default prefix is /usr/local/php5/var      ; Default Value: log/php-fpm.log      ;error_log = log/php-fpm.log      [root@localhost etc]# cd /usr/local/src/php-5.3.10/sapi/fpm/      [root@localhost fpm]# cp init.d.php /etc/rc.d/init.d/php-fpm      [root@localhost fpm]# service php-fpm start      [root@localhost fpm]# cd /usr/local/nginx/conf/nginx.conf              # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000              #              location ~ \.php$ {                  root           html;                  fastcgi_pass   127.0.0.1:9000;                  fastcgi_index  index.php;                  fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;                  include        fastcgi_params;              }                    # deny access to .htaccess files, if Apache's document root              # concurs with nginx's one  [root@localhost fpm]# /usr/local/nginx/sbin/nginx

   把fpm跟nginx配置文件修改好啓動,lnmp就完成了。值得注意的是:php-fpm.conf這個配置文件修改的時候,只需修改一處就是,把pid = run/php-fpm.pid這個前面的分號去掉就可以了,而nginx配置文件把支持PHP打開就OK!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章