435421 发表于 2016-4-25 09:14:58

LNMP新版安装

首先安装nginx,nginx已完成



第二安装mysql



# tar zxf mysql-5.5.38.tar.gz-C /usr/src/

# cd /usr/src/

# mvmysql-5.5.32-linux2.6-x86_64/ /application/

# cd /application/

# ln -s mysql-5.5.32-linux2.6-x86_64/mysql

# mkdir -p /application/mysql/data/

# chown-R mysql.mysql /application/mysql

# cd /application/mysql

# /bin/cp support-files/my-small.cnf/etc/my.cnf

初始化mysql



# /application/mysql/scripts/mysql_install_db--basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql





配置并启动mysql数据库

# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe   /etc/init.d/mysqld

# /etc/init.d/mysqld start

Starting MySQL...                                          [确定]

# ps -ef | grep 3306

mysql   295827152 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      298424750 02:17 pts/5    00:00:00 grep 3306





查看mysql启动日志



# tail /application/mysql/data/www.xiaohu.com.err

InnoDB: Creating foreign key constraint system tables

InnoDB: Foreign key constraint system tables created

1604162:17:34InnoDB: Waiting for the background threads to start

1604162:17:35 InnoDB: 5.5.32 started; log sequence number 0

1604162:17:35 Server hostname (bind-address): '0.0.0.0'; port: 3306

1604162:17:35    - '0.0.0.0' resolves to '0.0.0.0';

1604162:17:35 Server socket created on IP: '0.0.0.0'.

1604162:17:35 Event Scheduler: Loaded 0 events

1604162:17:35 /application/mysql/bin/mysqld: ready for connections.

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





添加服务设置开机并启动

# chkconfig --add mysqld

# chkconfigmysqld on











登录mysql测试

# 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不是,他是通过一个工具,fastcgi和php进行连接

,达到动态的效果





Fastcgi安装







首先测试nginx是否成功

# 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

正在保存至: “index.html.1”



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



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





测试没问题,开始安装



安装依赖包lib 和zlib





安装libmcrypt库和mhash库

直接./configure make make install



做软连接

# ln -s /usr/local/lib/libmcrypt.* /usr/lib

# ln -s /usr/local/lib/libmhash.* /usr/lib





安装php

# tar zxf php-5.3.28.tar.gz-C /usr/src/

# cd /usr/src/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



# cp php.ini-production/application/php/lib/php.ini

# cp php-fpm.conf.default php-fpm.conf



启动php-fpm

# /application/php/sbin/php-fpm

查看端口

# netstat -nlp | grep php-fpm

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





# lsof-i :9000

COMMAND   PIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME

php-fpm 53674root    7uIPv4 121088      0t0TCP localhost:cslistener (LISTEN)

php-fpm 53675 nginx    0uIPv4 121088      0t0TCP localhost:cslistener (LISTEN)

php-fpm 53676 nginx    0uIPv4 121088      0t0TCP localhost:cslistener (LISTEN)





Ok php-fpm启动一切正常



现在开始配置nginx 支持php

# vim /application/nginx/conf/nginx.conf



server {

      listen       80;

      server_namewww.xiaohu.com;

      location / {

            root   html;

            indexindex.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网页测试







# echo "<?php phpinfo(); ?>">test_info.php



访问192.168.1.110:test_info.php







spacer.gif



Ok测试成功



接下来测试php连接mysql服务



修改test.info.php

# 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目录下解压

# cp wordpress-4.5.tar.gz/application/nginx/html/

# tar zxf wordpress-4.5.tar.gz

# ls -l

总用量 7604

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

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

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

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

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

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

删除没用的文件

# rm -rf 50x.htmlqiqi/ wordpress-4.5.tar.gztest_info.php





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

# mv wordpress/* .



Ok

开始访问

http://192.168.1.110/index.php



一步一步创建 ok完成
页: [1]
查看完整版本: LNMP新版安装