简单的LNMP环境配置

  • 来源:网络
  • 更新日期:2020-09-08

摘要:系统运维 LNMP环境: ​ L:linux ​ N:nginx ​ M:mysql ​ P:php Linux系统就没什么好说的了。这里是centos 7.6 nginx安装 yum -y i

系统运维

LNMP环境:

​ L:linux

​ N:nginx

​ M:mysql

​ P:php

Linux系统就没什么好说的了。这里是centos 7.6

nginx安装
yum -y install epel-release
yum -y install nginx
PHP安装
yum -y install php php-fpm php-curl php-intl php-mcrypt php-Mysql php-mbstring php-xml php-dom php-gd gd

用Redis为MYSQL做缓存时,添加下列
 php-cli php-common php-pdo php-devel php-xmlrpc  php-bcmath php-dba php-enchant
nginx +PHP 环境配置

(nginx + php-fpm +fastcgi)

vim /etv/nginx/nginx.conf

location ~\\.php$ {
        root /webroot/farm;
        fastcgi_pass 127.0.0.1:9000;     #与php-fpm通信的方式
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
通信方式:
nginx和php-fpm的通信方式有两种,一种是socket形式,一种是tcp形式。配置两种方式都可以,但是必须保证nginx配置的监听方式,和php-fpm.conf配置的监听方式保持一致性!
推荐使用TCP方式也就是方式1,可以跨服务器。 php配置:/etc/php-fpm.conf或者/etc/php-fpm.d/xx.conf
方式1:
php-fpm.conf:       listen = 127.0.0.1:9000
nginx.conf:         fastcgi_pass 127.0.0.1:9000;
方式2:
php-fpm.conf:        listen = /tmp/php-fpm.sock
nginx.conf:          fastcgi_pass unix:/tmp/php-fpm.sock;
其中php-fpm.sock是一个文件,由php-fpm生成,类型是srw-rw----.

vim /etv/php.ini

#short_open_tag = off  改为如下:
short_open_tag = on           #打开短标签

上面配置完成就可以在nginx上部署php项目了。

安装mysql
[root@newrain ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@newrain ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm 
[root@newrain ~]# vim /etc/yum.repos.d/mysql-community.repo 

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1 将0改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0 将1改为0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[root@newrain ~]# yum -y install mysql-server mysql

启动&开机启动

[root@newrain ~]# systemctl start nginx
[root@newrain ~]# systemctl start mysqld          
[root@newrain ~]# systemctl start php-fpm
[root@newrain ~]# systemctl enable nginx
[root@newrain ~]# systemctl enable mysqld
[root@newrain ~]# systemctl enable php-fpm

新网虚拟主机