Centos6.7 源码安装LNMP

centos 源码安装nginx(1.10)、mysql(5.6) PHP(7.0)


关闭SELINUX和防火墙
  • 修改配置文件,重启服务后永久生效
# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
  • 命令行设置立即生效
# setenforce 0
  • 关闭防火墙
# service iptables stop
# chkconfig iptables off 
安装nginx
  • 添加运行nginx服务进程的用户
# groupadd -r nginx    
# useradd -r -g nginx  nginx
  • 下载源码包解压编译
# cd /usr/local/src
# wget http://nginx.org/download/nginx-1.10.2.tar.gz
# tar xvf nginx-1.10.2.tar.gz
# yum groupinstall "Development tools"
# yum -y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
# cd /usr/local/src/nginx-1.10.2
# ./configure \
--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 \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
# make && make install
# mkdir -pv /var/tmp/nginx/client
  • 添加SysV启动脚本
# vim /etc/init.d/nginx
#!/bin/sh 
# 
# nginx - this script starts and stops the nginx daemon 
# 
# chkconfig:   - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
#               proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config:      /etc/nginx/nginx.conf 
# config:      /etc/sysconfig/nginx 
# pidfile:     /var/run/nginx.pid 
# Source function library. 
. /etc/rc.d/init.d/functions
# Source networking configuration. 
. /etc/sysconfig/network
# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: " 
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo 
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: " 
    killproc $prog -QUIT
    retval=$?
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
killall -9 nginx
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: " 
    killproc $nginx -HUP
RETVAL=$?
    echo 
}
force_reload() {
    restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
    $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
      echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
        exit 2
esac
  • 赋予脚本执行权限
# chmod +x /etc/init.d/nginx
  • 设置开机自启动
# chkconfig --add nginx
# chkconfig  nginx on
# service nginx start
安装mysql
  • 准备编译环境
# yum groupinstall "Server Platform Development"  "Development tools" -y
# yum install cmake -y
  • 准备mysql存放目录
# mkdir /mnt/data
# groupadd -r mysql
# useradd -r -g mysql -s /sbin/nologin mysql
# id mysql
uid=497(mysql) gid=497(mysql) groups=497(mysql)
  • 更改数据目录属主属组
# chown -R mysql:mysql /mnt/data
  • 编译mysql
# cd /usr/local/src/
# wget https://www.mysql.com//Downloads/MySQL-5.6/mysql-5.6.24.tar.gz
# tar xvf mysql-5.6.24.tar.gz
# cd mysql-5.6.24
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mnt/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DWITH_BOOST=/usr/local/boost \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DMYSQL_USER=mysql \
-DWITH_READLINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci
# make && make install
  • 修改安装目录的属组为mysql
# chown -R mysql:mysql /usr/local/mysql/
  • 初始化数据库
# cd /usr/local/mysql/
# scripts/mysql_install_db --user=mysql --datadir=/mnt/data/
  • 拷贝配置文件和启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# cp support-files/my-default.cnf /etc/my.cnf
  • 设置开机自动启动
# chkconfig mysqld  on 
# chkconfig --add mysqld
  • 修改配置文件中的安装路径及数据目录存放路径
# echo -e "basedir = /usr/local/mysql\ndatadir = /mnt/data\n" >> /etc/my.cnf
  • 设置PATH环境变量
# echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
# source /etc/profile.d/mysql.sh
  • 启动服务
# service mysqld start 
  • 修改数据库密码及配置远程访问
# mysql -h 127.0.0.1
use mysql;
update user set password=PASSWORD('123456') where user='root';
# 退出重新登陆
mysql -u root -p
use mysql;
 update user set host = '%' where user = 'root' and host='127.0.0.1';
 grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; //给用户授权
 flush privileges;
安装PHP
  • 安装包依赖
# yum -y install libxml2 libxml2-devel curl-devel libpng-devel freetype-devel libmcrypt-devel libjpeg-devel bzip2 bzip2-devel gmp-devel install readline-devel

注:当yum源中没有libmcrypt-devel时,先装yum install -y epel-release 在执行yum install -y libmcrypt-devel

  • 下载源码并安装php
# cd /usr/local/src/
# wget http://cn2.php.net/distributions/php-7.0.14.tar.gz
# tar xvf php-7.0.14
# cd php-7.0.14
# ./configure \
--prefix=/usr/local/php \
--with-config-file-scan-dir=/etc/php.d \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
# make && make install
  • 添加php和php-fpm配置文件
# cp /usr/local/src/php-7.0.14/php.ini-production /etc/php.ini
# cd /usr/local/php/etc/
# cp php-fpm.conf.default php-fpm.conf
# cd php-fpm.init.d
# cp www.conf.default  www.conf
  • 添加php-fpm启动脚本
# cp /usr/local/src/php-7.0.14/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
  • 添加php-fpm至服务列表并设置开机自启
# chkconfig --add php-fpm     
# chkconfig php-fpm on
  • 启动服务
# service php-fpm start
  • 添加nginx对fastcgi的支持,首先备份默认的配置文件
# cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
  • 编辑/etc/nginx/nginx.conf
location / {
            root   /usr/local/nginx/html;
            index  index.php index.html index.htm;
        }
location ~ \.php$ {
            root           /usr/local/nginx/html;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
        }
  • 重新载入nginx的配置文件
# service nginx reload
  • 在/usr/local/nginx/html/新建index.php的测试页面
<?php
$conn=mysqli_connect('127.0.0.1','root','123456');
if ($conn){
  echo "LNMP platform connect to mysql is successful!";
}else{
  echo "LNMP platform connect to mysql is failed!";
}
 phpinfo();
?>
  • 开启错误提示
# vim /etc/php.ini
display_errors = On;
error_reporting = E_ALL;
# vim /usr/local/php/etc/php-fpm.init.d/www.conf
php_flag[display_errors] = on
  • 重启服务
# service nginx restart
# service php-fpm restart
  • 配置php到环境变量
#  vim /etc/profile
# 在文件最后添加
PATH=$PATH:/usr/local/php/bin
export PATH
#保存退出
source /etc/profile
php -v
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值