CentOS部署LNMP

一、先安装LNMP:

1)安装nginx:

vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
yum install -y nginx

通过nginx -v命令检查版本是1.22.1。

启动Nginx:

systemctl start nginx && systemctl enable nginx

然后检查下端口:

netstat -atunlp |grep nginx

2)安装mariadb:

yum install -y mariadb-server mariadb

启动mariadb:

systemctl start mariadb.service && systemctl enable mariadb.service

检查下端口:

netstat -atunlp |grep mysqld

进行初始化:

mysql_secure_installation

后面有些配置,直接看英文进行处理。

3)安装php7.2:

yum install epel-release -y

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum install -y php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql

php -v

4)配置nginx支持php:

vim /etc/php-fpm.d/www.conf  
8 user = nginx
10 group = nginx

CentOS部署LNMP_第1张图片

vim /etc/nginx/conf.d/default.conf
10 index index.php index.html index.htm;

配置php请求被传送到后端的php-fpm模块

ocation ~ \.php$ {
 31         root           /usr/share/nginx/html;
 32         fastcgi_pass   127.0.0.1:9000;
 33         fastcgi_index  index.php;
 34         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 35         include        fastcgi_params;
 36     }

把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。

配置php:

vim /etc/php.ini

359 expose_php = Off
202 short_open_tag = On

更改一些配置: 

368 max_execution_time = 300            
378 max_input_time = 300 
389 memory_limit = 128M
656 post_max_size =16M
799 upload_max_filesize = 2M
800 always_populate_raw_post_data = -1
877 date.timezone = Asia/Shanghai

systemctl start php-fpm
systemctl enable php-fpm

[root@server ~]# netstat -natp | grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      70153/php-fpm: mast 

systemctl restart nginx

测试首页:

vim /usr/share/nginx/html/info.php


在浏览器中输入:http://ip地址/info.php

CentOS部署LNMP_第2张图片

测试链接数据库:



你可能感兴趣的:(Nginx,Linux系统,运维)