LNMP架构基础搭建

Posted tcheng

tags:

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

LNMP架构+wordpress博客

环境:

  • centos6.7 2.6.32-573.el6.x86_64
  • nginx-1.6.3
  • mysql-5.5.49
  • php-5.3.27
  • wordpress-4.9.4

 

Linux环境:

[[email protected] ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[[email protected] ~]# uname -m

x86_64

[[email protected] ~]# uname -r

2.6.32-573.el6.x86_64

[[email protected] ~]#

 

安装Nginx:

yum install pcre pcre-devel openssl openssl-devel -y

mkdir -p /home/oldboy/tools

cd /home/oldboy/tools

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

useradd nginx -s /sbin/nologin -M

tar xf nginx-1.6.3.tar.gz

cd nginx-1.6.3

./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3 --with-http_stub_status_module --with-http_ssl_module

make

make install

ln -s /application/nginx-1.6.3 /application/nginx

cd ../

/application/nginx/sbin/nginx

lsof -i:80

 

安装MySQL:

cd /home/oldboy/tools/

rz

mysql-5.5.49-linux2.6-x86_64.tar.gz

useradd -s /sbin/nologin mysql -M

tar -xf mysql-5.5.49-linux2.6-x86_64.tar.gz

mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49

ln -s /application/mysql-5.5.49/ /application/mysql

cd /application/mysql

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

chown -R mysql.mysql /application/mysql/

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

cp support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld 

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

/etc/init.d/mysqld start

echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile

source /etc/profile

mysqladmin -u root password ‘123456‘

lsof -i:3306

 

安装PHP:

cd /home/oldboy/tools

rz

libtool-ltdl-devel-2.2.6-15.5.el6.x86_64.rpm

rpm -ivh libtool-ltdl-devel-2.2.6-15.5.el6.x86_64.rpm

yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar -xf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install

cd ../

rpm -ivh http://mirrors.sohu.com/fedora-epel/6/i386/epel-release-6-8.noarch.rpm

yum update

yum install libmcrypt-devel mhash mcrypt -y

rz

php-5.3.27.tar.gz

tar -xf php-5.3.27.tar.gz

cd php-5.3.27/

./configure \

--prefix=/application/php5.3.27 \

--with-mysql=/application/mysql \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--enable-rpath \

--enable-safe-mode \

--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-xmlrpc \

--enable-zip \

--enable-soap \

--enable-short-tags \

--enable-zend-multibyte \

--enable-static \

--with-xsl \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-ftp

ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/

touch ext/phar/phar.phar

make

make install

ln -s /application/php5.3.27/ /application/php

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

cd /application/php/etc/

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

/application/php/sbin/php-fpm

lsof -i:9000

 

上传wordpress:

mkdir /application/nginx/html/blog/ -p

cd /application/nginx/html/blog/

rz

wordpress-4.9.4.zip

unzip wordpress-4.9.4.zip

mv wordpress/* ./

rm -rf wordpress

chown -R nginx.nginx /application/nginx/html/blog/

编辑nginx配置文件,使用网站上线

grep -vE "#|^$" ./conf/nginx.conf.default >./conf/nginx.conf

[[email protected] nginx]# vim ./conf/nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    incule extra/blog.conf;

}

 

[[email protected] nginx]# mkdir ./conf/extra

[[email protected] nginx]# vim ./conf/extra/blog.conf

[[email protected] conf]#

[[email protected] conf]# cat /application/nginx/conf/extra/blog.conf

    server {

        listen      80;

        server_name  blog.etiantian.org;

        root    html/blog;

        index  index.php index.html index.htm;

 

        location / {

            if (-f $request_filename/index.html){

              rewrite (.*) $1/index.html break;

            }

            if (-f $request_filename/index.php){

              rewrite (.*) $1/index.php;

            }           

            if (!-f $request_filename){

              rewrite (.*) /index.php;

            } 

        }

 

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

            fastcgi_pass 127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }

}

[[email protected] conf]#

使PHP程序连接数据库

 

cp /application/nginx/html/blog/wp-config-sample.php /application/nginx/html/blog/wp-config.php

[[email protected] conf]# vim /application/nginx/html/blog/wp-config.php

<?php

……

define(‘DB_NAME‘, ‘wordpress‘);

 

/** MySQL database username */

define(‘DB_USER‘, ‘wordpress‘);

 

/** MySQL database password */

define(‘DB_PASSWORD‘, ‘123456‘);

 

/** MySQL hostname */

define(‘DB_HOST‘, ‘localhost‘);

 

/** Database Charset to use in creating database tables. */

define(‘DB_CHARSET‘, ‘utf8‘);

 

/** The Database Collate type. Don‘t change this if in doubt. */

define(‘DB_COLLATE‘, ‘‘);

 

……

 

创建数据库

mysql -uroot -p123456

mysql>create database wordpress;

mysql>grant all on wordpress.* to [email protected]‘localhost‘ identified by ‘123456‘;

mysql>flush privileges;

mysql> quit

重启nginx使WEB服务生效

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx -s reload

 

测试:

浏览器输入:http://blog.etiantian.org/wp-admin/install.php

 

以上是关于LNMP架构基础搭建的主要内容,如果未能解决你的问题,请参考以下文章

LNMP架构

LNMP基础架构

LNMP基础架构

LNMP架构的搭建

LNMP架构搭建与优化

lnmp 架构搭建