LNMP搭建 源码包

LNMP源码包搭建

linux    CentOS-6.5-x86_64-bin-DVD1

nginx   版本1.8.0  下载地址:http://nginx.org/en/download.html

mysql  版本5.0.56 

php     版本5.6.15 

nginx、 mysql 、php对应版本的源码包可以在这里下载:http://pan.baidu.com/s/1sjMOcYL

这些源码包都上传或下载到该目录下:  /usr/local/

1.安装nginx

安装之前先安装下各种依赖

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

# 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

 

原文地址:https://www.cnblogs.com/firstForEver/p/4943335.html