Home > php教程 > php手册 > body text

Lnmp环境搭建,lnmp搭建

WBOY
Release: 2016-06-13 08:57:06
Original
1006 people have browsed it

Lnmp环境搭建,lnmp搭建

1、检查并安装组件

yum -y install gcc automake autoconf libtool make gcc-c++ glibc
Copy after login

2、安装库

yum -y install libxslt-devel \
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \
krb5-devel libidn libidn-devel openssl openssl-devel
Copy after login

3、安装libmcrypt

cd /usr/local/src
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt
make && make install
vi /etc/ld.so.conf.d/local.conf
添加 “/usr/local/libmcrypt/lib”
ldconfig -v
Copy after login

4、安装PHP

wget http://cn2.php.net/get/php-5.6.11.tar.gz/from/this/mirror
tar zxvf php-5.6.11.tar.gz
cd php-5.6.11
./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt=/usr/local/libmcrypt \
--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
Copy after login

  

安装成功:

 

配置php-fpm

cd /usr/local/php/etc
cp php-fpm-default.conf php-fpm.conf
Copy after login

修改php-fpm.conf

vi php-fpm.conf
Copy after login
Copy after login

  

将user = nobody group = nobody 修改为 user = phpz group = phpz

创建用户phpz和用户组phpz

groupadd phpz
useradd -g phpz phpz
Copy after login

创建php.ini

cp /usr/local/src/php-5.6.11/php.ini-production /usr/local/php/lib/php.ini
Copy after login

设置php-fpm.pid

vi php-fpm.conf
Copy after login
Copy after login

  

将;pid = run/php-fpm.pid 前面的分号删掉。

注:重启php-fpm 命令:kill -USR2 `cat var/run/php-fpm.pid`

4、安装Nginx

cd /usr/local/src
Copy after login

下载并解压pcre-8.36.tar.gz:

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz 
tar zxvf pcre-8.36.tar.gz
Copy after login

下载并解压zlib-1.2.8.tar.gz

wget http://zlib.net/zlib-1.2.8.tar.gz
tar zxvf zlib-1.2.8.tar.gz
Copy after login

下载并解压openssl-1.0.1g.tar.gz:

wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar zxvf openssl-1.0.1g.tar.gz
Copy after login

下载并解压nginx-1.4.7.tar.gz:

wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar zxvf nginx-1.4.7.tar.gz
Copy after login

安装Nginx

vi /usr/bin/pod2man #注释第69行
cd /usr/local/src/nginx-1.4.7
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.36 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1g
Copy after login

启动nginx

cd /usr/local/nginx
./sbin/nginx
Copy after login

浏览器访问:http://localhost

  

配置nginx.conf ,让Nginx通过PHP的FastCGI处理请求,首先到nginx的安装目录cd /usr/local/nginx,修改vi conf/nginx.conf 文件,找到如下内容:

取消注释,再将/scripts$fastcgi_script_name 修改为 $document_root$fastcgi_script_name

新建一个php文件

cd /usr/local/nginx/html
vi index.php
Copy after login
<?php
echo phpinfo();
?>
Copy after login

启动php-fpm ,重启nginx

/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx -s reload
Copy after login

浏览器访问http://127.0.0.1/index.php  

5、安装MySQL

下载:

cd /usr/local/src
wget http://mirrors.sohu.com/mysql/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.7.tar.gz
Copy after login

先安装cmake:

yum -y install cmake
Copy after login

添加名为「mysql」的用户和组:

groupadd mysql
useradd -r -g mysql mysql
Copy after login

解压mysql-cluster-gpl-7.4.7.tar.gz:

tar zxvf mysql-cluster-gpl-7.4.7.tar.gz
Copy after login

cmake命令如下:

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/run/mysql.sock \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_SSL=yes
Copy after login

安装MySQL:

make && make install
Copy after login
安装需要一段时间,可以喝杯茶 初始化数据库,先切换目录到MySQL的安装目录:
cd /usr/local/mysql/
Copy after login

然后改变安装目录下所有文件的用户及组为mysql

chown -R mysql .
chgrp -R mysql .
Copy after login

初始化数据库:

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql
Copy after login

然后将目录的所有文件的所属用户改为「root」,接着将目录「data」的所属用户改为「mysql」(这一步很重要,否则数据库可能无法对这个目录进行操作):

chown -R root .
chown -R mysql data
chown -R mysql data/mysql
chown -R mysql.mysql /usr/local/mysql/data
Copy after login

将MySQL的配置文件拷贝到配置文件目录「/etc/」下,询问是否覆盖源文件输入「yes」即可:

cp support-files/my-medium.cnf /etc/my.cnf
Copy after login
要对MySQL进行设置 我自己设置为安装目录下的「run/」文件夹,因此要把这个文件夹的所属用户设置为「mysql」:
chown -R mysql ./run
Copy after login

接下来就是最有标志性的一步,运行MySQL的守护进程:

bin/mysqld_safe --user=mysql &
Copy after login

给MySQL数据库里的「root」账号设置密码:

./bin/mysqladmin -u root password '123456'
Copy after login

使用「root」账户进入MySQL管理系统中:

./bin/mysql -u root -p
Copy after login

弹出提示时输入密码即可。进入后的界面应该类似这样:

 

恭喜您,已成功搭建Lnmp环境。

总结:

Linux:CentOS-7-x86_64-DVD-1503-01.iso

PHP:php-5.6.11.tar.gz

Nginx:nginx-1.4.7

MySQL:mysql-cluster-gpl-7.4.7.tar.gz

如有任何疑问,请在评论中提出。

如本文对你有帮助,请帮忙点一下“推荐”。

转载请注明出处(原文网址):http://home.php-z.com/blog-1-39.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!