LNMP架构说明
一.LNMP架构说明
1).使前端web服务和后端存储服务进行串联
2).主要实现处理PHP程序动态请求
二.LNMP架构工作原理
L(Linux) N(Nginx) M(Mysql) P(Php)
三.LNMP架构部署
1).安装LNMP相关软件
部署Linux系统:基础优化操作要完成(防火墙关闭 关闭selinux /tmp权限1777)
部署nginx服务:忽略(请看上篇nginx部署实践)
部署mysql服务:忽略(接上篇mysql)
2).PHP软件安装过程
解决php软件依赖关系:yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
libiconv软件安装---字符集转换库(默认可以不进行安装)
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ../
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mhash mcrypt
rpm -qa libmcrypt-devel mhash mcrypt
下载PHP软件(PHP官网下载php.net):
cd /server/tools/
tar xf php-5.5.32.tar.gz
cd php-5.5.32
编译:./configure \
--prefix=/application/php-5.5.32 \
--with-mysql=/application/mysql-5.6.34 \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--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 \
--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-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no
##防错(以下信息可以不进行配置了)
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
make
make install
ln -s /application/php-5.5.32/ /application/php
##设置PHP程序配置文件
php.ini php-fpm.ini
cp php.ini-production /application/php-5.5.32/lib/
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.con
##启动php程序服务:
/application/php/sbin/php-fpm
netstat -lntup|grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 6251/php-fpm
四.进行软件的结合
nginx与php结合:编写nginx配置文件
location ~* .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
php与mysql结合:编写php程序代码
<?php
//$link_id=mysql_connect('主机名','用户','密码');
//mysql -u用户 -p密码 -h 主机
$link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();
if($link_id){
echo "mysql successful by oldboy !\n";
}else{
echo mysql_error();
}
?>
五.部署一个网站(wordpress为例)
1.下载与上传网站代码(直接搜即可)
2.解压程序代码,将程序代码保存到站点目录并进行授权
tar xf wordpress-4.7.3-zh_CN.tar.gz
mv wordpress/* /application/nginx/html/blog/
chown -R www.www /application/nginx/html/blog/
3.直接访问blog网站,进行初始化操作
创建数据库:
create database wordpress;
show databases;
4.创建连接数据用户信息
grant all on wordpress.* to 'wordpress'@'localhost' identified by 'oldboy123';
select user,host from mysql.user;