CentOS 7安装 LNMP(Linux+Nginx+MariaDB+PHP) - 开发说
当前位置: 主页 » Centos » CentOS 7安装 LNMP(Linux+Nginx+MariaDB+PHP)

CentOS 7安装 LNMP(Linux+Nginx+MariaDB+PHP)

      2017年07月11日   阅读 1,830 次     0 评论   Tags: · · ·

update: 2017-12-19 PHP7.2.0开始移除mcrypt模块,移除libmcrypt、libmcrypt-devel、mcrypt包和相应的PHP编译–enable-gd-native-ttf 和–with-mcrypt参数。
安装mcrypt参考:编译安装的PHP7.2如何安装mcrypt扩展

系统环境和对应软件版本。
systemos:centos7.6以上
nginx-1.17.6
MariaDB-10.4.10
php-7.3.12


1、安装EPEL源

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

1.1、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.2、安装相关依赖包:

[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.3、更新系统

[root@uscdn1 ~]# yum -y update

1.4、设置系统时间

[root@uscdn1 ~]# timedatectl set-timezone Asia/Hong_Kong [root@uscdn1 ~]# timedatectl

1.5、创建openladp库链接

[root@uscdn1 ~]# cp -frp /usr/lib64/libldap* /usr/lib/

1.6、删除原有的libzip包 并安装libzip-1.2.0

[root@uscdn1 ~]# yum remove libzip* [root@uscdn1 ~]# cd /usr/local/src [root@uscdn1 ~]# wget https://nih.at/libzip/libzip-1.2.0.tar.gz [root@uscdn1 ~]# tar xf libzip-1.2.0.tar.gz [root@uscdn1 ~]# tar xf libzip-1.2.0 [root@uscdn1 ~]# cd libzip-1.2.0 [root@uscdn1 ~]# ./configure && make && make install [root@uscdn1 ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

1.7、重新配置加载ld.so.conf文件

[root@uscdn1 ~]# echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf # 更新配置 [root@uscdn1 ~]# ldconfig -v

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


###稳定版:
Centos 7:
[root@uscdn1 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Centos 6:
[root@uscdn1 ~]# rpm -Uvh  http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

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

[root@uscdn1 ~]# vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 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源



[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 -y 启动和自启动 [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



[root@uscdn1 ~]# wget http://php.net/distributions/php-7.3.12.tar.gz
[root@uscdn1 ~]# tar xf php-7.3.12.tar.gz
[root@uscdn1 ~]# cd php-7.3.12
[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-dir' \
'--with-jpeg-dir' \
'--with-png-dir' \
'--with-zlib' \
'--with-libxml-dir' \
'--enable-xml' \
'--disable-rpath' \
'--enable-bcmath' \
'--enable-shmop' \
'--enable-sysvsem' \
'--enable-inline-optimization' \
'--with-curl' \
'--enable-mbregex' \
'--enable-mbstring' \
'--enable-intl' \
'--enable-ftp' \
'--with-gd' \
'--enable-gd-jis-conv' \
'--with-openssl' \
'--with-mhash' \
'--enable-pcntl' \
'--enable-sockets' \
'--with-xmlrpc' \
'--enable-zip' \
'--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.3.12]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@uscdn1 php-7.3.12]# 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


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

UPDATE:2017/7/11,PHP7已经自带了CENTOS 7的启动脚本不需要重写脚本,直接复制就可以了:

CENTOS 6
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

CENTOS 7
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/

PHP编译参数详解:

 ./configure \
--prefix=/usr/local/php \                               [php安装的根目录]
--exec-prefix=/usr/local/php \                          [php执行文件所在目录]
--bindir=/usr/local/php/bin \                           [php/bin目录]
--sbindir=/usr/local/php/sbin \                         [php/sbin目录]
--includedir=/usr/local/php/include \                   [php包含文件所在目录]
--libdir=/usr/local/php/lib/php \                       [php/lib目录]
--mandir=/usr/local/php/php/man \                       [php/man目录]
--with-config-file-path=/usr/local/php/etc \            [php的配置目录]
--with-mysql-sock=/var/run/mysql/mysql.sock \           [php的Unix socket通信文件]
--with-mcrypt \                                         [是php里面重要的加密支持扩展库,linux环境下该库在默认情况下不开启]
--with-mhash \                                          [Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启]
--with-openssl \                                        [OpenSSL 是一个安全套接字层密码库]
--with-mysqli=shared,mysqlnd \                          [php依赖mysql库]
--with-pdo-mysql=shared,mysqlnd \                       [php依赖mysql库]
--with-gd \                                             [gd库]                                               
--with-iconv \                                          [关闭iconv函数,种字符集间的转换]                        
--with-zlib \                                           [zlib是提供数据压缩用的函式库]
--enable-zip \                                          [打开对zip的支持]
--enable-inline-optimization \                          [优化线程]
--disable-debug \                                       [关闭调试模式]
--disable-rpath \                                       [关闭额外的运行库文件]
--enable-shared \                                       [启用动态库]
--enable-xml \                                          [开启xml扩展]
--enable-bcmath \                                       [打开图片大小调整,用到zabbix监控的时候用到了这个模块]
--enable-shmop \                                        [共享内存]
--enable-sysvsem \                                      [内存共享方案]
--enable-mbregex \                                      [开启多字节正则表达式的字符编码。]
--enable-mbstring \                                     [开启多字节字符串函数]
--enable-ftp \                                          [开启ftp]
--enable-gd-native-ttf \                                [开启gd库原有字体]
--enable-pcntl \                                        [PHP的进程控制支持实现了Unix方式的多进程创建]     
--enable-sockets \                                      [开启套节字]
--with-xmlrpc \                                         [打开xml-rpc的c语言]
--enable-soap \                                         [开启简单对象访问协议简单对象访问协议]
--without-pear \                                        [开启php扩展与应用库]
--with-gettext \                                        [开户php在当前域中查找消息]
--enable-session \                                      [允许php会话session]
--with-curl \                                           [允许curl扩展]
--with-jpeg-dir \                                       [指定jpeg安装目录yum安装过后不用再次指定会自动找到]
--with-freetype-dir \                                   [指定freetype安装目录yum安装过后不用再次指定会自动找到]
--enable-opcache \                                      [开启使用opcache缓存]
--enable-fpm \                                          [开启fpm]
--with-fpm-user=nginx \                                 [php-fpm的用户]
--with-fpm-group=nginx \                                [php-fpm的用户组]
--without-gdbm \                                        [数据库函数使用可扩展散列和类似于标准UNIX dbm的工作]
--enable-fast-install \                                 [为快速安装优化]

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

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

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

    发表回复

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