千家信息网

LNMP编译安装( stable release)

发表于:2024-10-28 作者:千家信息网编辑
千家信息网最后更新 2024年10月28日,LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、
千家信息网最后更新 2024年10月28日LNMP编译安装( stable release)

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

Mysql是一个小型关系型数据库管理系统。

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。[1]

系统环境:

适合centos6.x x86_64位操作系统

源码编译安装方式优势:1、自定义软件功能2、优化编译参数,提高性能3、解决不必要的软件间依赖

一、下载解压源码包

1.mysql免编译二进制包下载并解压 (5.1.72)

2.php源码包下载并解压 (5.3.27)

3.nginx 源码包下载并解压(1.4.4)

[root@coderblog ~]#  wget -cP /usr/local/src   http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz[root@coderblog ~]#  cd /usr/local/src/ && tar -xzvf mysql-5.1.72-linux-x86_64-glibc23.tar.gz #下载并解压mysql免编译二进制包
[root@coderblog src]# wget -c http://mirrors.sohu.com/php/php-5.3.27.tar.gz [root@coderblog src]# tar -xzvf php-5.3.27.tar.gz #下载并解压php源码包
[root@coderblog src]# wget -c [root@coderblog src]# tar -xzvf nginx-1.4.4.tar.gz#下载并解压nginx源码包

二、安装

安装顺序mysql > php > nginx

1) mysql安装

[root@coderblog src]# mv mysql-5.1.72-linux-x86_64-glibc23 /usr/local/mysql#移动并重命名至/usr/local/mysql
[root@coderblog src]# useradd -s /sbin/nologin mysql#建立mysql账户
[root@coderblog src]# cd /usr/local/mysql[root@coderblog mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql[root@coderblog mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql#初始化数据库

--user 定义数据库的所属主, --datadir 定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。这一步骤很关键,如果你看到两个 "OK" 说明执行正确

[root@coderblog mysql]# cp support-files/my-large.cnf /etc/my.cnf#拷贝配置文件
[root@coderblog mysql]# cp support-files/mysql.server  /etc/init.d/mysqld[root@coderblog mysql]# chmod 755 /etc/init.d/mysqld#拷贝启动文件并赋予权限
[root@coderblog mysql]# vim /etc/init.d/mysqld#修改启动配置文件需要修改的地方有 "datadir=/data/mysql" (前面初始化数据库时定义的目录)               basedir=/usr/local/mysql
[root@coderblog mysql]# chkconfig --add mysqld #把启动脚本加入系统服务项[root@coderblog mysql]# chkconfig mysqld on #设定开机启动[root@coderblog mysql]# service mysqld start #启动mysql

2)php安装

[root@coderblog ~]# cd /usr/local/src/php-5.3.27 #切到刚刚解压php之后的目录
[root@coderblog php-5.3.27]# useradd -s /sbin/nologin php-fpm #创建相关用户[root@coderblog php-5.3.27]# yum install -y epel-release #安装epel扩展源[root@coderblog php-5.3.27]# yum -y install pcre pcre-devel apr apr-devel zlib-devel libxml2-devel  openssl openssl-devel bzip2 bzip2-devel  libpng libpng-devel  freetype freetype-devel  libmcrypt-devel gcc libcurl-devel libtool-ltdl-devel libjpeg libjpeg-devel libpng libpng-devel #安装所需环境[root@coderblog php-5.3.27]#./configure \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \--with-fpm-user=php-fpm \--with-fpm-group=php-fpm \--with-mysql=/usr/local/mysql \--with-mysql-sock=/tmp/mysql.sock \--with-libxml-dir \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-iconv-dir \--with-zlib-dir \--with-mcrypt \--enable-soap \--enable-gd-native-ttf \--enable-ftp \--enable-mbstring \--enable-exif \--disable-ipv6 \--with-pear \--with-curl \--with-openssl \--enable-sockets#配置编译参数如有报错信息可以百度下error信息,一般都会有答案. [root@coderblog php-5.3.27]# echo $?0#检测是否执行成功 非0则不成功[root@coderblog php-5.3.27]# make && make install
[root@coderblog php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini[root@coderblog php-5.3.27]# vim /usr/local/php/etc/php-fpm.conf#修改配置文件#把如下内容写入php-fpm.conf[global]pid = /usr/local/php/var/run/php-fpm.piderror_log = /usr/local/php/var/log/php-fpm.log[www]listen.user=php-fpm listen.group=php-fpmlisten.mode=0666listen = /tmp/php-fcgi.sockuser = php-fpmgroup = php-fpmpm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024

保存配置文件后,检验配置是否正确的方法为:

[root@coderblog php-5.3.27]# /usr/local/php/sbin/php-fpm -t


启动php-fpm

[root@coderblog php-5.3.27]# cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #拷贝启动文件[root@coderblog php-5.3.27]# chmod 755 /etc/init.d/php-fpm #赋予权限[root@coderblog php-5.3.27]# service php-fpm start #启动php服务

如果想让它开机启动,执行:

[root@coderblog php-5.3.27]# chkconfig php-fpm on

3)nginx安装

[root@coderblog ~]# cd /usr/local/src/nginx-1.4.4/ #切到刚刚解压nginx之后的目录
[root@coderblog nginx-1.4.4]# useradd -s /sbin/nologin www #创建相关用户


[root@coderblog nginx-1.4.4]# ./configure \--prefix=/usr/local/nginx \--with-http_realip_module \--with-http_sub_module \--with-http_gzip_static_module \--with-http_stub_status_module  \--with-pcre#配置编译参数[root@coderblog nginx-1.4.4]# make && make install #安装[root@coderblog nginx-1.4.4]# vim /etc/init.d/nginx #自定义nginx启动脚本将以下内容拷贝到文件并保存#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="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=1esacexit $RETVAL
[root@coderblog nginx-1.4.4]# chmod 755 /etc/init.d/nginx #赋予启动文件权限[root@coderblog nginx-1.4.4]# chkconfig --add nginx #加入开机启动项[root@coderblog nginx-1.4.4]# chkconfig nginx on #设置开机自动启动
[root@coderblog nginx-1.4.4]# > /usr/local/nginx/conf/nginx.conf #清空配置文件[root@coderblog nginx-1.4.4]# vim /usr/local/nginx/conf/nginx.conf#编辑nginx配置文件 并把以下内容拷贝到文件中user www www;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/logs/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 /usr/local/nginx/client_body_temp;    proxy_temp_path /usr/local/nginx/proxy_temp;    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;    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 /usr/local/nginx/html$fastcgi_script_name;    }}}
[root@coderblog ~]# /usr/local/nginx/sbin/nginx  -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful#如显示如上,则配置文件无误[root@coderblog ~]# service nginx start #启动nginx

至此LNMP环境就安装完成了,nginx虚拟主机位置在:/usr/local/nginx/html/


可以写个phpinfo.php 测试php解析情况

phpinfo();

?>


文件 配置 系统 服务 编译 源码 拷贝 数据 数据库 服务器 目录 软件 操作系统 内容 参数 权限 环境 脚本 成功 二进制 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 上海市网络安全管理的经验 共青团与网络安全 楚雄互联网科技招生 国家铁路局网络安全技术中心 登陆linux服务器命令 北京it软件开发的行业须知 四年级网络安全手抄报简单字少 如何在服务器中改成创造模式 如何创建数据库引擎 arcgis保存文字到数据库 计算机网络技术的规划书 数据库怎么设置字符串 如何写阿里巴巴的服务器程序 自己制造服务器可以打品牌吗 成人本科有没有招网络安全的 易语言使用数据库 黄浦区专业性软件开发哪家好 dayz服务器管理员怎么传送 网络安全ppt商务总结 tor代理服务器 国际软件开发工程师 云服务器比物理服务器稳定吗 怀旧服能交易的服务器 视频连接到服务器失败 国外网络技术大神 北汽eu5酷我音乐服务器错误 软件开发 mcu 深圳网络安全运维哪个品牌好 美团饿了么软件开发公司 网络技术应用提前通知
0