centos7下編譯安裝lnmp

技術小阿哥發表於2017-11-28

1、先安裝mysql

cd /usr/local/src
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 
tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql
useradd mysql
mkdir /data/
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-default.cnf  /etc/my.cnf 
cp support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld

定義basedir和datadir

basedir=/usr/local/mysql
datadir=/data/mysql
/etc/init.d/mysqld start

2、安裝php

編譯安裝php-fpm

什麼是PHP-FPM

PHP-FPM是一個PHP FastCGI管理器,是隻用於PHP的,可以在 http://php-fpm.org/download下載得到.

PHP-FPM其實是PHP原始碼的一個補丁,旨在將FastCGI程式管理整合進PHP包中。必須將它patch到你的PHP原始碼中,在編譯安裝PHP後才可以使用。

新版PHP已經整合php-fpm了,不再是第三方的包了,推薦使用。PHP-FPM提供了更好的PHP程式管理方式,可以有效控制記憶體和程式、可以平滑過載PHP配置,比spawn-fcgi具有更多優點,所以被PHP官方收錄了。在./configure的時候帶 –enable-fpm引數即可開啟PHP-FPM,其它引數都是配置php的,具體選項含義可以檢視這裡。

安裝前準備

centos下執行

yum -y install gcc automake autoconf libtool make

yum -y install gcc gcc-c++ glibc

yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

axel http://mirrors.sohu.com/php/php-7.2.1.tar.xz
tar Jxf php-7.2.1.tar.xz
 useradd -s /sbin/nologin php-fpm
 cd php-7.2.1

./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt 
--enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath 
--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets 
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex 
--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli 
--with-gd --with-jpeg-dir

make all install
cp php.ini-production /usr/local/php-fpm/etc/php.ini

vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
 chmod 755 /etc/init.d/php-fpm
 chkconfig --add php-fpm
 chkconfig php-fpm on
 service php-fpm start
 ps aux |grep php-fpm

報錯 Cannot find OpenSSL`s <evp.h>

執行 yum install openssl openssl-devel

報錯 Please reinstall the libcurl distribution

執行 yum -y install curl-devel

錯誤 jpeglib.h not found

執行 yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

和執行 yum install libjpeg-devel

錯誤:checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution 這是bzip2軟體包沒有安裝

執行 yum install bzip2-devel.x86_64 -y

錯誤:configure: error: xpm.h not found.

執行yum install libXpm-devel

錯誤: Unable to locate gmp.h

執行 yum install gmp-devel

錯誤:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works

執行 yum install -y icu libicu libicu-devel

錯誤:mcrypt.h not found. Please reinstall libmcrypt.

執行 yum install php-mcrypt libmcrypt libmcrypt-devel

錯誤: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

執行 yum install postgresql-devel

錯誤: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

執行yum install libxslt-devel

3、安裝nginx

axel https://nginx.org/download/nginx-1.12.2.tar.gz
Initializing download: https://nginx.org/download/nginx-1.12.2.tar.gz

tar zxf nginx-1.12.2.tar.gz 
cd nginx-1.12.2/
useradd nginx -s /sbin/nologin 

Nginx編譯引數

–user 指定啟動程式所屬使用者

–group 指定組

–prefix 指定安裝路徑

–sbin-path 設定nginx二進位制檔案的路徑名

–conf-path 指定配置檔案路徑

–error-log-path 錯誤日誌檔案路徑

–http-log-path 指定訪問日誌檔案路徑

–http-client-body-temp-path 設定儲存HTTP客戶端請求主體的臨時檔案路徑

–http-proxy-temp-path 設定儲存HTTP代理臨時檔案的路徑

–http-fastcgi-temp-path 設定儲存HTTP fastcgi的臨時檔案的路徑

–pid-path 設定nginx.pid檔案路徑

–lock-path 設定nginx.lock檔案路徑

–with-openssl 啟用SSL

–with-pcre 啟用正規表示式

–with-http_stub_status_module 安裝可以監控nginx狀態的模組

–with-http_ssl_module 啟用SSL支援

–with-http_gzip_static_module 啟用gzip壓縮

./configure 
--user=nginx 
--group=nginx 
--prefix=/usr/local/nginx 
--sbin-path=/usr/sbin/nginx 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log 
--http-client-body-temp-path=/tmp/nginx/client_body 
--http-proxy-temp-path=/tmp/nginx/proxy 
--http-fastcgi-temp-path=/tmp/nginx/fastcgi 
--pid-path=/var/run/nginx.pid 
--lock-path=/var/lock/subsys/nginx 
--with-http_stub_status_module 
--with-http_ssl_module 
--with-http_gzip_static_module 
--with-pcre 
--with-http_realip_module 
--with-http_sub_module
echo $?
make && make install

vim /etc/init.d/nginx

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"
NGINX_PID="/var/run/nginx.pid"
RETVAL=0
prog="Nginx"
start() 
{
    echo -n $"Starting $prog: "
    mkdir -p /dev/shm/nginx_temp
    daemon $NGINX_SBIN -c $NGINX_CONF
    RETVAL=$?
    echo
    return $RETVAL
}
stop() 
{
    echo -n $"Stopping $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -TERM
    rm -rf /dev/shm/nginx_temp
    RETVAL=$?
    echo
    return $RETVAL
}
reload()
{
    echo -n $"Reloading $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -HUP
    RETVAL=$?
    echo
    return $RETVAL
}
restart()
{
    stop
    start
}
configtest()
{
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit $RETVAL
chmod 755 !$
chkconfig --add nginx
service nginx start
ps aux | grep nginx
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload 

增加mysql和php的環境變數

vim /etc/profile.d/mysql.sh
PATH=$PATH:/usr/local/mysql/bin

vim /etc/profile.d/php.sh 
PATH=$PATH:/usr/local/php-fpm/bin

非虛擬主機的配置

vim /etc/nginx/nginx.conf

user nginx nginx;
worker_processes 2;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 6000;
}
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip `$remote_addr $http_x_forwarded_for [$time_local]`
    ` $host "$request_uri" $status`
    ` "$http_referer" "$http_user_agent"`;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /tmp/nginx/client_body;
    proxy_temp_path /tmp/nginx/proxy;
    fastcgi_temp_path /tmp/nginx/fastcgi;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm 
    application/xml;
    server
    {
        listen 80;
        server_name localhost;
        index index.html index.htm index.php;
        root /usr/local/nginx/html;
        location ~ .php$ 
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
        }    
    }
}
Vim /data/www/1.php

<?php
    echo "test php scripts.";
?>

curl localhost/1.php

test php scripts.

本文轉自 喵來個魚 51CTO部落格,原文連結:http://blog.51cto.com/m51cto/2070200,如需轉載請自行聯絡原作者


相關文章