码迷,mamicode.com
首页 > 其他好文 > 详细

lnmp部署以及相关应用

时间:2016-08-15 22:42:15      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:lnmp   nginx   

lnmp实现多个虚拟主机,部署wordpress和phpmyadmin,并为后一个主机提供https;


1yum安装部署

 

安装nginx

[root@luffy yum.repos.d]# vim nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

[root@luffy ~]# yum install -y nginx

安装php

[root@luffy ~]# yum install php-fpm -y

[root@luffy ~]# vim /etc/php-fpm.d/www.conf

listen = 127.0.0.1:9000   

user = nginx

group = nginx

 

配置nginx对接php,把nginx 通过fastcgi作为fastcgi的客户端,将php网页反向代理给fastcgi服务端

[root@luffy ~]# vim /etc/nginx/nginx.conf

worker_processes  3;

gzip  on;

include /etc/nginx/conf.d/*.conf;

[root@luffy ~]# vim /etc/nginx/conf.d/default.conf

index  index.php index.html index.htm;

root   /data/www

location ~ \.php$ {

        root           /data/www;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /data/www/$fastcgi_script_name;

        include        fastcgi_params; 

    }  

[root@luffy ~]# mkdir -p /data/www

[root@luffy ~]# nginx -t

[root@luffy ~]# nginx

[root@luffy ~]# systemctl start php-fpm.service

测试nginxphp的连接

[root@luffy ~]# vim /data/www/index.php

<?php

        phpinfo();

?>

技术分享

安装mariadbphpmaridb之间的驱动

[root@luffy html]# yum install mariadb-server php-mysql -y

[root@luffy html]# systemctl start mariadb

MariaDB [(none)]> grant all on *.* to zou@‘localhost‘ identified by ‘123.comer‘;

MariaDB [(none)]> create database wordpress;

MariaDB [(none)]> grant all on wordpress.* to ‘wpuser‘@‘localhost‘ identified by ‘wppasswd‘;

MariaDB [(none)]> flush privileges;

[root@luffy ~]# vim /data/www/index.php

<?php

   $conn=mysql_connect(‘localhost‘,‘zou‘,‘123.comer‘);

   if($conn)

echo "web is ok";

   else

echo fault;

   mysql_close();

   phpinfo();

?>

[root@luffy html]# systemctl reload php-fpm

技术分享

[root@luffy html]# yum install httpd-tools -y

[root@luffy html]# ab -c 100 -n 1000 http://172.16.1.1/index.php        (在没有缓存的情况下是1450)

 

准备搭建wordpress

wordpress下载下来,并解压缩到/data/www目录下面

[root@luffy wordpress]# pwd

/data/www/wordpress

[root@luffy wordpress]# cp wp-config-sample.php wp-config.php

[root@luffy wordpress]# vim wp-config.php

define(‘DB_NAME‘, ‘wordpress‘);

define(‘DB_USER‘, ‘wpuser‘);

define(‘DB_PASSWORD‘, ‘wppasswd‘);

define(‘DB_HOST‘, ‘localhost‘);

在浏览器键入:http://172.16.1.1/wordpress/

技术分享

之后输入已经设定好的网页版的管理者zou和密码

技术分享

准备设置phpmyadmin

[root@luffy phpmyadmin]# pwd

/data/www/phpmyadmin

[root@luffy phpmyadmin]# vim libraries/config.default.php

$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘;

$cfg[‘Servers‘][$i][‘user‘] = ‘zou‘;

$cfg[‘Servers‘][$i][‘password‘] = ‘123.comer‘;

[root@luffy phpmyadmin]# yum install php-mbstring

[root@luffy html]# systemctl reload php-fpm

[root@luffy phpmyadmin]# nginx -s reload

在浏览器输入http://172.16.1.1/phpmyadmin

技术分享

有错,php.inisession问题

[root@luffy php]# vim /etc/php.ini

session.use_cookies = 1

session.save_path = "/tmp"

在phpmyadmin中找到,config.sample.inc.php,改成config.inc.php,找到 $cfg[‘blowfish_secret‘] 将后面的赋值,加入数字和字母组合(最好位数在16位左右)

[root@luffy php]# mkdir /var/lib/php/session

[root@luffy php]# chmod 777 /var/lib/php/session/

[root@luffy php]# nginx -s reload

[root@luffy php]# systemctl reload php-fpm

技术分享

2)编译安装LNMP

# yum groupinstall "Development Tools" "Server Platform Development" -y

gzip模块需要zlib库,rewrite模块需要pcre库,ssl功能需要openssl,所以要安装

# yum install pcre-devel zlib-devel openssl-devel  -y

# useradd -r nginx

[root@localhost src]# tar zxvf nginx-1.10.1.tar.gz

[root@localhost src]# cd nginx-1.10.1/

# ./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 --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module  --with-http_stub_status_module --with-threads --with-file-aio

# make -j 4

#  make install

#  nginx -t   检查语法

# nginx -s {stop|start|reopen|reload}  进程的管理

 

mariadb客户端编译安装服务

(这里实际上并算不上是编译安装,mariadb压缩包解压完之后就可以安装,二进制格式安装)

[root@zou src]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz

[root@zou src]# mv mariadb-5.5.46-linux-x86_64 /usr/local/mysql

[root@localhost local]# useradd -r mysql

[root@localhost local]# cd /usr/local/mysql/

[root@localhost mysql]# chown -R root:mysql ./*

[root@localhostmysql]# ll

[root@localhost mysql]# mkdir -p /data/mariadb

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mariadb

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# support-files/my-large.cnf  /etc/my.cnf

[root@localhost ~]#  vim /etc/my.cnf

添加三个选项:

datadir = /data/mariadb

innodb_file_per_table = ON

skip_name_resolve = ON

[root@localhost ~]# /etc/init.d/mysqld start

Starting MySQL.. SUCCESS!

[root@localhost ~]# ss -ntlp    查看3306端口

[root@localhost ~]# /usr/local/mysql/bin/mysql  可以登录即可

MariaDB [(none)]> grant all on *.* to ‘zou‘@‘%‘ identified by ‘123.comer‘;

MariaDB [(none)]> flush privileges;

 

编译安装php

[root@haizei src]# yum install mariadb mariadb-devel

[root@haizei src]# yum install libxml2-devel gd-devel freetype-devel libmcrypt-devel

[root@haizei php-5.4.40]# mkdir /usr/lib/mysql

[root@haizei php-5.4.40]# cp -r /usr/lib64/mysql/* /usr/lib/mysql/

 

[root@haizei php54]# ./configure --prefix=/usr/local/php54 --with-mysql=/usr --with-openssl --with-mysqli=/usr/bin/mysql_config --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --enable-fpm  --with-config-file-path=/etc/php54/php.ini --with-config-file-scan-dir=/etc/php54/php.d

 

[root@haizei php-5.4.40]# make -j 2

[root@haizei php-5.4.40]# make install

[root@haizei php54]# cd /usr/local/php54

[root@haizei php54]# cp etc/php-fpm.conf.default etc/php-fpm.conf

[root@haizei php54]# vim etc/php-fpm.conf

listen = 127.0.0.1:9000    (如果对外响应也可以写上主机的ip加上9000端口)

user = nginx

group = nginx

[root@haizei php54]# sbin/php-fpm   启动服务 如果关闭就用pkill php-fpm

[root@haizei php54]# ss -ntlp     查看监听的服务

 

[root@localhost php54]# vim /etc/nginx/nginx.conf

location / {

            root   /data/www;

            index  index.php index.html index.htm;

        }

location ~ \.php$ {

            root           /data/www;

            fastcgi_pass   127.0.0.1:9000;  如果php服务端不在本地,那就要写phpip和端口了

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /data/www/$fastcgi_script_name;

            include        fastcgi_params;

        }

[root@localhost php54]# mkdir -p /data/www

[root@localhost php54]# vim /data/www/index.php

[root@localhost php54]# iptables -F

[root@localhost php54]# setenforce 0

[root@localhost php54]# nginx -s reload

技术分享

技术分享


本文出自 “北极的linux” 博客,请务必保留此出处http://941012521.blog.51cto.com/9253690/1838720

lnmp部署以及相关应用

标签:lnmp   nginx   

原文地址:http://941012521.blog.51cto.com/9253690/1838720

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!