下载软件:
nginx:nginx-1.8.0.tar.gz

php: php-7.1.1.tar.gz

mysql: mysql-5.6.21.tar.gz

libxml2:libxml2-2.9.1.tar.gz

openssl:openssl-1.0.1e.tar.gz

zlib:zlib-1.2.3.tar.gz

pcre:pcre-8.36.tar.gz


创建目录:

这里创建 /www/web 用于存入程序代码; /www/source 环境的安装目录; /www/lnmp 用于存放安装软件

创建安装目录命令:

mkdir -p /www/{lnmp,source,web}


2、将上面下载好的软件用ftp(或其它工具)上传到 /www/lnmp,并进行解压

3、安装工具

这里用yum安装一下在编译过程中所需要的编译工具和小程序,如:gcc、gd库、cmake等等。这么多小软件,我们不需要编译安装,因为这些软件安装后,以后并不会修改操作,只是一个工具而已。

yum install -y gcc gcc-c++ make sudo autoconf libtool-ltdl-devel gd-devel \
freetype-devel libxml2-devel libjpeg-devel libpng-devel \
openssl-devel curl-devel patch libmcrypt-devel \
libmhash-devel ncurses-devel bzip2 \
libcap-devel ntp sysklogd diffutils sendmail iptables unzip cmake

 

yum install -y libxml2-dev libpng12-dev libfreetype6-dev openssl libcurl3-openssl-dev libjpeg-dev
yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

 

 

 

注意:这里可能会出现以下错误

Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 71 M RSS (370 MB VSZ)
Started: Sat Feb 11 18:45:08 2017 - 00:34 ago
State : Running, pid: 3033
这是因为yum正在运行着,我们需要停止yum,停止yum的命令如下:

[root@localhost ~]# kill /var/run/yum.pid
停止yum之后,再进行上面的yum安装。


4、创建用户

我们需要创建2个用户,一个用来启动mysql,一个用来启动nginx

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r mysql -g mysql
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -r www -g www


二、安装nginx
安装nginx前,我们需要安装3个依赖包:
1、安装 pcre

[root@localhost lnmp]# cd /www/lnmp/pcre-8.36
[root@localhost pcre-8.36]# ./configure
[root@localhost pcre-8.36]# make
[root@localhost pcre-8.36]# make install


2、安装 openssl

[root@localhost pcre-8.36]# cd /www/lnmp/openssl-1.0.1e
[root@localhost openssl-1.0.1e]# ./config
[root@localhost openssl-1.0.1e]# make
[root@localhost openssl-1.0.1e]# make install

3、安装 zlib

[root@localhost openssl-1.0.1e]# cd /www/lnmp/zlib-1.2.3
[root@localhost zlib-1.2.3]# CFLAGS="-O3 -fPIC" ./configure
[root@localhost zlib-1.2.3]# make && make install

 

4、安装 nginx

  nginx redis 扩展

  wget  http://people.freebsd.org/~osa/ngx_http_redis-0.3.8.tar.gz

  nginx hash 扩展
  wget https://codeload.github.com/replay/ngx_http_consistent_hash/zip/master

   nginx 统计模块,便于观察nginx的状态

  ./configure 添加 --with-http_stub_status_module


[root@localhost zlib-1.2.3]# cd /www/lnmp/nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --help // 这是查看帮助的命令
[root@localhost nginx-1.8.0]# ./configure --user=www --group=www --prefix=/www/source/nginx --with-pcre=/www/lnmp/pcre-8.36 --with-zlib=/www/lnmp/zlib-1.2.3 --with-openssl=/www/lnmp/openssl-1.0.1e --add-module=/www/lnmp/ngx_http_redis --add-module=/www/lnmp/ngx_httpd_consistent_hash
[root@localhost nginx-1.8.0]# make && make install


报错:
1、src/core/ngx_regex.h:24: error: expected specifier-qualifier-list before ‘pcre’
解决:没有pcre-devel 库 yum install -y pcre-devel

2、*** No rule to make target `libpcre.la'. Stop.
解决:不能安装pcre2 只能安装pcre-8版本

安装好之后,我们可以用 ls 查看 /www/source,发现有一个 nginx,说明已经安装成功了。

[root@localhost nginx-1.8.0]# ls /www/source/nginx
[root@localhost nginx-1.8.0]#

 

三、安装mysql

看第二个网页:https://blog.csdn.net/sqzhao/article/details/88058536
以保存到

报错:./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决:yum -y install numactl


报错:Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
解决: rm -rf /etc/my.cnf

 

 

四、安装php

1、安装 libxml2

[root@localhost mysql]# cd /www/lnmp/libxml2-2.9.1
[root@localhost libxml2-2.9.1]# ./configure --with-python=no
[root@localhost libxml2-2.9.1]# make && make install


报错:
make[2]: *** [libxml2.la] 错误 1
make[2]: Leaving directory `/lnmp/libxml2-2.9.1'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/lnmp/libxml2-2.9.1'
make: *** [all] 错误 2

解决方法: 有可能本机安装了 rpm -qa | grep 软件名

./configure --with-python=no --enable-shared=no --with-pic=PIC

 

 openssl 版本不能安装1.1的,不然报错无法安装;


[root@localhost libxml2-2.9.1]# cd /www/lnmp/php-7.1.1
[root@localhost php-7.1.1]# ./configure --prefix=/www/source/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=/www/source/mysql/ --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-sockets --with-curl --enable-maintainer-zts
[root@localhost php-7.1.1]# make
[root@localhost php-7.1.1]# make test // 测试完之后,输入 n
[root@localhost php-7.1.1]# make install

 

出现make: *** [sapi/cli/php] Error 1 解决办法(php7.3版本报错util.c没有修复安装7.1或7.2版本)

undefined reference to `libiconv_open

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz

tar -zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/libiconv
make
make install
php编译时添加 --with-iconv=/usr/local/libiconv
 
继续报错就下面操作

vi Makefile

找到97行的位置在末尾-lcrypt后添加  -liconv

添加:-lcrypt -liconv

然后重新编译

 php7 openssl undefined reference   (https://de.v2ex.com/t/476429)

系统中先是装了一个 openssl 1.1.1 版本的 之前 yum 安装的 devel 版本还是 1.0.1 的 卸载 openssl-devel-1.0.1e-48.el6_8.1.x86_64 后 再编译 正常了 


报错:error: PDO_MYSQL configure failed, MySQL 4.1 needed. Please check config.log for more information.

解决: 编译php的参数的时候--disable-pdo了

 

 

五、环境配置

1、php 配置

[root@localhost php-7.1.1]# cd /www/source/php/
[root@localhost php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@localhost php]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
[root@localhost php]# cp /www/lnmp/php-7.1.1/php.ini-production lib/php.ini

2、启动 php-fpm

[root@localhost php]# /www/source/php/sbin/php-fpm

3、nginx 配置

[root@localhost php]# cd /www/source/nginx/conf/
[root@localhost conf]# vim nginx.conf

将 nginx.conf 中的 server 保存成如下

server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log logs/host.access.log main;

root /www/web;
index index.html index.php;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME /www/web$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

include fastcgi_params;
}
}

4、启动 nginx

[root@localhost conf]# /www/source/nginx/sbin/nginx

 

 


六、测试环境
在 /www/web/ 目录下创建一个 index.php,内容如下:

<?php
phpinfo();

修改 index.php 所属组

[root@localhost php]# chown -R www:www /www/web/

 

 

posted on 2019-03-15 12:53  潇潇六月雨  阅读(308)  评论(0)    收藏  举报