首页 > 其他 > 详细

LNMP新版安装

时间:2016-04-25 01:06:05      阅读:304      评论:0      收藏:0      [点我收藏+]

            

                      LNMP环境

首先安装nginxnginx已完成

 

第二安装mysql

 

[root@www mnt]# tar zxf mysql-5.5.38.tar.gz  -C /usr/src/

[root@www ~]# cd /usr/src/

[root@www src]# mv  mysql-5.5.32-linux2.6-x86_64/ /application/

[root@www src]# cd /application/

[root@www application]# ln -s mysql-5.5.32-linux2.6-x86_64/  mysql

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

[root@www ~]# chown  -R mysql.mysql /application/mysql

[root@www ~]# cd /application/mysql

[root@www mysql]# /bin/cp support-files/my-small.cnf  /etc/my.cnf

初始化mysql

 

[root@www mysql]# /application/mysql/scripts/mysql_install_db  --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql

 

 

配置并启动mysql数据库

[root@www mysql]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe   /etc/init.d/mysqld

[root@www mysql]# /etc/init.d/mysqld start

Starting MySQL...                                          [确定]

[root@www mysql]# ps -ef | grep 3306

mysql     2958  2715  2 02:17 pts/5    00:00:00 /application/mysql/bin/mysqld --basedir=/application/mysql --datadir=/application/mysql/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/www.xiaohu.com.err --pid-file=/application/mysql/data/www.xiaohu.com.pid --socket=/tmp/mysql.sock --port=3306

root      2984  2475  0 02:17 pts/5    00:00:00 grep 3306

 

 

查看mysql启动日志

 

[root@www mysql]# tail /application/mysql/data/www.xiaohu.com.err

InnoDB: Creating foreign key constraint system tables

InnoDB: Foreign key constraint system tables created

160416  2:17:34  InnoDB: Waiting for the background threads to start

160416  2:17:35 InnoDB: 5.5.32 started; log sequence number 0

160416  2:17:35 [Note] Server hostname (bind-address): ‘0.0.0.0‘; port: 3306

160416  2:17:35 [Note]   - ‘0.0.0.0‘ resolves to ‘0.0.0.0‘;

160416  2:17:35 [Note] Server socket created on IP: ‘0.0.0.0‘.

160416  2:17:35 [Note] Event Scheduler: Loaded 0 events

160416  2:17:35 [Note] /application/mysql/bin/mysqld: ready for connections.

Version: ‘5.5.32‘  socket: ‘/tmp/mysql.sock‘  port: 3306  MySQL Community Server (GPL)

 

 

添加服务设置开机并启动

[root@www mysql]# chkconfig --add mysqld

[root@www mysql]# chkconfig  mysqld on

 

 

 

 

 

登录mysql测试

[root@www ~]# mysql

mysql> select user,host from mysql.user;  查看当前用户

+------+----------------+

| user | host           |

+------+----------------+

| root | 127.0.0.1      |

| root | ::1            |

|      | localhost      |

| root | localhost      |

|      | www.xiaohu.com |

| root | www.xiaohu.com |

+------+----------------+

6 rows in set (0.00 sec)

 

 

 

OK Mysql服务器已经安装完成

现在开始php安装

 

 

FASCGI介绍:

什么是fastcgi

FastCGI nginx 动态网站的一个工具,他是进程是php-fpm,因为咱们之前的LAMP apache是自带php动态接口,但是nginx不是,他是通过一个工具,fastcgiphp进行连接

,达到动态的效果

 

 

Fastcgi安装

 

 

 

首先测试nginx是否成功

[root@www ~]# wget 192.168.1.110

--2016-04-16 02:54:55--  http://192.168.1.110/

正在连接 192.168.1.110:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:74 [text/html]

正在保存至: index.html.1

 

100%[=============================================================================================>] 74          --.-K/s   in 0.06s   

 

2016-04-16 02:54:55 (1.30 KB/s) - 已保存 “index.html.1[74/74])

 

 

测试没问题,开始安装

 

安装依赖包lib zlib

 

 

安装libmcrypt库和mhash

直接./configure make make install

 

做软连接

[root@www ~]# ln -s /usr/local/lib/libmcrypt.* /usr/lib

[root@www ~]# ln -s /usr/local/lib/libmhash.* /usr/lib

 

 

安装php

[root@www mnt]# tar zxf php-5.3.28.tar.gz  -C /usr/src/

[root@www mnt]# cd /usr/src/php-5.3.28/

 

编译

[root@www php-5.3.28]# ./configure  --prefix=/application/php --with-mcrypt   --with-mysql=/application/mysql --with-config-file-path=/application/php  --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx   && make && makeinstall

 

出现这个提示表示正确

 

Installing PDO headers:          /application/php/include/php/ext/pdo/

 

拷贝php文件到php默认目录,改名php.ini

 

[root@www php-5.3.28]# cp php.ini-production  /application/php/lib/php.ini

[root@www etc]# cp php-fpm.conf.default php-fpm.conf

 

启动php-fpm

[root@www etc]# /application/php/sbin/php-fpm

查看端口

[root@www etc]# netstat -nlp | grep php-fpm

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      53674/php-fpm.conf)

 

 

[root@www etc]# lsof  -i :9000

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

php-fpm 53674  root    7u  IPv4 121088      0t0  TCP localhost:cslistener (LISTEN)

php-fpm 53675 nginx    0u  IPv4 121088      0t0  TCP localhost:cslistener (LISTEN)

php-fpm 53676 nginx    0u  IPv4 121088      0t0  TCP localhost:cslistener (LISTEN)

 

 

Ok php-fpm启动一切正常

 

现在开始配置nginx 支持php

[root@www html]# vim /application/nginx/conf/nginx.conf

 

 server {

        listen       80;

        server_name  www.xiaohu.com;

        location / {

            root   html;

            index  index.html index.htm;

        }

        location ~ .*\.(php|php5)?$ {

            root   html;

            fastcgi_pass 127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }

        }

添加php

重启nginx服务

 

 

成功后添加一个测试的php网页测试

 

 

 

[root@www html]# echo "<?php phpinfo(); ?>"  >test_info.php

 

访问192.168.1.110test_info.php

 

 

 

技术分享

 

Ok测试成功

 

接下来测试php连接mysql服务

 

修改test.info.php

[root@www html]# cat test_info.php

<?php

 //$link_id=mysql_connect(‘主机名‘,‘用户名‘,‘密码‘);

 $link_id=mysql_connect(‘localhost‘,‘root‘,‘123.com‘) or mysql_error();

//$link_id=mysql_connect(‘‘,‘‘,‘‘);

if ($link_id) {

echo "mysql success for by oldboy";

}

else {

echo "mysql_error";

}

//php单行注释

/ * php多行注释

 

测试访问test.info.php

 

mysql success for by oldboy

访问成功

 

OK 现在lnmp 部署环境已经完成

 

 

现在开始部署网站

 

首先我们需要一个自己的blog模板

我在这里就用网上的wordpress免费的模板

下载地址:https://wordpress.org/download/

 

 

Mysql 准备 创建一个wordpress 的数据库,用来存放网站的数据

mysql> create database wordpress;

Query OK, 1 row affected (0.00 sec)

 

 

创建一个管理用户

mysql> grant all on wordpress.* to wordpress@‘localhost‘ identified by ‘123.com‘;

Query OK, 0 rows affected (0.03 sec)

查看用户

mysql> select user,host from mysql.user;

+-----------+----------------+

| user      | host           |

+-----------+----------------+

| root      | 127.0.0.1      |

| root      | ::1            |

|           | localhost      |

| root      | localhost      |

| wordpress | localhost      |

| workpress | localhost      |

|           | www.xiaohu.com |

| root      | www.xiaohu.com |

+-----------+----------------+

8 rows in set (0.00 sec)

 

 

 

 

 

 

Ok账户存在

 

现在开始获取workpress的程序

 

把程序转移到html目录下解压

[root@www ~]# cp wordpress-4.5.tar.gz  /application/nginx/html/

[root@www html]# tar zxf wordpress-4.5.tar.gz

[root@www html]# ls -l

总用量 7604

-rw-r--r--. 1 root   root          537  4月 15 18:13 50x.html

-rw-r--r--. 1 root   root           74  4月 15 18:19 index.html

drwxr-xr-x. 2 root   root         4096  4月 15 18:31 qiqi

-rw-r--r--. 1 root   root          260  4月 16 04:32 test_info.php

drwxr-xr-x. 5 nobody nfsnobody    4096  4月 13 02:46 wordpress

-rw-r--r--. 1 root   root      7762865  4月 16 04:50 wordpress-4.5.tar.gz

删除没用的文件

[root@www html]# rm -rf 50x.html  qiqi/ wordpress-4.5.tar.gz  test_info.php

 

 

将workpress目录下所有文件复制到根目录下

[root@www blog]# mv wordpress/* .

 

Ok

开始访问

http://192.168.1.110/index.php

 

一步一步创建 ok完成

技术分享 


LNMP新版安装

原文:http://10966380.blog.51cto.com/10956380/1767317

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!