lnmp平台搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lnmp平台搭建相关的知识,希望对你有一定的参考价值。

1:环境准备

useradd nginx -s /sbin/nologin -M

useradd mysql -s /sbin/nologin -M


nginx:nginx-1.8.1.tar.gz

http://nginx.org/download/nginx-1.8.1.tar.gz


cmake-2.8.10.2.tar.gz

http://download.chinaunix.net/download.php?id=45213&ResourceID=1605


mysql-5.5.13.tar.gz

http://www.mysql.com/downloads/mysql


php扩展库

mhash-0.9.9.9.tar.gz

libiconv-1.13.tar.gz

libmcrypt-2.5.8.tar.gz


php-5.4.9.tar.gz


yum -y install vim-enhanced ncurses-devel elinks gcc gcc-c++ flex bison autoconf automake gzip net-snmp-devel net-snmp \

ncurses-devel pcre pcre-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel \

gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel \

libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel


2:安装nginx

tar -zxf nginx-1.8.1.tar.gz

cd nginx-1.8.1

编译参数详解见:http://blog.csdn.net/eric1012/article/details/6052154

./configure    --prefix=/usr/local/nginx     --pid-path=/usr/local/nginx/nginx.pid   --user=nginx   --group=nginx  \

--with-http_ssl_module   --with-http_flv_module   --with-http_stub_status_module  --with-http_gzip_static_module  --http-client-body-temp-path=/usr/local/nginx/client  \

--http-proxy-temp-path=/usr/local/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/fcgi  --http-uwsgi-temp-path=/usr/local/nginx/uwsgi  --http-scgi-temp-path=/usr/local/nginx/scgi  --with-pcre

make && make install

2.1:启动nginx

检查语法

/usr/local/nginx/sbin/nginx -t

启动nginx

/usr/local/nginx/sbin/nginx

2.2:测试

netstat -ntlp | grep nginx

浏览器测试:http:/192.168.110.130

命令行测试:elinks --dump http://192.168.110.130


3:安装mysql(cmake的方式安装或者二进制文件方式安装)

3.1:安装cmake

tar -zxf cmake-2.8.10.2.tar.gz

cd cmake-2.8.10.2

./bootstrap --prefix=/usr/local/cmake

make && make install

3.2:安装mysql

tar -zxf mysql-5.5.13.tar.gz

cd mysql-5.5.13

编译参数详解:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

/usr/local/cmake/bin/cmake    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    -DSYSCONFDIR=/etc   -DMYSQL_DATADIR=/usr/local/mysql/data  \

-DMYSQL_TCP_PORT=3306   -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock   -DMYSQL_USER=mysql  \

 -DEXTRA_CHARSETS=all   -DWITH_READLINE=1   -DWITH_SSL=system   -DWITH_EMBEDDED_SERVER=1   -DENABLED_LOCAL_INFILE=1   -DWITH_INNOBASE_STORAGE_ENGINE=1

make

make install (这里不要这样写make && make install)

3.3:初始化数据库并建立主配置文件

/usr/local/mysql/scripts/mysql_install_db --user=mysql

cp -p /usr/local/src/mysql-5.5.13/support-files/my-medium.cnf /etc/my.cnf

ln -s /usr/local/mysql/bin/* /usr/sbin/

3.4:启动数据库并设置密码测试

/usr/local/mysql/bin/mysqld_safe --user=mysql &

netstat -ntlp| grep mysql

mysqladmin -hlocalhost -uroot password "testpass"

mysql -uroot -hlocalhost -ptestpass


4:安装php

4.1:PHP安装扩展库

libmcrypt #动态内容的加载,添加和移除算法

mhash #mhash为php提供了多种哈希算法(常见的MD5)

mcrypt #mcrypt加密和mhash结合使用对PHP加密(20种算法,8种加密模式)


tar -zxf mhash-0.9.9.9.tar.gz 

cd mhash-0.9.9.9

./configure

make && make install


tar -zxf libiconv-1.13.tar.gz

cd libiconv-1.13

./configure

make && make install


tar -zxf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8 

./configure

make && make install

cd libltdl/

./configure   --with-gmetad --enable-gexec --enable-ltdl-install

make && make install

4.2:安装php

环境准备

vim /etc/ld.so.conf

include ld.so.conf.d/*.conf

/usr/local/mysql/lib/

/usr/local/mysql/include/


ln -sv /usr/local/lib/libmcrypt*     /usr/lib/

ln -sv /usr/local/lib/libmhash.*    /usr/lib/

ln -sv /usr/local/lib/libiconv.*    /usr/lib/

ldconfig


tar -zxf php-5.4.9.tar.gz

cd php-5.4.9

编译参数详解见:http://wanwentao.blog.51cto.com/2406488/647585

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  \

--with-mysql=/usr/local/mysql  --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir   --with-jpeg-dir --with-png-dir \

--with-zlib    --with-libxml-dir=/usr --enable-xml    --disable-rpath   --enable-bcmath --enable-shmop  --enable-sysvsem --enable-inline-optimization \

--with-curl   --with-curlwrappers --enable-mbregex   --enable-fpm  --enable-mbstring    --with-mcrypt   --with-gd   --enable-gd-native-ttf --with-openssl  \

--with-mhash   --enable-pcntl --enable-sockets   --with-ldap   --with-ldap-sasl --with-xmlrpc    --enable-zip   --enable-soap

make ZEND_EXTRA_LIBS=‘-liconv‘

make install

4.3:建立主配置文件

cp /usr/local/src/php-5.4.9/php.ini-production /usr/local/php5nginx/etc/php.ini

vim /usr/local/nginx/html/test.php

4.4:安装配置fpm并启动服务

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cd /usr/local/src/php-5.4.9/sapi/fpm

cp init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

/etc/init.d/php-fpm start

netstat -ntlp|grep php

5:修改nginx配置,使其能解析php

vim   nginx.conf

http  {

   server    {

       location    /   {

             root   html;

             index   index.php  index.html;

       }


       location ~ \.php$ {

            root           html;

           fastcgi_pass   127.0.0.1:9000;

           fastcgi_index  index.php;

           fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

           include        fastcgi_params;

         }

   }

}


vim    fastcgi_params

fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;


5.1:重新加载nginx(以下两种方式平滑启动)

kill  -HUP  `cat  /usr/local/ngin/logs/nginx.pid`

/usr/local/nginx/sbin/nginx -s reload

6:测试php能否连接mysql

vi index.php

<?php

$linkdb=mysql_connect("localhost","root","testpass");

if($linkdb){

     echo "ok";

}else{

     echo "no";

};


?>


elinks --dump http://192.168.110.130/index.php


以上是关于lnmp平台搭建的主要内容,如果未能解决你的问题,请参考以下文章

docker搭建LNMP网站平台

docker搭建LNMP网站平台

LNMP平台搭建网站实战案例

LNMP平台搭建与应用 #yyds干货盘点#

lnmp平台搭建

LNMP平台搭建