Centos7.7安装LNMP(PHP-7.4.5 Nginx-1.18.0 MariaDB-10.4.12) - AFF大佬
当前位置: 主页 » 技术干货 » Centos7.7安装LNMP(PHP-7.4.5 Nginx-1.18.0 MariaDB-10.4.12)

Centos7.7安装LNMP(PHP-7.4.5 Nginx-1.18.0 MariaDB-10.4.12)

      2020年04月21日   阅读 466 次     0 评论   Tags: · ·

PHP7.4也出了一段时间了,也尝试升级过,一直升级错误,今天折腾一下,升级成功了。

系统环境和对应软件版本。
systemos:centos7.7以上
nginx-1.18.0
MariaDB-10.4.12
php-7.4.5

在Centos 8 中部署LNMP环境并安装WordPress
CentOS 7安装 LNMP(Linux+Nginx+MariaDB+PHP)
Centos7 LNMP一键安装脚本

1、安装依赖环境


1.1、安装EPEL源

[root@uscdn1 ~]# yum -y install epel-release.noarch

1.2、firewalld开放http和https端口

[root@uscdn1 ~]# firewall-cmd --zone=public --add-service=http --permanent
[root@uscdn1 ~]# firewall-cmd --zone=public --add-service=https --permanent
[root@uscdn1 ~]# firewall-cmd --reload


1.3、安装相关依赖包:

[root@uscdn1 ~]# yum -y install gcc gcc-c++ make cmake  perl autoconf automake libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel pcre pcre-devel libtool  pcre-devel libaio-devel libaio bzip2-devel libcurl-devel gd-devel bison bison-devel  mhash openldap openldap-devel libicu-devel

1.4、更新系统

[root@uscdn1 ~]# yum -y update

1.5、设置系统时间
[root@uscdn1 ~]# timedatectl set-timezone Asia/Hong_Kong
[root@uscdn1 ~]# timedatectl

1.6、创建openladp库链接
[root@uscdn1 ~]# cp -frp /usr/lib64/libldap* /usr/lib/

1.7、安装oniguruma
yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-5.9.5-3.el7.x86_64.rpm
yum install -y https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-5.9.5-3.el7.x86_64.rpm

2、添加nginx stable(稳定版或者开发板)源 ,在http://nginx.org/packages/centos/7/noarch/RPMS/ 查看最新库信息


2.1、添加nginx稳定版:
[root@uscdn1 ~]#  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
module_hotfixes=true

2.1.1、添加nginx mainline(长期开发版)源

[root@uscdn1 ~]#  vi /etc/yum.repos.d/nginx.repo 

[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
module_hotfixes=true


2.2、安装nginx,nginx启动和自启动

[root@uscdn1 ~]# yum -y install nginx
[root@uscdn1 ~]# systemctl enable nginx.service 
[root@uscdn1 ~]# systemctl start nginx.service

nginx配置文件位置(配置文件都是一样的)
nginx主配置文件:/etc/nginx/nginx.conf
nginx默认配置文件目录:/etc/nginx/conf.d/
nginx默认站点主目录:/usr/share/nginx/html/
nginx默认日志目录:/var/log/nginx/

3、创建mariadb源,安装mariadb


[root@uscdn1 ~]# vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


3.1、安装mariadb

[root@uscdn1 ~]# yum install -y MariaDB-shared MariaDB-server MariaDB-client MariaDB MariaDB-devel jemalloc

启动和自启动
[root@uscdn1 ~]# systemctl enable mariadb.service
[root@uscdn1 ~]# systemctl start mariadb.service


初始化MySQL数据库并创建密码
[root@uscdn1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2021
Server version: 10.4.10-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'mysqlrootpwd';
MariaDB [(none)]> use mysql;
MariaDB [(none)]> delete from user where password="";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

4、安装PHP-7.4.5


[root@uscdn1 ~]# wget http://php.net/distributions/php-7.4.5.tar.gz
[root@uscdn1 ~]# tar xf php-7.4.5.tar.gz
[root@uscdn1 ~]# cd php-7.4.5
[root@uscdn1 ~]# vi config.nice 

#! /bin/sh
#
# Created by configure

'./configure' \
'--prefix=/usr/local/php' \
'--with-config-file-path=/usr/local/php/etc' \
'--enable-fpm' \
'--with-fpm-user=nobody' \
'--with-fpm-group=nobody' \
'--enable-mysqlnd' \
'--with-mysqli=mysqlnd' \
'--with-pdo-mysql=mysqlnd' \
'--enable-mysqlnd-compression-support' \
'--with-iconv-dir' \
'--with-freetype' \
'--with-jpeg' \
'--with-zlib' \
'--enable-xml' \
'--disable-rpath' \
'--enable-bcmath' \
'--enable-shmop' \
'--enable-sysvsem' \
'--enable-inline-optimization' \
'--with-curl' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-intl' \
'--enable-ftp' \
'--enable-gd' \
'--with-webp' \
'--enable-gd-jis-conv' \
'--with-openssl' \
'--with-mhash' \
'--enable-pcntl' \
'--enable-sockets' \
'--with-xmlrpc' \
'--enable-soap' \
'--with-gettext' \
'--enable-opcache' \
'--with-pear' \
'--with-ldap=shared' \
'--enable-embed' \
'--without-gdbm' \
'--enable-fast-install' \
'--disable-fileinfo' \
'--without-sqlite3' \
'--without-pdo-sqlite' \
"$@"

[root@uscdn1 ~]# chmod +x config.nice
[root@uscdn1 ~]# ./config.nice && make && make install
[root@uscdn1 php-7.4.5]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@uscdn1 php-7.4.5]# cp php.ini-production /usr/local/php/etc/php.ini
[root@uscdn1 ~]# cd /usr/local/php/etc
[root@uscdn1 ~]# cp php-fpm.conf.default php-fpm.conf
[root@uscdn1 ~]# cd php-fpm.d
[root@uscdn1 ~]# cp www.conf.default www.conf

### 安装Cmake3、pdo_mysql和libzip,让PHP支持MySQL PDO和ZIP扩展

[root@uscdn1 ~]# yum remove -y libzip
[root@uscdn1 ~]# yum install -y cmake3
[root@uscdn1 ~]# sudo ln -sf /usr/bin/cmake3 /usr/bin/cmake
[root@uscdn1 ~]# cd /usr/local/src/
[root@uscdn1 ~]# wget https://libzip.org/download/libzip-1.6.1.tar.gz
[root@uscdn1 ~]# tar xf libzip-1.6.1.tar.gz 
[root@uscdn1 ~]# cd libzip-1.6.1
[root@uscdn1 ~]# mkdir build && cd build
[root@uscdn1 ~]# cmake ..
[root@uscdn1 ~]# make && make install
[root@uscdn1 ~]# /usr/local/php/bin/pecl install zip

###安装MySQL PDO扩展

[root@uscdn1 php-7.4.5]# cd ext/pdo_mysql/
[root@uscdn1 php-7.4.5]# /usr/local/php/bin/phpize 
[root@uscdn1 php-7.4.5]# ./configure -with-php-config=/usr/local/php/bin/php-config -with-pdo-mysql=mysqlnd
[root@uscdn1 php-7.4.5]# make && make install

5、配置php.ini、php-fpm.conf、www.conf文件



[root@uscdn1 php-7.4.5]# vi /usr/local/php/etc/php.ini

;配置MySQL socket文件
pdo_mysql.default_socket= /var/lib/mysql/mysql.sock
mysqli.default_socket = /var/lib/mysql/mysql.sock

;不显示错误,默认
display_errors = Off

;在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置),默认
log_errors = On

;字符集,默认
default_charset = "UTF-8"

;文件上传大小,默认值太小,建议修改10M
upload_max_filesize = 2M

;Maximum size of POST data that PHP will accept.  表单最大值,默认是8M,如果表单含有多图上传,大小可能不够。超过该大小后台收不到 表单数据
post_max_size = 8M

;设置PHP的扩展库路径,默认被注释了,之后一个文件夹 于 你/usr/local/php/lib/php/extensions/ 下的文件夹同名。
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/"
extension = "pdo_mysql.so"
extension = "ldap.so"
extension = "zip.so"

;设置PHP的时区
date.timezone = PRC

;开启opcache,默认是0
[opcache]
; Determines if Zend OPCache is enabled
zend_extension= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/opcache.so"
opcache.enable=1

### 配置/usr/local/php/etc/php-fpm.conf文件

[root@uscdn1 php-7.4.5]# vi /usr/local/php/etc/php-fpm.conf

; 去掉里分号,方便以后重启。建议修改
;Default Value: none
; 下面的值最终目录是/usr/local/php/var/run/php-fpm.pid
; 开启后可以平滑重启php-fpm
pid = run/php-fpm.pid

; 设置错误日志的路径,可以默认值
; Note: the default prefix is /usr/local/php/var
; Default Value: log/php-fpm.log, 即/usr/local/php/var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log

; Log等级,可以默认值
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; 后台运行,默认yes,可以默认值
; Default Value: yes
;daemonize = yes

; 引入www.conf文件中的配置,可以默认值
include=/usr/local/php/etc/php-fpm.d/*.conf

### 配置/usr/local/php/etc/php-fpm.d/www.conf

[root@uscdn1 php-7.4.5]# vi /usr/local/php/etc/php-fpm.d/www.conf
; 设置用户和用户组,默认都是nobody。可以默认值
user = nobody
group = nobody

; 设置PHP监听
; 下面是默认值,不建议使用。可以默认值
listen = 127.0.0.1:9000
; 根据nginx.conf中的配置fastcgi_pass unix:/dev/shm/php-fpm.sock;
listen = /dev/shm/php-fpm.sock

;修改权限
listen.owner = nobody
listen.group = nobody
listen.mode = 0660

######开启慢日志。可以默认值
slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s



### 添加PHP-fpm自启动和启动
[root@uscdn1 ~]# systemctl enable php-fpm.service 
[root@uscdn1 ~]# systemctl start php-fpm.service 

至此,最新版LNMP(PHP-7.4.5 Nginx-1.18.0 MariaDB-10.4.12)安装完成。

  • 版权声明:本文版权归AFF大佬和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 AFF大佬 整理发布,欢迎转载,转载请带版权。

  • 来源:AFF大佬 ( https://www.affdalao.com/ ),提供主机优惠信息深度测评和服务器运维编程技术。
  • 链接:https://www.affdalao.com/1778.html
  • 评论(0

    1. 还没有任何评论,你来说两句吧

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注

    本站CDN由CdnTiger提供
    本站DNS解析由TOYDNS提供