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


1yum安装部署

 

安装nginx

[[email protected] yum.repos.d]# vim nginx.repo

[nginx]

name=nginx repo

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

gpgcheck=0

enabled=1

[[email protected] ~]# yum install -y nginx

安装php

[[email protected] ~]# yum install php-fpm -y

[[email protected] ~]# vim /etc/php-fpm.d/www.conf

listen = 127.0.0.1:9000   

user = nginx

group = nginx

 

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

[[email protected] ~]# vim /etc/nginx/nginx.conf

worker_processes  3;

gzip  on;

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

[[email protected] ~]# 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; 

    }  

[[email protected] ~]# mkdir -p /data/www

[[email protected] ~]# nginx -t

[[email protected] ~]# nginx

[[email protected] ~]# systemctl start php-fpm.service

测试nginxphp的连接

[[email protected] ~]# vim /data/www/index.php

<?php

        phpinfo();

?>

lnmp部署以及相关应用

安装mariadbphpmaridb之间的驱动

[[email protected] html]# yum install mariadb-server php-mysql -y

[[email protected] html]# systemctl start mariadb

MariaDB [(none)]> grant all on *.* to [email protected]'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;

[[email protected] ~]# 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();

?>

[[email protected] html]# systemctl reload php-fpm

lnmp部署以及相关应用

[[email protected] html]# yum install httpd-tools -y

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

 

准备搭建wordpress

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

[[email protected] wordpress]# pwd

/data/www/wordpress

[[email protected] wordpress]# cp wp-config-sample.php wp-config.php

[[email protected] 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/

lnmp部署以及相关应用

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

lnmp部署以及相关应用

准备设置phpmyadmin

[[email protected] phpmyadmin]# pwd

/data/www/phpmyadmin

[[email protected] phpmyadmin]# vim libraries/config.default.php

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

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

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

[[email protected] phpmyadmin]# yum install php-mbstring

[[email protected] html]# systemctl reload php-fpm

[[email protected] phpmyadmin]# nginx -s reload

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

lnmp部署以及相关应用

有错,php.inisession问题

[[email protected] 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位左右)

[[email protected] php]# mkdir /var/lib/php/session

[[email protected] php]# chmod 777 /var/lib/php/session/

[[email protected] php]# nginx -s reload

[[email protected] php]# systemctl reload php-fpm

lnmp部署以及相关应用

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

[[email protected] src]# tar zxvf nginx-1.10.1.tar.gz

[[email protected] 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压缩包解压完之后就可以安装,二进制格式安装)

[[email protected] src]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz

[[email protected] src]# mv mariadb-5.5.46-linux-x86_64 /usr/local/mysql

[[email protected] local]# useradd -r mysql

[[email protected] local]# cd /usr/local/mysql/

[[email protected] mysql]# chown -R root:mysql ./*

[[email protected]mysql]# ll

[[email protected] mysql]# mkdir -p /data/mariadb

[[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mariadb

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql]# support-files/my-large.cnf  /etc/my.cnf

[[email protected] ~]#  vim /etc/my.cnf

添加三个选项:

datadir = /data/mariadb

innodb_file_per_table = ON

skip_name_resolve = ON

[[email protected] ~]# /etc/init.d/mysqld start

Starting MySQL.. SUCCESS!

[[email protected] ~]# ss -ntlp    查看3306端口

[[email protected] ~]# /usr/local/mysql/bin/mysql  可以登录即可

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

MariaDB [(none)]> flush privileges;

 

编译安装php

[[email protected] src]# yum install mariadb mariadb-devel

[[email protected] src]# yum install libxml2-devel gd-devel freetype-devel libmcrypt-devel

[[email protected] php-5.4.40]# mkdir /usr/lib/mysql

[[email protected] php-5.4.40]# cp -r /usr/lib64/mysql/* /usr/lib/mysql/

 

[[email protected] 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

 

[[email protected] php-5.4.40]# make -j 2

[[email protected] php-5.4.40]# make install

[[email protected] php54]# cd /usr/local/php54

[[email protected] php54]# cp etc/php-fpm.conf.default etc/php-fpm.conf

[[email protected] php54]# vim etc/php-fpm.conf

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

user = nginx

group = nginx

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

[[email protected] php54]# ss -ntlp     查看监听的服务

 

[[email protected] 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;

        }

[[email protected] php54]# mkdir -p /data/www

[[email protected] php54]# vim /data/www/index.php

[[email protected] php54]# iptables -F

[[email protected] php54]# setenforce 0

[[email protected] php54]# nginx -s reload

lnmp部署以及相关应用

lnmp部署以及相关应用