标签:
一、准备工作
需要的安装包都是从官网下载的,系统centos6.6
nginx-1.10.1.tar.gz
php-5.6.24.tar.gz
mysql-5.5.32.tar.gz
所有的包都一传入/var/opt/lnmp/中
1、由于是虚拟机所以很放心的更新了一下系统
bash> yum update
二、安装nginx
1、安装相关软件包
bash> yum -y install zlib zlib-devel openssl openssl-devel pcre-devel cc-c++ autoconf automake
bash>
yum
-y install gcc automake autoconf libtool make pcre* openssl* zlib
zlib-devel bzip2-devel
2解压文件
bash>
tar
zxvf nginx-1.10.1
bash>
cd
nginx-1.10.1
3编译安装
bash> ./configure \
--prefix=/usr/local/lnmp/nginx-1.10.1
\
--with-http_ssl_module
\
--with-http_flv_module
\
--with-http_gzip_static_module
\
--http-log-path=/var/log/nginx/access.log
\
--http-client-body-temp-path=/var/tmp/nginx/client
\
--http-proxy-temp-path=/var/tmp/nginx/proxy
\
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi
\
--with-http_stub_status_module
bash> make && make install
4创建缺少的目录
bash> mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
5、编辑conf/nginx.conf,将#[user nobody]改为[user root]
bash> vim /usr/local/lnmp/nginx-1.10.1/conf/nginx.conf
6、 编辑conf/nginx.conf,打开php支持
bash> vim /usr/local/lnmp/nginx-1.10.1/conf/nginx.conf
7、建立软连接
bash> ln -s /usr/local/lnmp/nginx-1.10.1/sbin/nginx .
8、启动nginx
bash> nginx
9、打开浏览器输入ip查看nginx结果
三、安装php
1、添加扩展源
bash> yum install epel-release
bash> yum update
2、安装相关软件包
bash> yum install libmcrypt libmcrypt-devel mcrypt mhash -y
bash> yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
3、解压文件
bash> tar zxvf php-5.6.24.tar.gz
bash> cd php-5.6.24
4、编译安装
bash> ./configure --prefix=/usr/local/lnmp/php-5.6.24 \
--enable-fpm --with-mcrypt --enable-mbstring \
--disable-pdo --with-curl --disable-debug \
--disable-rpath --enable-inline-optimization \
--with-bz2 --with-zlib --enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-pcntl \
--enable-mbregex --with-mhash --enable-zip \
--with-pcre-regex --with-mysql --with-mysqli \
--with-gd --with-jpeg-dir --with-openssl
make &&make install
5、设置php配置文件
bash> cd /usr/local/lnmp/php-5.6.24/etc
bash> cp php-fpm.conf.default php-fpm.conf
6、更改php-fpm.conf,[user = nobody],[group = nobody]分别改为[user = www],[group = www]
7、去掉[pid=]这一行之前的分号
bash> vim /usr/local/lnmp/php-5.6.24/etc/php-fpm.conf
8、创建组和用户
bash> groupadd www
bash> useradd -g www www
9、创建ini文件
bash> cp /var/opt/lnmp/php-5.6.24/php.ini-production /usr/local/lnmp/php-5.6.24/lib/php.ini
10、在nginx的html下创建index.php文件
<?
echo phpinfo()
?>
11、建立php-fpm的软连接
bash> ln -s /usr/local/lnmp/php-5.6.24/sbin/php-fpm .
12、启动php和重启nginx
bash> nginx -s quit
bash> nginx
bash> php-fpm
13、打开浏览器输入ip/index.php查看结果
四、安装mysql
1、安装相关软件包
bash> yum -y install cmake ncurses-devel
2、创建mysql用户
bash> groupadd mysql
bash> useradd -r -g mysql mysql
3、解压文件
bash> tar mysql-5.5.32.tar.gz
bash> tar zxvf mysql-5.5.32.tar.gz
4编译安装
bash> cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql-5.5.32/mysql \ -DMYSQL_DATADIR=/usr/local/lnmp/mysql-5.5.32/data/ -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_SSL=yes
make && make install
5、配置环境变量以及配置文件
bash> cp /usr/local/lnmp/mysql-5.5.32/mysql/support-files/my-small.cnf /etc/my.cnf
bash> echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile
bash> source /etc/profile
6、初始化
bash> cd /usr/local/lnmp/mysql-5.5.32/mysql/scripts/
./mysql_install_db –basedir=/usr/local/lnmp/mysql-5.5.32/mysql/ --datadir=/usr/local/lnmp/mysql-5.5.32/data/ --user=mysql/
7、复制启动脚本
bash> /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
8、启动mysql
bash> /etc/init.d/mysqld start/
9、设置mysql密码
bash> mysqladmin -u root password ‘123qwe‘
10、登录mysql
bash> mysql -u root password ‘123qwe‘
11、创建新用户
mysql> CREATE USER ‘hello‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
12、创建一个数据库hello_db
mysql> CREATE DATABASE hello_db;
13、让hello对hello_db有完全操作的权限
mysql> GRANT ALL ON hello_db.* TO ‘hello‘@‘localhost‘;
14、先退出
mysql> exit;
15、使用hello账号登录mysql
bash> mysql -u hello password ‘123456‘
16、进入 hello_db数据库
mysql> USE hello_db;
17、建一张为[hello_table]的表
mysql> CREATE TABLE `hello_table`( `id` INT(10) PRIMARY KEY NOT NULL AUTO_INCREMENT, `content` VARCHAR(256) DEFAULT ‘Hello LNMP!‘ );
18、往里面插入一条数据
mysql> INSERT INTO `hello_table` (`id`, `content`) VALUES(1, ‘Hello World! Hello LNMP!‘);
19、退出mysql
mysql> exit;
20、在nginx的html文件下创建一个lnmp.php的文件内容如下
bash> vim /usr/local/lnmp/nginx-1.10.1/html/lnmp.php
<?php
$con = mysqli_connect(‘localhost:3306‘, ‘hello‘, ‘123456‘, ‘hello_db‘);
//检查连接是否出错
if (mysqli_connect_errno($con)) {
echo ‘Failed to connect to MySQL: ‘ . mysqli_connect_error() . "\n";
die("Connect to database failed.\n");
}
//执行读取数据的语句
$query = ‘SELECT `id`, `content` FROM `hello_table` WHERE `id`=1;‘;
$result = mysqli_query($con, $query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
//输出结果
echo $row[‘content‘];
//关闭连接
mysqli_close($con);
?>
21、打开浏览器输入ip/lnmp.php查看
标签:
原文地址:http://www.cnblogs.com/hygs/p/5778407.html