LNMP搭建 源碼包

 

LNMP源碼包搭建php

linux    CentOS-6.5-x86_64-bin-DVD1html

nginx   版本1.8.0  下載地址:http://nginx.org/en/download.htmlmysql

mysql  版本5.0.56 linux

php     版本5.6.15 nginx

nginx、 mysql 、php對應版本的源碼包能夠在這裏下載:http://pan.baidu.com/s/1sjMOcYLc++

這些源碼包都上傳或下載到該目錄下:  /usr/local/sql

1.安裝nginxapp

安裝以前先安裝下各類依賴curl

# yum  -y install zlib-devel pcre-devel openssl-devel gccsocket

# cd /usr/local

# tar -xf nginx-1.8.0.tar.gz

# cd nginx-1.8.0

# ./configure --prefix=/usr/local/nginx --with-openssl=/usr/include/openssl --with-pcre --with-http_stub_status_module

# make && make install

啓動nginx

# /usr/local/nginx/sbin/nginx

查看是否啓動

# ps aux | grep nginx

 

2.安裝mysql  (注:mysql5.6或者高版本mysql須要cmake編譯安裝)

 安裝以前先安裝下依賴

# yum -y install ncurses-devel gcc-c++

# useradd -M -s /sbin/nologin mysql

# cd /usr/local

# tar -xf mysql-5.0.56.tar.gz

# cd mysql-5.0.56

# ./configure --prefix=/usr/local/mysql --without-debug --with-extra-charsets=utf8,gbk --enable-assembler --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --with-ssl

# make && make install

    #編譯的時間比較漫長。。

# cp /usr/local/mysql-5.0.56/support-files/my-medium.cnf  /etc/my.cnf

# cp /usr/local/mysql-5.0.56/support-files/mysql.server  /etc/init.d/mysqld

# chmod +x /etc/init.d/mysqld

# ln -s /usr/local/mysql/bin/* /usr/local/bin/

# ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/

# mysql_install_db --user=mysql   (mysql 5.6 install表 # /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &)

# chown -R root:mysql /usr/local/mysql/ 

# chown -R mysql:mysql /usr/local/mysql/var/

# service mysqld start

# mysql

 

 

3. 安裝php

先安裝各類依賴

# yum -y install libxml2 libxml2-devel curl-devel libpng-devel openldap-devel

# cd /usr/local

# tar -xf php-5.6.15.tar.gz

# cd php-5.6.15

# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap -enable-mbstring

 

======================================== 

可能遇到錯誤:Cannot find ldap libraries in /usr/lib.   

這樣解決:  # cp -frp /usr/lib64/libldap* /usr/lib/

==========================================

可能遇到錯誤:configure: error: mcrypt.h not found. Please reinstall libmcrypt

這樣解決:

# yum -y install wget

# cd /usr/local

# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz

# tar -xf libmcrypt-2.5.7.tar.gz

# cd libmcrypt-2.5.7

# ./configure

# make && make install

================================================

可能遇到錯誤:configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no

這樣解決: # export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib

===================================================

 

若是遇到以上問題,解決後,繼續

# cd /usr/local/php-5.6.15

# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap -enable-mbstring  

# make && make install

  編譯的時間比較漫長。。

php安裝完成

 

php全局執行命令

# ln -s /usr/local/php/bin/php /usr/bin/

php的配置文件(注意php配置文件原來在源碼包裏面

# cp /usr/local/php-5.6.15/php.ini-development /usr/local/php/lib/php.ini

php-fpm的配置文件,暫先不改內容:

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

 

 

==================================

解決php命令不是環境變量

這樣解決:  

第一種方法: # ln -s /usr/local/php/bin/php /usr/bin/   順便提示寫,軟連接的源文件須要從根目錄的頭開始,好比/usr/local/php/bin/php要寫全。

第二種方法:

修改/etc/profile文件,在文件末尾加上以下兩行代碼

PATH=$PATH:/usr/local/php/bin
export PATH

保存退出後,執行  # source /etc/profile

=======================================

 

如今lnmp基本搭建完成。

 

啓動php-fpm,這個就是nginx和php進行通訊用
# /usr/local/php/sbin/php-fpm

默認開啓9000端口,能夠經過查看是否已開啓

# netstat -anp | grep 9000

 

配置nginx,編輯nginx配置文件
# vi /usr/local/nginx/conf/nginx.conf

主要修改一下內容:


server {
  listen 80;
  server_name www.lnmp.com;    #這裏隨意起一個域名,而後在訪問的機器上配置下本身的hosts

  location / {
    root /data/www;    #網站的目錄
    index index.php index.html index.htm;
  }

  location ~ \.php$ {
    root /data/www;
    fastcgi_pass 127.0.0.1:9000;    # 這個9000端口就是php-fpm的使用端口
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;        #這個地方注意下$document_root...
    include fastcgi_params;
  }
}

 

改完配置後,啓動nginx

# /usr/local/nginx/sbin/nginx

若是報錯說已經開啓了。。

能夠這樣解決:

# pkill -9 nginx

而後再啓動。

 

=====

有些安裝軟件的過程當中使用了root,可能出現沒權限的報錯。最好用一個非root賬號,好比一個work賬號

例如nginx、php均可以搞成work工做。啓動nginx若是用80賬號,work權限不夠,能夠sudo一下。

chown -R work:work /usr/local/php/
chown -R work:work /usr/local/nginx/

=====

 

能夠在/data/www寫一個測試內容

# mkdir -p /data/www

# cd /data/www

# vi index.php     

好比這樣

<?php  

  phpinfo();

?>

 

這樣就能夠訪問http://www.lnmp.com了~

若是訪問不了,有可能linux上有防火牆限制。能夠關閉下

# service iptables stop

再訪問下試試哈哈~

恭喜成功!!~~

 

 

 

 

-----------------------yum安裝LNMP--------------

yum install -y nginx

yum install -y mysql mysql-server mysql-devel

yum install -y php php-fpm php-mysql php-gd php-mbstring php-mcrypt

相關文章
相關標籤/搜索