CentOS7.3 安装配置 Nginx、MariaDB、PHP
CentOS7.3 安装配置 Nginx、MariaDB、PHP
配置 nginx 安装参数并安装
配置
以下参数也可以在后期通过配置 conf 文件进行配置
基本配置如下
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --user=nginx --group=nginx
更多模块一起安装配置如下,有些模块需要系统安装相应组件,根据提示进行安装,比如 gd 组件,需要通过 yum install gd-devel
安装对应系统组件。
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --user=nginx --group=nginx --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_xslt_module=dynamic --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module --http-log-path=/var/log/nginx/access.log --with-mail --with-mail_ssl_module --with-cpu-opt=CPU --with-pcre --with-pcre-jit --with-zlib-asm=CPU --with-debug
出现如下内容说明配置成功,记录了你的 Nginx 相关配置信息。
nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/etc/nginx"nginx configuration file: "/etc/nginx/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: ""nginx http access log file: "/var/log/nginx/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"
编译
make && make install
提示如下成功:
cp objs/ngx_http_xslt_filter_module.so '/usr/local/nginx/modules/ngx_http_xslt_filter_module.so'
make[1]: 离开目录“/root/nginx-1.11.10”
检查是否安装成功
执行如下命令启动,并用 ps 命令检查启动情况
/usr/sbin/nginx -c /etc/nginx/nginx.conf
ps -ef | grep nginx
添加 nginx 到系统服务
vim /usr/lib/systemd/system/nginx.service
增加如下内容(结合安装时的配置文件进行修改),其中 特殊的环境变量 $MAINPID 可用于表示主进程的PID
。有关 systemd.service 的配置,可以参加下面两篇文章:
systemd 入门教程:命令篇
Systemd 入门教程:实战篇
systemd.service 中文手册
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/sbin/nginx -c /etc/nginx/nginx.conf -t
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true[Install]
WantedBy=multi-user.target
:wq 保存退出
停止原先启动的 Nginx 进程,
/usr/sbin/nginx -s stopps -ef|grep nginxsystemctl daemon-reloadsystemctl start nginx.service
服务启动后,打开浏览器,输入您网站的地址,查看欢迎页面是否正常显示。
不知道 ip 的,可以通过如下命令找到本机 ip 地址
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
命令行测试网页
curl http://yourip
安装 MySQL (MariaDB)
sudo yum install mariadb-server mariadb
sudo systemctl start mariadb
增加 mysql 安全性
sudo mysql_secure_installation
设置为系统启动加载
sudo systemctl enable mariadb
安装 php7
建立 php7 的 yum 源
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm
rpm -Uvh epel-release-latest-7.noarch.rpm
後面會用到 yum-config-manager,若無此指令,可先用 yum search 查詢在那個套件再安裝,我们通过 search 找到为 yum-utils
yum search yum-config-manager
yum install yum-utils
开启remi 、remi-php71 源
yum-config-manager --enable remi
yum-config-manager --enable remi-php71
如果安装的是 php5.6 则修改上句如下:
yum-config-manager --enable remi-php56
用 yum repolist all
查看所有 repo,检查是否配置成功。
安装 php php-fpm php-mysql 及其他 php 模块
如果原先已安装 php,可以用 yum update php*
更新,或者用 yum remove php
删除后再重新安装。
yum install php php-fpm php-mysql php-bcmath php-gd php-mbstring -y
以下组件也可以挑需要的安装。
yum install php-fpm php-mysql php-bcmath php-cli php-common php-gd php-mbstring php-pdo php-pear php-pecl-msgpack php-process php-xml gd-last php-json php-pecl-memcached php-pecl-zip -y
可以用 yum list installed | grep php
查看 php 套件安装情况。
用 php -v
查看当前版本。
配置 php-fpm
找到你的 php-fpm.sock 文件,将该路径配置到 php-fpm 的 conf 文件中
find / -name www.conf
vi /etc/php-fpm.d/www.conf
修改 www.conf 如下
listen = /run/php-fpm/php-fpm.sock
php-fpm 的 user/group 要和 webserver 的所有权一致,如我在 CentOS7 下,用 nginx 用户 运行 nginx 服务,则修改 php-fpm 的 www.conf 配置如下:
listen.owner = nginx
listen.group = nginx
listen.mode = 0660user = nginx
group = nginx
重启 php-fpm 服务,并加入到系统自启动中:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
如果重启后,php 服务还是不成功,可能还需执行 chown nginx:nginx /run/php-fpm/php-fpm.sock
后再重启。
配置 Nginx 使其能执行 php 页面
vi /etc/nginx/nginx.conf
主要有如下步骤:
设置 root 根目录
添加 index.php 为默认目录首页请求
修改 server_name ,添加域名或 IP
定义 404 等错误页面的规则
配置 PHP 处理模块,主要调整
location ~ \.php$ {
部分,尤其注意fastcgi_pass unix:
指向的 php-fpm.sock 路径是否正确;保存后重启 nginx 服务
我的配置文件大致如下:
server {listen 80;server_name server_domain_name_or_IP;# note that these lines are originally from the "location /" blockroot /www;index index.php index.html index.htm;location / {try_files $uri $uri/ =404;}error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root /www;}location ~ \.php$ {try_files $uri =404;fastcgi_pass unix:/run/php-fpm/php-fpm.sock;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
在根目录添加一个 phpinfo 的 php 文件,打开浏览器进行测试是否正常显示。
成功后删除测试页面。
安装 phpmyadmin
去官网下载解压即可:
wget https://files.phpmyadmin.net/phpMyAdmin/4.6.6/phpMyAdmin-4.6.6-all-languages.zip
unzip phpMyAdmin-4.6.6-all-languages.zip -d /wwwcp config.sample.inc.php config.inc.php
如果浏览器打开出现如下错误:
session_start(): open(SESSION_FILE, O_RDWR) failed: Permission de
则修改报错信息文件的所有权,如下
chown nginx:nginx /var/lib/php/session
CentOS7.3 安装配置 Nginx、MariaDB、PHP相关推荐
- linux nginx 安装stream,Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载
Centos7-64bit-编译安装配置Nginx stream四层负载均衡 动态加载 2018-08-10 17:12 分享人:老牛 yum install screen -y && ...
- 在CentOS7上安装配置Corosync高可用集群过程全记录
在CentOS7上安装配置Corosync高可用集群过程全记录 一.环境.拓朴及其他准备工作: 1-1:准备网络YUM源环境: All Nodes OS CentOS 7.3 x86_64: # wg ...
- linux nginx编译安装mysql_Centos7下编译安装配置Nginx+PHP+MySql环境
序言 这次玩次狠得.除了编译器使用yum安装,其他全部手动编译.哼~ 看似就Nginx.PHP.MySql三个东东,但是它们太尼玛依赖别人了. 没办法,想用它们就得老老实实给它们提供想要的东西. 首先 ...
- centos中安装配置nginx完成之后主机无法访问
原因 VMware中安装centos7,安装配置完成nginx后,主机无法访问.虚拟机没有放行Nginx默认端口80. 解决办法 首先:开启 web 端口 firewall-cmd --permane ...
- centos7 Kubeadm安装配置K8S 及Dashboard外部服务
环境: Kubernetes Master节点:192.168.0.47 Kubernetes node1节点:192.168.0.33 Kubernetes node2节点:192.168.0.37 ...
- 在阿里云centos7.4上配置nginx免费的https证书,支持泛解析
在阿里云centos7.4上配置nginx免费的https证书,支持泛解析 一 原理说明: 使用acme.sh工具来生成证书,但为了方面采用的使用dns添加TXT记录验证方式,跟传统的webroot有 ...
- Linux服务器下安装配置Nginx的教程
这篇文章主要介绍了Linux服务器下安装配置Nginx服务器的教程,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下 Nginx("engine x")是一款 ...
- Centos7下安装配置开源存储虚拟化QuadStor(4)----Vdisk Clone
操作环境 同< Centos7下安装配置开源存储虚拟化QuadStor(1)------初始化QuadStor> QuadStor Server:10.10.200.227 iSCSi I ...
- 【Linux系列】安装配置Nginx
[Linux 环境]安装配置Nginx 文章目录 [Linux 环境]安装配置Nginx 前言 一.Nginx是什么? 二.使用Nginx 1.安装nginx 2.配置Nginx 3.配置websoc ...
最新文章
- swap的实现(没有中间变量)
- Oracle11g rac监听,关于oracle11g RAC 监听器使用中出现的no services以及no listener分析...
- 怎么查看有关cas的报错_Linux LVM I/O报错,你也遇到这样的问题吗?
- 创建AOP静态代理(上篇)
- python 小海龟鼠标画图_Python小海龟画图
- MyBatis 实现多表查询、resultMap 标签、MyBatis 注解、mybatis运行原理
- c语言 数据结构 多为整数带括号四则运算,用C语言实现 多位整数的四则运算,用栈,例如56*(12+20)-102/2...
- 哔哩哔哩2021年Q4及全年财报:全年营收194亿元,同比增长62%
- 创建图书管理_阿拉尔市文化(图书)馆举办总分馆制建设图书管理软件、文化云专题培训班...
- 随想录(招聘怎样的员工)
- touch无法创建文件或者文档
- 动态创建Sql Server数据库相关(全)
- rtmp/rtsp直播源(真是有效的,网上很多都是失效的)
- 2021版itunes不备份更新ios系统
- java文本框背景_Java 添加文本框到PPT幻灯片过程解析
- 团队建设的不同阶段与管理方式
- php5.2.17 pecl,php pecl的使用
- loj 6184 无心行挽 虚树+DP+倍增
- 【快应用】account.authorize授权码模式登录报错1102
- 吹爆“Alibaba”自研Spring全家桶全套全彩学习笔记(终极版)
热门文章
- 粤港澳大湾区落地首家人工智能工程院
- 生成器与迭代器的区别
- Point-to Analysis指针分析(1)
- 马斯克:今年占全球发射质量65%,星舰5月或首次轨道试飞
- 数字孪生等前沿技术,将如何解码未来交通?
- 评阅百篇博士论文后我发现:博士生发SCI越多,通常科研能力越差!
- Alpha fold: 人工智能在蛋白质结构预测上跑赢人类的启示
- 亚马逊首家“无人超市”系统存在bug?!开业当天,记者中途换装成功骗过摄像头...
- 这一次,脑机接口可以实时读取人类脑中画面了?
- 【南科大发言】人类赋予人工智能伦理,生物进化方向的突破是关键