资讯专栏INFORMATION COLUMN

CentOS7.3 安装配置 Nginx、MariaDB、PHP

Jason / 2907人阅读

摘要:编译提示如下成功离开目录检查是否安装成功执行如下命令启动,并用命令检查启动情况添加到系统服务增加如下内容结合安装时的配置文件进行修改其中特殊的环境变量可用于表示主进程的。以下组件也可以挑需要的安装。成功后删除测试页面。

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 stop
  ps -ef|grep nginx
  systemctl daemon-reload
  systemctl 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 = 0660

user = 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 /" block
    root   /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 /www

cp config.sample.inc.php config.inc.php

如果浏览器打开出现如下错误:

session_start(): open(SESSION_FILE, O_RDWR) failed: Permission de

则修改报错信息文件的所有权,如下

chown nginx:nginx /var/lib/php/session

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/45719.html

相关文章

  • CentOS7.3 安装配置 NginxMariaDBPHP

    摘要:编译提示如下成功离开目录检查是否安装成功执行如下命令启动,并用命令检查启动情况添加到系统服务增加如下内容结合安装时的配置文件进行修改其中特殊的环境变量可用于表示主进程的。以下组件也可以挑需要的安装。成功后删除测试页面。 CentOS7.3 安装配置 Nginx、MariaDB、PHP 配置 nginx 安装参数并安装 配置 以下参数也可以在后期通过配置 conf 文件进行配置基本配置如...

    tommego 评论0 收藏0
  • CentOS7.3 安装配置 NginxMariaDBPHP

    摘要:编译提示如下成功离开目录检查是否安装成功执行如下命令启动,并用命令检查启动情况添加到系统服务增加如下内容结合安装时的配置文件进行修改其中特殊的环境变量可用于表示主进程的。以下组件也可以挑需要的安装。成功后删除测试页面。 CentOS7.3 安装配置 Nginx、MariaDB、PHP 配置 nginx 安装参数并安装 配置 以下参数也可以在后期通过配置 conf 文件进行配置基本配置如...

    cncoder 评论0 收藏0
  • Debian9(Stretch) 下编译安装LNMP环境

    摘要:下源码安装一前言之前,我的开发环境是。重新加载权限表将确保所有到目前为止所做的更改将立即生效。然后,和注意,如果是使用二进制包安装了及相应的开发库,不需要指定路径。五参考资料入门教程编译安装编译安装 Debian9下源码安装LNMP 一、前言 之前,我的开发环境是Windows-10+PHP-7.1+Nginx-1.10+MariaDB-10.1。 后面开发需要使用到memcached...

    ideaa 评论0 收藏0
  • Debian9(Stretch) 下编译安装LNMP环境

    摘要:下源码安装一前言之前,我的开发环境是。重新加载权限表将确保所有到目前为止所做的更改将立即生效。然后,和注意,如果是使用二进制包安装了及相应的开发库,不需要指定路径。五参考资料入门教程编译安装编译安装 Debian9下源码安装LNMP 一、前言 之前,我的开发环境是Windows-10+PHP-7.1+Nginx-1.10+MariaDB-10.1。 后面开发需要使用到memcached...

    blastz 评论0 收藏0
  • Debian9(Stretch) 下编译安装LNMP环境

    摘要:下源码安装一前言之前,我的开发环境是。重新加载权限表将确保所有到目前为止所做的更改将立即生效。然后,和注意,如果是使用二进制包安装了及相应的开发库,不需要指定路径。五参考资料入门教程编译安装编译安装 Debian9下源码安装LNMP 一、前言 之前,我的开发环境是Windows-10+PHP-7.1+Nginx-1.10+MariaDB-10.1。 后面开发需要使用到memcached...

    spacewander 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<