LNMP环境部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP环境部署相关的知识,希望对你有一定的参考价值。
构建LNMP网站平台
构建lnmp平台需要linux服务器,mysql数据库,php解析环境,区别主要在nginx与PHP协作配置上
一:部署nginx服务
1)安装支持软件
Nginx配置运行需要pcre,zlib 等软件包支持,因此预先安装这些软件的开发包,以提供相应库和文件,确保Nginx顺利完成
[[email protected] /]# yum -y install pcre-devel zlib-devel
1)创建运行用户组
[[email protected] /]# useradd -M -s /sbin/nologin nginx
1)编译安装Nginx
安装目录为/usr/local/nginx 运行用户和组均设置为Nginx启用http_stub_status_module模块支持状态统计,便于服务器连接情况。
[[email protected] src]# tar zxf nginx-1.6.2.tar.gz [[email protected] src]# cd nginx-1.6.2/ [[email protected] nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module [[email protected] nginx-1.6.2]# make && make install
为了使Nginx服务器运行方便,可以为主程序nginx创建连接文件
[[email protected] nginx-1.6.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [[email protected] nginx-1.6.2]# ls -l /usr/local/sbin/nginx lrwxrwxrwx. 1 root root 27 Mar 18 15:03 /usr/local/sbin/nginx -> /usr/local/nginx/sbin/nginx
二:Nginx运行控制
1)检查配置文件
与apache的主程序类似,Nginx主程序提供了 -t 选项用来对配置文件进行检查
[[email protected] nginx-1.6.2]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
1)启动 停止 nginx
直接运行Nginx即可启动Nginx服务器,使用默认配置文件,若要改其他配置文件,需要加-C配置文件路径
[[email protected] nginx-1.6.2]# nginx [[email protected] nginx-1.6.2]# netstat -anpt | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8002/nginx: master
三:访问状态统
Nginx 访问情况统计
Location /status //访问位置为:/status
Stub_status on; //打开状态统计功能
Access_log off; //关闭此位置日志记录
四 Mysql安装步骤
[[email protected] src]# yum -y install ncurses-devel [[email protected] cmake-2.8.12]# ./configure && make && make install [[email protected] mysql-5.5.38]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYCONFDIR=/etc/ [[email protected] mysql-5.5.38]# make && make install [[email protected] mysql-5.5.38]# cp support-files/my-medium.cnf /etc/my.cnf [[email protected] mysql-5.5.38]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql-5.5.38]# chmod +x /etc/rc.d/init.d/mysqld [[email protected] mysql-5.5.38]# chkconfig --add mysqld [[email protected] mysql-5.5.38]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile [[email protected] mysql-5.5.38]# . /etc/profile
初始化数据库
[[email protected] mysql-5.5.38]# groupadd mysql [[email protected] mysql-5.5.38]# useradd -M -s /sbin/nologin mysql -g mysql [[email protected] mysql-5.5.38]# chown -R mysql:mysql /usr/local/mysql [[email protected] mysql-5.5.38]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql [[email protected] mysql-5.5.38]# service mysqld start [[email protected] mysql-5.5.38]# mysqladmin -u root password '123456'
五 安装php解析环境
[[email protected] conf]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel [[email protected] src]# tar zxf php-5.3.28.tar.gz [[email protected] src]# cd php-5.3.28/ [[email protected] php-5.3.28]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib [[email protected] php-5.3.28]# make && make install
安装后调整
[[email protected] php-5.3.28]# cp php.ini-development /usr/local/php5/php.ini [[email protected] php-5.3.28]# ln -s /usr/local/php5/bin/* /usr/local/bin/ [[email protected] php-5.3.28]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
配置Nginx支持php环境
[[email protected] php-5.3.28]# cd /usr/local/php5/etc/ [[email protected] etc]# cp php-fpm.conf.default php-fpm.conf [[email protected] etc]# useradd -M -s /sbin/nologin php [[email protected] etc]# vim php-fpm.conf
pid = run/php-fpm.pid 确认pid文件位置
user = php 运行用户
group = php 运行组
pm.start_servers = 20 启动开启进程数
pm.min_spare_servers = 5 最少空闲进程数
pm.max_spare_servers = 35
pm.max_children = 50
[[email protected] etc]# /usr/local/sbin/php-fpm [[email protected] etc]# netstat -anpt | grep php-fpm tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 12575/php-fpm: mast
支持nginx解析php
测试访问php情况
以上是关于LNMP环境部署的主要内容,如果未能解决你的问题,请参考以下文章