手动搭建LNMP

LNMP环境搭建

需要编译安装的软件包:

mysql-5.6.30.tar.gz    下载地址为:http://dev.mysql.com/downloads/

wget  

http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.30.tar.gz

 php-5.6.22.tar.gz      下载地址为:http://www.php.net/downloads.php

http://am1.php.net/get/php-5.6.36.tar.gz/from/this/mirror

mcrypt-2.6.8.tar.gz     

mhash-0.9.9.9.tar.gz      

libmcrypt-2.5.8.tar.gz

libiconv-1.14.tar.gz 

curl-7.48.0                   下载地址:http://curl.haxx.se/download/curl-7.48.0.tar.gz

nginx-1.8.1.tar.gz      下载地址为:

http://nginx.org/download/nginx-1.8.1.tar.gz

ImageMagick-7.0.1-6.tar.gz

      下载地址为:http://www.imagemagick.org/download/

imagick-3.4.1.tgz            下载地址为:http://pecl.php.net/package/imagick(

http://pecl.php.net/get/imagick-3.4.1.tgz

 

一、安装及配置mysql

查看系统中是否有mysql相关包

#rpm -qa | grep mysql

出现如下相关包:

mysql-libs-5.1.73-3.el6_5.x86_64

删除系统默认的mysql相关包

#rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64

#rpm -qa | grep mysql        //再次查看,若为空则说明清理干净了系统默认的mysql关联包

                      

安装mysql关联包

#yum install ntp vim-enhanced gcc gcc-c++ cmake bison autoconf automake bzip2-devel ncurses-devel zlib-devel gettext-devel  libtool libtool-ltdl openssl openssl-devel curl-devel

 

 

以上错误解决方式

yum install make

 

安装mysql

# mkdir /usr/local/mysql

# cd /usr/local/src/lnmp

# tar zxvf mysql-5.6.30.tar.gz

# cd mysql-5.6.30

#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DINSTALL_PLUGINDIR=/usr/local/mysql/plugin -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306

 

-- Configuring done

-- Generating done

 

# make

# make install 

 

创建mysql用户及用户组

  // 创建用户mysql及mysql组

#useradd -r -d /adata/mydb -s /sbin/nologin mysql

#chown -R mysql.mysql /usr/local/mysql/                          // 修改mysql安装目录拥有组及拥有者

#cd /usr/local/mysql   

# cp support-files/my-default.cnf  /etc/my.cnf 

# vim /etc/my.cnf                            # 编辑配置文件,在 [mysqld] 部分增加下面一行

basedir         = /usr/local/mysql

datadir         = /adata/mydb

:wq  保存

                                                         //进入MySQL安装目录

#scripts/mysql_install_db --user=mysql --datadir=/adata/mydb                    //生成mysql系统数据库

#cp support-files/mysql.server  /etc/rc.d/init.d/mysqld  //把Mysql加入系统启动

chmod 755 /etc/rc.d/init.d/mysqld         //增加执行权限

chkconfig mysqld on                              //加入开机启动

#service mysqld start                          //启动mysql

#vim /etc/profile                                    //把mysql服务加入系统环境变量:在最后添加下面这一行

 

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

 

# source /etc/profile

# bin/mysql_secure_installation        // 安全设置,设置root密码,输入密码,按提示一路回车即可。

root密码:newerpdb.dh666

# service mysqld restart 

输入命令

#mysql -u root -p

再输入密码,便可以登陆进mysql。至此,mysql5.6.24安装完毕

 

二、安装php组件

 

安装相应关联包

#yum install libxml2 libxml2-devel kernel-devel libjpeg libjpeg-devel libpng libpng-devel gd gd-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel e2fsprogs e2fsprogs-devel krbs krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers  pcre-devel

 

1. 安装curl

#wget http://curl.haxx.se/download/curl-7.48.0.tar.gz

#tar zxvf  curl-7.48.0.tar.gz

#cd curl-7.48.0

#./configure --prefix=/usr/local/curl

#make

#make install

 

2. 安装libiconv

#tar zvxf   libiconv-1.14.tar.gz  

#cd  libiconv-1.14

#./configure --prefix=/usr/local/libiconv

#make

#make install

 

 

vim srclib/stdio.in.h

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)

_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

#endif

 

3. 安装mhash

第一步,对源码文件解压并建立安装目录,命令行如下:

#tar zvxf mhash-0.9.9.9.tar.gz 

#cd mhash-0.9.9.9

 

第二步,使用“configure”命令生成安装配置文件,命令行如下:

# ./configure

 

第三步,使用“make“命令编译并生成安装文件

#make

 

第四步,使用“make install“命令进行安装,命令如下:

#make install

 

4. 安装libmcrypt

第一步,对源码文件解压并建立安装目录,命令行如下:

#tar zvxf libmcrypt-2.5.8.tar.gz 

#cd libmcrypt-2.5.8

 

第二步,使用“configure”命令生成安装配置文件,命令行如下:

# ./configure

 

第三步,使用“make“命令编译并生成安装文件

#make

 

第四步,使用“make install“命令进行安装,命令如下:

#make install

 

5. 安装mcrypt

第一步,对源码文件解压并建立安装目录,命令行如下:

#tar zvxf mcrypt-2.6.8.tar.gz 

#cd mcrypt-2.6.8

#ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config (建个软件链接)

#export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH (手动加载变量)

 

第二步,使用“configure”命令生成安装配置文件,命令行如下:

# ./configure

 

第三步,使用“make“命令编译并生成安装文件

#make

 

第四步,使用“make install“命令进行安装,命令如下:

#make install

 

6. 安装ImageMagick 

#tar zxvf

ImageMagick-7.0.1-6

.tar.gz

#cd 

ImageMagick-7.0.1-6/

#./configure --prefix=/usr/local/imagemagick(configure之前应先创建imagemagick目录;也可以不带参数,直接./configure ,此时ImageMagick默认安装到/usr/local/include/ImagicMagick-6)

#make

#make install

#convert -version 查看版本

 

三、安装php

第一步,对源码包文件解压并配置安装环境,命令如下:

#tar zvxf php-5.6.22.tar.gz

#cd php-5.6.22

#mkdir /usr/local/php                  //建立php的安装目录(目录可以随便选择)

 

第二步,使用"configure"命令生成安装配置文件,命令如下:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql  --with-iconv=/usr/local/libiconv --with-curl=/usr/local/curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-zlib --with-freetype-dir --with-gd --with-bz2  --with-mcrypt --with-openssl --with-mhash --with-gettext --with-xmlrpc --enable-soap --enable-mbstring=all --enable-sockets --enable-shared --enable-gd-native-ttf --enable-zip --enable-xml --enable-fpm --enable-inline-optimization --enable-pcntl --enable-bcmath --enable-calendar --enable-ftp

 

configure 成功后的提示:

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+

 

Thank you for using PHP.

 

第三步,使用“make“命令编译并生成安装文件

#make

 

第四步,使用“make install“命令进行安装,命令如下:

#make install

 

第五步,建立php配置文件,开发环境下将当前目录下的文件php.ini-production换名复制到/usr/local/php5/etc目录下,且重命名为php.ini, 命令如下:

#cp php.ini-production /usr/local/php/etc/php.ini

#cd /usr/local/php

#vi etc/php.ini

date.timezone = America/Chicago(此处使用的是 Asia/Hong_Kong)

error_log = /usr/local/php/var/log/php_errors.log

 

第六步,创建www用户和用户组(此处是ngwww)方便php-fpm和nginx中配置默认用户。

#useradd -d /mnt/hgfs/vmware -M -s /sbin/nologin ngwww

useradd -d /bedata/site -M -s /sbin/nologin ngwww

 

第七步,配置php-fpm

#cd /usr/local/php55/etc

#cp php-fpm.conf.default php-fpm.conf

#cat /dev/null > php-fpm.conf         //清空php-fpm.conf中的所有内容

#vi php-fpm.conf

添如下基本配置:

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log =  /usr/local/php/var/log/php-fpm.log

log_level = notice

 

[www]

user = ngwww

group = ngwww

listen = /dev/shm/php-cgi.sock

listen.owner = ngwww

listen.group = ngwww

listen.backlog = -1

listen.mode = 0666

pm.status_path = /phpfpm_status

pm = dynamic

pm.max_children = 30

pm.start_servers = 5

pm.min_spare_servers = 3

pm.max_spare_servers = 10

;pm.max_requests = 500

request_terminate_timeout = 3600

rlimit_files = 10240

slowlog = /usr/local/php/var/log/phpslow.log

request_slowlog_timeout = 100s

 

保存,退出即可。

将php-fpm的启动脚本复制到/etc/rc.d/init.d,并给矛相应的执行权限:

#cd /usr/local/src/lnmp/php/php-5.3.29

源码包里

#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

#chmod 755 /etc/rc.d/init.d/php-fpm

 

启动php-fpm

#/etc/init.d/php-fpm start

 

关闭php-fpm

#/etc/init.d/php-fpm stop

 

重启php-fpm:

#/etc/init.d/php-fpm restart

 

查看php-fpm进程是否启动:

ps -ef | grep php-fpm

 

四、安装配置nginx

安装nginx

http://nginx.org/en/download.html

#tar zxvf nginx-1.8.1.tar.gz

# cd nginx-1.8.1

# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_sub_module --with-http_image_filter_module

 

#make

#make install

 

配置nginx

 

防火墙的配置

//修改防火墙配置(开启80,3306端口):

# vi /etc/sysconfig/iptables

添加配置项

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

 

保存,退出。重启防火墙

#service iptables restart

 

nginx的启动、重启、停止

nginx的启动

#方法1

[root@admin nginx-1.2.6]# /usr/local/nginx/sbin/nginx

#方法2

[root@admin nginx-1.2.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 

nginx的重启

#方法1

#kill -HUP nginx主进程号

#方法2

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

备注:nginx重启前需要先执行命令/usr/local/nginx/sbin/nginx –t   来检查配置文件有没有错误。

 

nginx的停止

方法1

 # kill -QUIT nginx主进程

 

方法2

 #kill -INT nginx主进程号

 

查看nginx进程号

#ps -ef | grep nginx

 

【把nginx和php连接起来】

 

编辑nginx 的配置文件,其命令为vi  /usr/local/nginx/conf/nginx.conf,其详细配置如下:

user ngwww ngwww;

worker_processes  2;

 

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

error_log  logs/error.log  error;

 

pid        logs/nginx.pid;

 

 

events {

    use epoll;

    worker_connections  10240;

}

 

 

http {

    include       mime.types;

    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  logs/access.log  main;

 

    sendfile        on;

    tcp_nopush     on;

    keepalive_timeout 30;

    #keepalive_timeout  65;

    log_not_found off;

    server_tokens off;

    tcp_nodelay on;

 

    gzip  on;

    gzip_min_length  1k;

    gzip_buffers     4 16k;

    gzip_http_version 1.0;

    gzip_comp_level 2;

    gzip_types       text/plain text/css text/xml text/javascript application/x-javascript application/xml application/rss+xml application/xhtml+xml application/atom_xml;

    gzip_vary on;

   client_max_body_size 8m;

 

    open_file_cache max=10240 inactive=20s;

    open_file_cache_valid 30s;

    open_file_cache_min_uses 1;

 

    fastcgi_connect_timeout 400;

    fastcgi_send_timeout 350;

    client_header_timeout 300;

    client_body_timeout 350;

    send_timeout 350;

    fastcgi_read_timeout 350;

 

    fastcgi_buffer_size 64k;

    fastcgi_buffers 16 64k;

    fastcgi_busy_buffers_size 64k;

    fastcgi_temp_file_write_size 64k;

 

    server {

        listen       80 default;

        server_name  _;

        return 403;

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 

        #location / {

        #    root   html;

        #    index  index.html index.htm;

        #}

 

        #error_page  404              /404.html;

 

        # redirect server error pages to the static page /50x.html

        #

        #error_page   500 502 503 504  /50x.html;

        #location = /50x.html {

        #    root   html;

        #}

 

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root           /data/web;

        #    fastcgi_pass   unix:/dev/shm/php-cgi.sock;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        #    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

 

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

 

 

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen       8000;

    #    listen       somename:8080;

    #    server_name  somename  alias  another.alias;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

 

 

    # HTTPS server

    #

    #server {

    #    listen       443 ssl;

    #    server_name  localhost;

 

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

 

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

#include vhost/*.conf;

}

 

保存,退出。然后再重启nignx

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

 

在web目录,此处为 /mnt/hgfs/vmware,新建一个php文件,测试能否正常解析php。如此,便完成了整个lNMP基础的搭建。

 

五、安装配置php扩展

 

1. 安装imagick扩展

#tar zxvf imagick-3.4.1.tgz

#cd imagick-3.4.1

#/usr/local/php/bin/phpize

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

#make

#make install

 

(make时有时会提示:checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program,出现这种问题的原因:是没有安装ImageMagick-devel包,注意ImageMagick-devel并不是ImageMagick,ImageMagick-devel是用于 ImageMagick 程序开发的静态库和头文件。所以Imagick也是基于此开发,必不可少咯。而ImageMagick是用来显示和操作图像的 X 应用程序)。

解决方法:

# yum install ImageMagick-devel(通过该命令大概安装了14M左右的关联文件)

然后

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

#make

#make install

至此便完成了imagick的安装,此时ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

便能看到目录下面生成了一个imagick.so

 

extension=imagick.so

 

2.imap扩展安装

cd /adata/src/soft/php-5.6.22/ext/imap

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-imap --with-kerberos --with-imap-ssl

make

make install

 

把imap.so扩展加到php.ini:

extension = imap.so

 

注意:./configure编译报错

报错1:configure: error:utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This shouldnot happen. Check config.log for additional information

解决:

yum install -y libc-client-devel

ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so

 

#yum install pam-devel libc-client libc-client-devel -y

 

报错2:configure: error:Kerberos libraries not found.  Check thepath given to --with-kerberos (if no path is given, searches in /usr/kerberos,/usr/local and /usr )

解决:ln -s /usr/lib64/libkrb5.so /usr/lib/libkrb5.so

 

报错3:configure: error:Cannot find OpenSSL's libraries

解决:ln -s /usr/lib64/libssl.so /usr/lib/libssl.so

 

重新./configure编译即可。

 

ERP nginx加密文件生成

htpasswd -c dhfile auerp (htpasswd -c 文件名 用户名)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

明雨星云

感谢,我会继续创作更优质作品

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值