- 动态网站架构
- LNMP动态网站环境部署
1.动态网站架构
1.1资源
资源文件识别 语言识别 框架识别
index.php 开源的php Windows/Linux+nginx+php+mysql
index.py 开源python Windows/Linux+apache+python+mysql
index.jsp 商业JAVA Windows/Linux+tomcat+JDK+Oracle
index.asp 商业c# Windows+iis+asp.net+sql-server/oracle/mogodb
2.LNMP动态网站环境部署
2.1LINUX部署
关闭防火墙
2.2Nginx部署
安装nginx
2.3php-fpm部署
(一)部署方法一:RPM部署
yum install -y php-fpm php-mysql php-gd
php-fpm:php接收动态请求的程序
php-mysql:php链接mysql的程序
php-gd:图形库程序(GD库可以处理图片,或者生成图片)注意这里的安装的php-fpm 如果版本过低则测试不成功,可以在阿里巴巴开源镜像站中安装"remi"源,该源中包含最新版本PHP和MySQL包的Linux源
systemctl restart php-fpm 启动php-fpm
netstat -anpt | grep 9000 查看php-fpm的端口【php-fpm的端口为9000】
vim /usr/share/nginx/html/index.php 测试php页面(php基本信息)
<?php
phpinfo();
?> 测试语句
vim /etc/nginx/conf.d/default.conf 增加PHP主页名称:index.php
server {
location / {
...
index index.php index.html;
...
}
}
vim /etc/nginx/conf.d/default.conf 启动nginx_fastcgi功能,解除#注释修改路径即可。
server {
location / {
index index.php;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}什么是动态请求(index.php)将动态请求转发给九千岁(php-fpm)九千岁的位置
fastcgi_param:这个配置的意思是 在浏览器中访问的.php文件,实际读取的是 $document_root(网站根目录)下的.php文件 -- 也就是说当访问127.0.0.1/index.php的时候,需要读取网站根目录下面的index.php文件,如果没有配置这一配置项时,nginx不回去网站根目录下访问.php文件,所以返回空白
通过location指令,将所有以php为后缀的文件都交给127.0.0.1:9000来处理,而这里的IP地址和端口就是FastCGI进程监听的IP地址和端口。
fastcgi_param指令指定放置PHP动态程序的主目录,也就是$fastcgi_script_name前面指定的路径,这里是/usr/local/nginx/html目录,建议将这个目录与Nginx虚拟主机指定的根目录保持一致,当然也可以不一致。
fastcgi_params文件是FastCGI进程的一个参数配置文件,在安装Nginx后,会默认生成一个这样的文件,这里通过include指令将FastCGI参数配置文件包含了进来。
接下来,启动nginx服务。
/usr/local/nginx/sbin/nginx
到此为止,Nginx+PHP已经配置完成。
重启nginx服务并访问:http://192.168.26.147/index.php
(二)部署方法二(源码部署)
部署PHP-fpm
1. 以php-fpm的方式安装php
[root@tianyun ~]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \
libxml2 libxml2-devel libcurl libcurl-devel libxslt-devel openssl-devel[root@webserver ~]# tar xf php-5.6.29.tar.xz
[root@webserver ~]# cd php-5.6.29/
[root@webserver ~]# ./configure \
--prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-jpeg-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
[root@webserver php-5.6.29]# make
[root@webserver php-5.6.29]# make install2. php-fpm配置文件(影响php处理php程序的性能,例如php进程数、最大连接数配置等,运维人员关注)
[root@webserver php-5.6.29]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf3. php置文件(影响php代码,例如允许客户端最大上传文件的大小,设置的timezone,php所支持的扩展功能例如是否可以连接MySQL、Memcache,程序员关注)
[root@webserver php-5.6.29]# cp php.ini-production /usr/local/php/lib/php.ini4. init script centos6 [可选]centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 centos6 c
[root@webserver php-5.6.29]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@webserver php-5.6.29]# chmod a+x /etc/rc.d/init.d/php-fpm
[root@webserver php-5.6.29]# chkconfig --add php-fpm
[root@webserver php-5.6.29]# chkconfig php-fpm on
[root@webserver php-5.6.29]# service php-fpm start
Starting php-fpm done4. Systemd Script centos7 [可选]
[root@webserver ~]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID[Install]
WantedBy=multi-user.target[root@webserver ~]# systemctl start php-fpm.service
[root@webserver ~]# systemctl status php-fpm.service
[root@localhost ~]# ss -an |egrep ':80|:9000'
tcp LISTEN 0 128 127.0.0.1:9000 *:*
tcp LISTEN 0 128 *:80 *:*
(三)自学站点:
2.4mysql 部署
(一)部署方法一(RPM部署)
yum -y install mariadb-server mariadb 安装mysql服务器程序和客户机程序。
systemctl start mariadb 启动mysql服务器
systemctl enable mariadb 开机启动mysql服务器
mysqladmin password '123456' 修改mysql的root密码为‘123456’
create database bbs; 准备数据库,存放app
grant all on bbs.* to phptest@'192.168.100.10' identified by '123456';
授权phptest用户管理bbs库
flush privileges; 刷新权限
vim /usr/share/nginx/html/index.php
<?php
$servername = "192.168.26.147";
$username = "phptest";
$passwd = "123456";$conn = mysqli_connect($servername,$username,$passwd);
if(!$conn){
die("connection failed:" . mysqli_connect_errno());
}else{
echo "成功连接数据库";
mysqli_close($conn);}
?>修改主页,测试MYSQL的链接状态
如果测试为faile,请检查数据库授权结果。
(二)部署方法二(源码部署)略
2.5业务上线
(一)下载wordpress
下载wordpress包:wget https://cn.wordpress.org/latest-zh_CN.tar.gz
解压wordpress: tar -xf ./latest-zh_CN.tar.gz
清除之前的index.php :rm -rf /usr/share/nginx/html/index.php
将解压之后wordpress目录下的文件拷到nginx网站的根目录下:
cp -rf /root/wordpress/* /usr/share/nginx/html
更改nginx网站根目录的属主:
chown -R nginx.nginx /usr/share/nginx/html/*
更改网站的权限:chmod 777 /usr/share/nginx/html/
再用客户端去访问nginx:192.168.26.147
填写信息:数据库名称 数据库用户 数据密码 必须和前方授权一致。
如果出现wp-config.php文件不可写。请手动创建。 vim /usr/local/nginx/html/wp-config.php
填写密码等信息:
v6PNs2m$68wMgotY5y