LNMP就是linux+nginx+mysql+php,linux作为服务器的操作系统,nginx作为web服务器,php作为解析动态脚本语言,mysql即为数据库。
MySQL作为后端存储数据库服务。
Nginx服务本身不能处理php的请求,那么当用户发起php动态请求,Nginx又是如何进行处理
将php页面的解析请求转发给PHP的解析请求转你发给apache处理
将PHP页面的额解析请求转发给php-fpm模块 ***
注意:fatcgi是nginx连接php-fpm之间的协议
Nginx与Fast-CGI工作流程如下
最总数据由mysql->php->php-fpm->fastcgi->nginx->http->user
[root@nginx_web1 ~]# yum -y install nginx
[root@nginx_web1 ~]# systemctl start nginx
[root@nginx_web1 ~]# systemctl enable nginx
rpm -ivh http://repo.mysql.com/yum/mysql-5.6-community/el/7/x86_64/mysql-community-release-el7-5.noarch.rpm//下载官方yum扩展源
[root@nginx_web1 ~]# yum -y install mysql-community-server
[root@nginx_web1 ~]# systemctl start mysqld
[root@nginx_web1 ~]# systemctl enable mysqld
[root@nginx_web1 ~]# mysqladmin -u root password 123.com.cn
[root@nginx_web1 ~]# mysqladmin -uroot -p password 123
Enter password: //输入旧密码
Warning: Using a password on the command line interface can be insecure.
[root@nginx_web1 ~]# mysql -u root -p123
[root@nextcloud ~]# wget -c https://cmake.org/files/v2.8/cmake-2.8.12.tar.gz
[root@nextcloud ~]# tar xf cmake-2.8.12.tar.gz -C /usr/src/
[root@nextcloud ~]# cd /usr/src/cmake-2.8.12/
[root@nextcloud cmake-2.8.12]# ./configure && gmake -j 8 && gmake install
[root@nextcloud ~]# wget -c https://downloads.mysql.com/archives/get/file/mysql-5.6.45.tar.gz
[root@nextcloud ~]# tar xf mysql-5.6.45.tar.gz -C /usr/src/
[root@nextcloud ~]# cd /usr/src/mysql-5.6.45/
[root@nextcloud mysql-5.6.45]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DENABLED_LOCAL_INFILE=ON -DDEFAULT_CHARSET=utf8 DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_DEBUG=0 -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock $$ make && make install
[root@nextcloud ~]# mkdir /usr/local/mysql/tmp
[root@nextcloud ~]# mkdir /usr/local/mysql/log
[root@nextcloud ~]# mkdir /usr/local/mysql/pid
[root@nextcloud ~]# mkdir /usr/local/mysql/binlog
[root@nextcloud ~]# mkdir /usr/local/mysql/relaylog
[root@nextcloud ~]# mkdir /usr/local/mysql/tmpdata
[root@nextcloud ~]# chown -R mysql:mysql /usr/local/mysql
[root@nextcloud ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
[root@nextcloud ~]# source /etc/profile``[root@nextcloud ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@nextcloud ~]# cd /usr/src/mysql-5.6.45 && cp support-files/my- default.cnf /etc/my.cnf
[root@nextcloud mysql-5.6.45]# BASEDIR="/usr/local/mysql"
[root@nextcloud mysql-5.6.45]# DATADIR="/usr/local/mysql/data"
[root@nextcloud mysql-5.6.45]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=$BASEDIR --datadir=$DATADIR
[root@nextcloud mysql-5.6.45]# cp support-files/mysql.server /usr/local/mysql/bin/mysql.sh
[root@nextcloud mysql-5.6.45]# chmod +x /usr/local/mysql/bin/mysql.sh && cd ~
[root@nextcloud ~]# cat > /usr/lib/systemd/system/mysql.service <
[Unit]
Description=MySQL
After=network.target
[Service]
User=mysql
Group=mysql
LimitNOFILE=65535
Type=forking
ExecStart=/usr/local/mysql/bin/mysql.sh start
ExecStop=/usr/local/mysql/bin/mysql.sh stop
[Install]
WantedBy=multi-user.target
EOF
[root@nextcloud ~]# systemctl start mysql
[root@nextcloud ~]# netstat -anput | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 32584/mysqld
[root@nextcloud ~]# systemctl enable mysql
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.
[root@nginx_web1 ~]# yum localinstall -y https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
或
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@nginx_web1 ~]# yum -y install php71w php71w-cli php-71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
[root@nginx_web1 ~]# yum install epel-release
[root@nginx_web1 ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
或
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@nginx_web1 ~]# yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w php72w-bcmath php72w-dba php72w-enchant php72w-imap php72w-interbase php72w-intl php72w-ldap php72w-odbc php72w-pdo_dblib php72w-pear php72w-pecl-apcu php72w-pecl-xdebug php72w-pgsql php72w-phpdbg php72w-process php72w-pspell php72w-recode php72w-snmp php72w-soap php72w-tidy php72w-xmlrpc php72w-pecl-igbinary php72w-intl php72w-pecl-memcached php72w-pecl-mongodb -y
[root@nginx_web1 ~]# systemctl start php-fpm
[root@nginx_web1 ~]# systemctl enable php-fpm
[root@nginx_web1 php]# netstat -anpt | grep "php"
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 29158/php-fpm: mast
先安装如下依赖包
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
#下载
tar -zxvf php-7.2.0.tar.gz
php-7.2.0
# 安装过程大约需要20分钟时间.
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --with-openssl --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl --enable-bcmath --with-gettext && make && make install
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
① 去掉 pid = run/php-fpm.pid 前面的分号
cd php-fpm.d
cp www.conf.default www.conf
vim www.conf
② 修改user和group的用户为当前用户(也可以不改,默认会添加nobody这个用户和用户组)
的时候、大家先使用 -t 选项 检查一下、然后即可启动 php-fpm 服务、如果有错误、那就根据提示进行排查、最后使用 -m 选项 查看自己安装了那些模块
/etc/init.d/php-fpm start #php-fpm启动命令
/etc/init.d/php-fpm stop #php-fpm停止命令
/etc/init.d/php-fpm restart #php-fpm重启命令
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll php73-php-pecl-zip
php73*dom* yum install php73*xml*
#查看软件包配置文件
[root@xxx etc]# rpm -ql php73-php-fpm-7.3.6-1.el7.remi.x86_64
/etc/logrotate.d/php73-php-fpm
/etc/opt/remi/php73/php-fpm.conf
/etc/opt/remi/php73/php-fpm.d
/etc/opt/remi/php73/php-fpm.d/www.conf
/etc/opt/remi/php73/sysconfig/php-fpm
/etc/systemd/system/php73-php-fpm.service.d
/opt/remi/php73/root/usr/sbin/php-fpm
/opt/remi/php73/root/usr/share/doc/php73-php-fpm-7.3.6
/opt/remi/php73/root/usr/share/doc/php73-php-fpm-7.3.6/php-fpm.conf.default
/opt/remi/php73/root/usr/share/doc/php73-php-fpm-7.3.6/www.conf.default
/opt/remi/php73/root/usr/share/fpm
/opt/remi/php73/root/usr/share/fpm/status.html
/opt/remi/php73/root/usr/share/licenses/php73-php-fpm-7.3.6
/opt/remi/php73/root/usr/share/licenses/php73-php-fpm-7.3.6/fpm_LICENSE
/opt/remi/php73/root/usr/share/man/man8/php-fpm.8.gz
/usr/lib/systemd/system/php73-php-fpm.service
/var/opt/remi/php73/lib/php/opcache
/var/opt/remi/php73/lib/php/session
/var/opt/remi/php73/lib/php/wsdlcache
/var/opt/remi/php73/log/php-fpm
/var/opt/remi/php73/run/php-fpm
systemctl restart php73-php-fpm #重启
systemctl start php73-php-fpm #启动
systemctl stop php73-php-fpm #关闭
systemctl status php73-php-fpm #检查状态
fastcgi文件
fastcgi_param QUERY_STRING $query_string; #请求的参数;如?app=123
fastcgi_param REQUEST_METHOD $request_method; #请求的动作(GET,POST)
fastcgi_param CONTENT_TYPE $content_type; #请求头中的Content-Type字段
fastcgi_param CONTENT_LENGTH $content_length; #请求头中的Content-length字段。
fastcgi_param SCRIPT_NAME $fastcgi_script_name; #脚本名称
fastcgi_param REQUEST_URI $request_uri; #请求的地址不带参数
fastcgi_param DOCUMENT_URI $document_uri; #与$uri相同。
fastcgi_param DOCUMENT_ROOT $document_root; #网站的根目录。在server配置中root指令中指定的值
fastcgi_param SERVER_PROTOCOL $server_protocol; #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
fastcgi_param GATEWAY_INTERFACE CGI/1.1; #cgi 版本
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; #nginx 版本号,可修改、隐藏
fastcgi_param REMOTE_ADDR $remote_addr; #客户端IP
fastcgi_param REMOTE_PORT $remote_port; #客户端端口
fastcgi_param SERVER_ADDR $server_addr; #服务器IP地址
fastcgi_param SERVER_PORT $server_port; #服务器端口
fastcgi_param SERVER_NAME $server_name; #服务器名,域名在server配置中指定的server_name
fastcgi_param PATH_INFO $path_info; #可自定义变量
创建.php网站文件
echo /code/www/index.php
创建.php网站文件
vim /code/index1.php
fastcgi_connect_timeout 240; # Nginx服务器和后端FastCGI服务器连接的超时时间
fastcgi_send_timeout 240; # Nginx允许FastCGI服务器返回数据的超时时间,即在规定时间内后端服务器必须传完所有的数据,否则Nginx将断开这个连接
fastcgi_read_timeout 240; # Nginx从FastCGI服务器读取响应信息的超时时间,表示连接建立成功后,Nginx等待后端服务器的响应时间
fastcgi_buffer_size 64k; # Nginx FastCGI 的缓冲区大小,用来读取从FastCGI服务器端收到的第一部分响应信息的缓冲区大小
fastcgi_buffers 4 64k; # 设定用来读取从FastCGI服务器端收到的响应信息的缓冲区大小和缓冲区数量
fastcgi_busy_buffers_size 128k; # 用于设置系统很忙时可以使用的 proxy_buffers 大小
fastcgi_temp_file_write_size 128k; # FastCGI 临时文件的大小
1.获取wordpress代码
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
2.解压网站源代码文件,拷贝到对应站点目录,并授权站点目录
安装php7.2版本
。。。。。。。。。。。。
[root@nginx_web1 ~]# tar zxvf wordpress-4.9.4-zh_CN.tar.gz
[root@nginx_web1 ~]# useradd -u 666 -g 666 -M -s /sbin/nologin www
[root@nginx_web1 ~]# cp -r wordpress /code
[root@nginx_web1 ~]# chwon -R www.www /code/wordpress/
#nginx也需要修改程序用户,让通过nginx访问页面的用户具有写权限
[root@nginx_web1 ~]# sed -i '^user/c user www;' /etc/nginx/nginx.conf
#php-fpm也需要修改程序用户,让通过访问php页面的用户具有写权限
[root@nginx_web1 ~]# sed -i '^user/c user www;' /etc/php-fpm.d/www.conf
[root@nginx_web1 ~]# sed -i '^group/c group www;' /etc/php-fpm.d/www.conf
#重载nginx和php-fpm
[root@nginx_web1 ~]# systemctl reload nginx php-fpm
3.由于wordpress产品需要以来数据库
[root@nginx_web1 ~]# mysql -u root -p
Enter password:
mysql> create database wordpress; //创建数据库
mysql> exit //退出
4.测试
[root@nginx_web1 ~]# mysqldump -u root -p'123.com.cn' --all-databases > `date +%F%H`-mysql-all.sql
Warning: Using a password on the command line interface can be insecure.
--all-databases //选择所有的数据库
--single-transaction //数据库一致性
[root@nginx_web1 ~]# scp 2020-01-2518-mysql-all.sql [email protected]:~
1.3.在新mysql服务器上导入数据库
注意:mysql自身提供安全初始化脚步
##初始化数据库
[root@nginx_web2 ~]# mysql_secure_installation
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] y
... Success!
motely? [Y/n] n
... skipping.
Remove test database and access to it? [Y/n] n
... skipping.
##导入数据库
[root@nginx_web2 ~]# mysql -uroot -p123.com.cn < 2020-01-2518-mysql-all.sql
##数据库访问授权
mysql> grant all on *.* to root@'%' identified by '123.com.cn';
Query OK, 0 rows affected (0.00 sec)
mysql> create user owncloud;
mysql> grant all root on auto.* to 'root'@'%' identified by 'Admin@123';
搭建分离的LNMP平台