lnmp的编译安装

记录一下lnmp的安装步骤,以及扩展安装

lnmp的编译安装步骤

nginx模块安装

不同于apache扩展的安装,nginx每一次安装都是重新编译一次

  1. 下载所需要的安装包,我这里使用的是ngx_http_consistent_hash nginx扩展包
    https://github.com/replay/ngx_http_consistent_hash
    下载到服务器上,然后解压
  2. 进入nginx安装包目录,下面是nginx的安装包目录。我是用的lnmp1.3的安装包

    查看一下以前的编译情况

    1
    2
    3
    4
    5
    6
    /usr/local/nginx/sbin/nginx -V;
    nginx version: nginx/1.10.0
    built by gcc 6.2.0 20161005 (Ubuntu 6.2.0-5ubuntu12)
    built with OpenSSL 1.0.2g 1 Mar 2016
    TLS SNI support enabled
    configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=/root/ngx_http_consistent_hash-master/
  3. 安装第三方模块

    1
    2
    ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=/root/ngx_http_consistent_hash-master/  
    make && make install

安装memcache服务端

1
2
3
4
5
6
7
8
9
10
11
12
13
http://memcached.org/downloads 官网下载稳定版
wget http://memcached.org/latest
tar -zxvf memcached-1.x.x.tar.gz
cd memcached-1.x.x
./configure && make && make test && sudo make install

/usr/local/memcached/bin/memcached -p 11211 -u nobody -m 64m -vv //启动

$memcache = new Memcache; //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$get_value = $memcache->get('key'); //从内存中取出key的值
echo $get_value;

安装php的memcache扩展

1
2
3
4
5
6
7
https://pecl.php.net/ 官方模块下载地址搜索 memcache
cd 扩展目录;
/usr/local/php/bin/phpize --with-php-config=/usr/local/php/bin/php-config //生成 ./configure
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install //提示安装成功 /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/ 安装目录
php.ini 添加一条扩展
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache.so

安装apache

1
2
3
4
5
6
7
8
9
10
11
12
官网下载apache稳定版
#chmod 755 httpd-2.0.54.tar.gz (说明:给予更多的权限)

#./configure --prefix=/usr/local/apache --enable-module=most --enable-shared=max
(说明:配置Apache。这里我把默认可以生成的"httpd"改成了"apache"的目录,目的为了便于查找)
#make (说明:编译Apache)
#make install (说明:安装Apache)
#/usr/local/apache/bin/apachectl start (说明:启动Apache服务,看Apache服务是否可以正常启动)
如果启动出这个问题:httpd: Could not reliably determine the server's fully qualified domain name
,可以用记事本打开httpd.conf,将里面的#ServerName localhost:80注释去掉即可,再执行httpd
#/usr/local/apache/bin/apachectl stop (说明:停止Apache服务,看Apache服务是否可以正常关闭)
常用的工具都放在其安装目录的bin目录下:

php安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
下载php源文件可以直接在 www.php.net官网进行下载
//apache使用的
./configure --prefix=/usr/local/fastphp --with-mysql=mysqlnd --enable-mysqlnd --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-apxs2=/usr/local/apache2.2/bin/apxs

//nginx使用的
./configure --prefix=/usr/local/fastphp --with-mysql=mysqlnd --enable-mysqlnd --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --enable-fpm

make && make install //有时候可能会出错,使用下面的安装
make ZEND_EXTRA_LIBS='-liconv' && make install
cp php.ini-development /usr/local/fastphp/lib/php.ini //复制一份php.ini文件

修改apache下面的httpd.config文件
LoadModule php5_module modules/libphp5.so 这项配置Apache有可能已经在配置文件中配置好了,如果没有则自己添加上去
AddType application/x-httpd-php .php

/usr/local/apache/bin/apachectl restart //重新启动apache 测试php程序是否执行了

mysql安装

1
2
3
groupadd mysql                增加mysql用户组
useradd -g mysql -s /bin/false -M mysql 建立属于mysql组的mysql用户,且不允许登陆系统
然后把mysql安装路径,文件拥有者及拥有组改为mysql

文章目录
  1. 1. nginx模块安装
|