源码编译搭建LNMP

Linux: Ubuntu 14.04 PHP: 7.0.1 Nginx: 1.9.9 MySQL: 5.7.10

安装Nginx

下载地址:https://nginx.org/en/download.html

依赖关系:

apt-get install build-essential libtool libpcre3 libpcre3-dev openssl libssl-dev

配置:

./configure --user=www-data --group=www-data --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module

编译安装:

make && make install

Nginx默认安装到 /usr/local/nginx 目录。

创建符号链接:

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

配置nginx.conf

location ~ \.php$ {
    #fastcgi_pass   127.0.0.1:9000;
    fastcgi_pass   unix:/var/run/php-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

 

安装PHP7

安装其他版本的php也可用这个方法

下载地址:http://php.net/downloads.php

安装依赖:

apt-get install libxml2-dev libcurl4-gnutls-dev libjpeg-dev libpng-dev libmcrypt-dev libreadline6 libreadline6-dev libfreetype6-dev

缺少了openssl解决:

ln -s /lib/x86_64-linux-gnu/libssl.so.1.0.0 /usr/lib/libssl.so

配置:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

编译:

make -j4

安装:

make install

这样 PHP 将被安装到 /usr/local/php 目录。
编辑 /etc/enviornment, 将 /usr/local/php/bin 添加到 PATH 变量, 然后用 source /etc/environment 更新。

配置 php.ini

cp <source-dir>/php.ini-development /usr/local/php/etc/php.ini

配置php-fpm.conf

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

配置www.conf

mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

初始化 php-fpm 服务脚本

Reference: FPM Installation and Configuration

cp /sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm

修改该文件内容

prefix=
exec_prefix=
php_fpm_BIN=/usr/local/php/sbin/php-fpm
php_fpm_CONF=/usr/local/php/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid

关于PHP7的一些配置优化, 可以看鸟哥的文章 让PHP7达到最高性能的几个Tips

 

安装MySQL

先要编译 boost 库

apt-get install python-dev gccxml libbz2-dev
wget -c http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -zvxf boost_1_59_0.tar.gz
cd boost_1_59_0/
./bootstrap.sh
./bjam --prefix==./prefix/install
./b2 install

提示 virtual memory exhausted: Cannot allocate memory 解决

mkdir /opt/images/
rm -rf /opt/images/swap
dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000  
mkswap /opt/images/swap
swapon /opt/images/swap

swapoff swap
rm -f /opt/images/swap

下载选择 community – source code – Generic Linux

wget -c http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.10.tar.gz

apt-get install cmake bison libncurses5-dev

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=

make -j4

make install

修改 php.ini 中mysql链接的 socket 位置为: /var/run/mysqld/mysqld.sock

 

转自:https://github.com/Zhangjd/my-lnmp

 

赞(0) 人间有温暖
未经允许不得转载:搜查记 » 源码编译搭建LNMP
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

文章滞销帮帮我们

支付宝扫一扫打赏

微信扫一扫打赏