Lnmp架构用Linux+nginx+php+MariaDB
1.安装前,查看是否关闭防火墙和selinux安全
[root@node2 ~]# getenforce
Permissive
[root@node2 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2.安装yum-utils,这是一个与yum集成的实用程序集合,通过多种方式扩展其本机特性
[root@node2 ~] yum install yum-utils
3.设置yum存储库
#nginx的yum配置
[root@node2 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
[root@node2 ~]# yum-config-manager --enable nginx-mainline #使用主线nginx包,使用最新版本的nginx包
3.1.安装epel额外包和php的存储库
[root@node2 ~]# yum install wget -y #没有安装的就要安装一下,如果有安装就不用再安装了
[root@node2 ~]# wget https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7 #epel额外包的密钥
[root@node2 ~]# wget https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm #epel额外包的yum的配置
[root@node2 ~]# wget https://rpms.remirepo.net/RPM-GPG-KEY-remi #remi包的密钥
[root@node2 ~]# wget https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm #php的yum配置
[root@node2 ~]#rpm --import RPM-GPG-KEY-EPEL-7 #导入epel额外包的密钥
[root@node2 ~]#rpm --import RPM-GPG-KEY-remi #导入remi包的密钥
[root@node2 ~]#rpm -ivh epel-release-latest-7.noarch.rpm #安装epel额外包的yum配置
[root@node2 ~]#rpm -ivh remi-release-7.rpm #安装php的yum配置
或者用编辑yum配置
[root@localhost ~]# vi /etc/yum.repos.d/local.repo
[bao]
name=bao
baseurl=file:///opt/bao
gpgcheck=0
enabled=1
[epel] #额外rpm包
name=epel
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enabled=1
[php73] #php7.3rpm包
name=php73
baseurl=https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/7/safe/x86_64/
gpgcheck=0
enabled=1
[php73extend] #php7.3rpm扩展包
name=php73extend
baseurl=http://mirrors.aliyun.com/remi/enterprise/7/php73/x86_64/
gpgcheck=0
enabled=1
3.2.注意:安装yum源包,手动删除了yum的包,就要强制卸载 ,并执行事务;才是完全卸载,才可以重新安装yum源包
[root@node2 ~]# yum remove remi-release-7.6-2.el7.remi.noarch --nodeps
...
==============================================================================
Package 架构 版本 源 大小
==============================================================================
正在删除:
remi-release noarch 7.6-2.el7.remi installed 19 k
事务概要
==============================================================================
移除 1 软件包
安装大小:19 k
Exiting on user command
您的事务已保存,请执行:
yum load-transaction /tmp/yum_save_tx.2019-08-14.18-36.mJqhk9.yumtx 重新执行该事务
[root@node2 ~]# yum load-transaction /tmp/yum_save_tx.2019-08-14.18-36.mJqhk9.yumtx #执行事务
...
依赖关系解决
==============================================================================
Package 架构 版本 源 大小
==============================================================================
正在删除:
remi-release noarch 7.6-2.el7.remi installed 19 k
事务概要
==============================================================================
移除 1 软件包
安装大小:19 k
是否继续?[y/N]:y
...
4.安装nginx+php
[root@node2 ~]# yum remove php* #移除旧的php版本
...
依赖关系解决
=================================================================================
Package 架构 版本 源 大小
=================================================================================
正在删除:
php-cli x86_64 5.4.16-45.el7 @cnetos 8.8 M
php-common x86_64 5.4.16-45.el7 @cnetos 3.8 M
php-gd x86_64 5.4.16-45.el7 @cnetos 343 k
php-pdo x86_64 5.4.16-45.el7 @cnetos 193 k
事务概要
=================================================================================
移除 4 软件包
...
[root@node2 ~]# yum install nginx
[root@node2 ~]# yum install php73 php-fpm php-mysqlnd -y
...
=================================================================================
Package 架构 版本 源 大小
=================================================================================
正在安装:
php x86_64 7.3.8-1.el7.remi php73 3.2 M
php-fpm x86_64 7.3.8-1.el7.remi php73 1.7 M
php-mysqlnd x86_64 7.3.8-1.el7.remi php73 233 k
为依赖而安装:
libargon2 x86_64 20161029-3.el7 epel 23 k
php-cli x86_64 7.3.8-1.el7.remi php73 4.9 M
php-common x86_64 7.3.8-1.el7.remi php73 1.1 M
php-json x86_64 7.3.8-1.el7.remi php73 65 k
php-pdo x86_64 7.3.8-1.el7.remi php73 127 k
事务概要
=================================================================================
安装 3 软件包 (+5 依赖软件包)
...
5. 编辑nginx默认配置
[root@node2 ~]# vi /etc/nginx/conf.d/default.conf
server {
listen 800;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#location ~ /\.ht {
# deny all;
#location ~ /\.ht {
# deny all;
server {
listen 800;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#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;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; #File not found.php模块引导设置这里
include fastcgi_params;
}
}
6.启动php-fpm和nginx服务
[root@node2 ~]# systemctl start php-fpm
[root@node2 ~]# systemctl start nginx
7.编辑php页面
[root@node2 ~]# vi /usr/share/nginx/html/index.php
<?php
phpinfo()
?>
8.浏览nginx的静态网页和动态网页
扫描二维码关注公众号,回复:
12472675 查看本文章
9.编辑php-fpm配置
[root@node2 ~]# vi /etc/php-fpm.d/www.conf
...
user = nginx #user=apache改为nginx
group = nginx #group=apache改为nginx
...
[root@node2 ~]# systemctl restart php-fpm
10.安装MariaDB
[root@node2 ~]# yum install mariadb mariadb-server -y #安装mariadb数据库
[root@node2 ~]# yum install php-mbstring #安装php模块,扩展的方法代码
...
依赖关系解决
==============================================================================
Package 架构 版本 源 大小
==============================================================================
正在安装:
php-mbstring x86_64 7.3.8-1.el7.remi php73 510 k
为依赖而安装:
oniguruma5 x86_64 6.9.2-2.el7.remi remi-safe 192 k
事务概要
==============================================================================
安装 1 软件包 (+1 依赖软件包)
...
11.启动MariaDB服务
[root@node2 ~]# systemctl start mariadb
[root@slave ~]# mysql_secure_installation
...
Set 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!
...
Disallow root login remotely? [Y/n] n
... skipping.
...
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
...
Reload privilege tables now? [Y/n] y
... Success!
...
12.塔建phpMyAdmin,下载地址:https://www.phpmyadmin.net/downloads/
[root@node2 ~]# wget https://files.phpmyadmin.net/phpMyAdmin/5.0.0-alpha1/phpMyAdmin-5.0.0-alpha1-all-languages.tar.gz
[root@node2 ~]# ls phpMyAdmin-5.0.0-alpha1-all-languages.tar.gz
phpMyAdmin-5.0.0-alpha1-all-languages.tar.gz
12.1.解压phpMyAdmin到nginx存放网页的数据
[root@node2 ~]# tar -zxvf phpMyAdmin-5.0.0-alpha1-all-languages.tar.gz -C /usr/share/nginx/
[root@node2 ~]# chown -R nginx:nginx /usr/share/nginx/html/phpMyAdmin
[root@node2 ~]# cd /usr/share/nginx/ #切换到nginx存放网页数据的目录
[root@node2 nginx]# mv phpMyAdmin-5.0.0-alpha1-all-languages/ phpMyAdmin #修改名称
12.2.到phpMyAdmin复制一份默认的配置文件
[root@node2 ~]# cd /usr/share/nginx/html/phpMyAdmin/
[root@node2 phpMyAdmin]# cp config.sample.inc.php config.inc.php
12.3.修改所有拥有者和所属组的文件
[root@node2 ~]# chown -R nginx:nginx /usr/share/nginx/html #修改所有拥有者和所属组的nginx的页面存放位置
[root@node2 ~]# chmod -R -755 /usr/share/nginx/html/phpMyAdmin/ #修改权限
[root@node2 ~]# ls -lh /var/lib/php/
总用量 0
drwxrwx---. 2 root apache 6 7月 30 23:30 opcache
drwxrwxr-x. 2 root apache 6 8月 16 11:10 session
drwxrwx---. 2 root apache 6 7月 30 23:30 wsdlcache
[root@node2 ~]# chown -R nginx:nginx /var/lib/php/ #修改所有者和所属组的php的session连接网页
[root@node2 ~]# ls -lh /var/lib/php/
总用量 0
drwxrwx---. 2 nginx nginx 6 7月 30 23:30 opcache
drwxrwx---. 2 nginx nginx 123 8月 16 11:19 session
drwxrwx---. 2 nginx nginx 6 7月 30 23:30 wsdlcache
[root@node2 ~]# systemctl restart nginx
[root@node2 ~]# systemctl restart php-fpm
12.4.浏览网页
12.5.输入MariaDB数据库的用户和密码