LNMP中的mysql,php,nginx安装

12.1-12.6 LNMP介绍,mysql,php,nginx安装。

LNMP

LNMP指的是linux,nginx,mysql和php。其中nginx取代了apache的作用。nginx相比于apache,他在静态资源的支持方面,速度比apache更快,且支持的并发访问量也更大,所以nginx的流行速度非常快。虽然目前市场份额并没有超过apache。

nginx也是开源软件,淘宝根据其业务特点在nginx的基础上开发了tengine用于阿里的业务。tengine在安全和限速方面表现突出,同时也支持js,css和图片的合并,可以减少请求数,提高网站的性能。

相比于LNMP,php作为apache的一个模块存在,他们必须安装在同一台主机上。但是LNMP的架构不一样,php作为一个独立的模块存在,负责连接mysql与nginx之间的通信。

这里写图片描述

一般来说,apache的主机只能支持4000个并发连接,但是nginx可以支持2-3万的并发连接。nginx在静态资源的支持上,速度比apache快,但是动态资源的支持还是不如apache。

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 //二进制包移到local/mysql目录下
 cd /usr/local/mysql
 useradd mysql
 mkdir /data/mysql
 ./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
 chmod 755 /etc/init.d/mysqld
 vim /etc/init.d/mysqld      //定义basedir和datadir

chkconfig --add mysqld  //添加服务
chkconfig mysqld on     //开机启动
service mysqld start    //开启服务

ps aux|grep mysqld  //查看进程是否已开启

php安装

 cd /usr/local/src/
 wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
 tar zxf php-5.6.30.tar.gz
 useradd php-fpm
 cd php-5.6.30
 ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc  //安装路径是/local/php-fpm,也多了一个--enable-fpm,不然不会有php-fpm文件生成
 --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-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 --with-pear --with-curl  --with-openssl

//出现报错
yum install libcurl libcurl-devel -y

echo $?
make
echo $?
make install

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  //复制启动脚本
chmod 755 /etc/init.d/php-fpm

cp php.ini-production /usr/local/php-fpm/etc/php.ini
vim /usr/local/php/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


/usr/local/php-fpm/sbin/php-fpm -t //测试配置是否正确

 chkconfig --add php-fpm
 chkconfig php-fpm on
 service php-fpm start
 ps aux |grep php-fpm //查看php-fpm是否已开启

安装nginx

nginx的版本更新很快,但是建议安装最近的stable版。

 cd /usr/local/src
 wget http://nginx.org/download/nginx-1.12.1.tar.gz
 tar zxf nginx-1.12.1.tar.gz
 ./configure --prefix=/usr/local/nginx
 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/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/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 /etc/init.d/nginx  //更改启动脚本的权限
chkconfig --add nginx
chkconfig nginx on 
vim /usr/local/nginx/conf/nginx.conf  
//添加以下内容
user nobody nobody;
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;
        }    
    }
}
/usr/local/nginx/sbin/nginx -t  //测试配置是否正确
service nginx start
ps aux|grep nginx

测试php是否正确解析

vim /usr/local/nginx/html/2.php
//添加如下内容
<?php
echo "test php";
?>

curl localhost/2.php
test php  //显示这条内容说明php解析成功
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您希望配置一个LNMP(Linux + Nginx + MySQL + PHP)环境,以下是一些基本步骤: 1. 安装Linux操作系统:选择适合您的需求的Linux发行版,并将其安装在服务器上。 2. 安装Nginx:使用软件包管理器(如apt、yum等)安装Nginx。例如,在Ubuntu上可以使用以下命令安装Nginx: ``` sudo apt update sudo apt install nginx ``` 3. 配置Nginx:根据您的需求编辑Nginx的配置文件。主要的配置文件是`/etc/nginx/nginx.conf`,您可以根据需要进行修改。确保您正确配置了Nginx的虚拟主机和反向代理等设置。 4. 安装MySQL:使用软件包管理器安装MySQL数据库。例如,在Ubuntu上可以使用以下命令安装MySQL: ``` sudo apt update sudo apt install mysql-server ``` 安装过程会提示您设置MySQL的root用户密码,请记住该密码。 5. 安装PHP:使用软件包管理器安装PHP及其相关扩展。例如,在Ubuntu上可以使用以下命令安装PHP及常用扩展: ``` sudo apt update sudo apt install php-fpm php-mysql ``` 6. 配置PHPNginx:编辑Nginx的虚拟主机配置文件(通常位于`/etc/nginx/sites-available/`目录下),将请求转发给PHP-FPM处理,确保PHP正确工作。 7. 重启服务:完成配置后,重启NginxPHP-FPM服务以使更改生效。 ``` sudo service nginx restart sudo service php-fpm restart ``` 这只是一个基本的LNMP环境配置概述,具体的配置细节和需求会因您的具体情况而异。您可以根据需要进一步定制和优化配置。希望这能帮到您!如果您有更多问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值