centos8配置lnmpr


linux下,centos8配置nginx/mysql/php/redis

本文不断打磨,有什么事装个系统和环境,使用最新的系统和软件,如有更新实时记录!!

下面涉及到版本的,建议都访问目录获取最新的release版本。

可能存在的安装错误和解决方案

这个放在前面,大部分都是lnmp的基础库,建议先安装

如果提示:-bash: make: command not found
执行yum -y install automake autoconf libtool make

nginx相关

如果提示:./configure: error: the HTTP rewrite module requires the PCRE library
执行yum -y install pcre-devel

如果提示:./configure: error: C compiler cc is not found
执行yum -y install gcc

如果提示:./configure: error: SSL modules require the OpenSSL library.
执行yum -y install openssl openssl-devel

php相关:

如果提示:configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
执行yum install sqlite-devel

如果提示:configure: error: Package requirements (libcurl >= 7.15.5) were not met:
执行yum install -y libcurl-devel

如果提示:configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:
执行yum install libicu-devel

或者直接省事:

yum install -y gcc gcc-c++  make zlib zlib-devel 
yum install -y automake autoconf libtool make
yum install -y openssl openssl-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel
yum install -y curl curl-devel libicu-devel libcurl-devel sqlite-devel openldap openldap-devel
yum install -y freetype freetype-devel libxml2 libxml2-devel


yum install -y glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel
yum install -y e2fsprogs e2fsprogs-devel krb5 krb5-devel ncurses ncurses-devel 
yum install -y nss_ldap openldap-clients openldap-servers

如果提示:configure: error: Cannot find ldap libraries in /usr/lib.
执行cp -frp /usr/lib64/libldap* /usr/lib/

如果提示:configure: error: Package requirements (oniguruma) were not met:
执行:

# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
# tar -zxf oniguruma-6.9.4.tar.gz
# cd oniguruma-6.9.4
# ./autogen.sh && ./configure --prefix=/usr
# make && make install

nginx安装与配置

wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz 
cd nginx-1.16.1/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install

安装完毕后,测试一下:/usr/local/nginx/sbin/nginx -t

配置安全组后,可以配置防火墙端口:

firewall-cmd --state
firewall-cmd --list-ports
systemctl enable firewalld --now
firewall-cmd --query-port=80/tcp
systemctl restart firewalld.service

启动nginx服务:/usr/local/nginx/sbin/nginx

增加开机启动:
将上述命令放到/etc/rc.d/rc.local
(好像无效,centos8要通过chkconfig实现,参考下述收尾)

php7安装与配置

https://www.php.net/distributions/php-7.4.10.tar.gz
tar -zxvf php-7.4.10.tar.gz
cd php-7.4.10/

最基础的编译参数:`
./configure --prefix=/usr/local/php --enable-fpm --with-pdo-mysql --with-openssl`

作为一个开发环境,推荐使用以下完整编译参数,遇到问题直接yum就可以成功的是:

./configure  --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm --enable-pcntl

当上面的configure出现了如下提示,则表示一切准备就绪(否则就遇神杀神佛挡弑佛ba...)

Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

完美,接下来执行三部曲(其实test没啥用):

$ make
$ make test
$ make install

安装成功提示:

[root@localhost php-7.4.11]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20190902/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM defconfig:     /usr/local/php/etc/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/php/fpm/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.9
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.9 is not the recommended version 1.4.4
[PEAR] PEAR           - installed: 1.10.12
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/root/php-7.4.11/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

三大缺少文件:

一、将同目录中的www.conf.defalt修改成php-fpm.conf:

cd /usr/local/php/etc/php-fpm.d/
cp -a www.conf.default www.conf

二、将/usr/local/php/etc/php-fpm.conf.default拷贝一个作为php-fpm.conf:

/usr/local/php/etc/
cp -a php-fpm.conf.default php-fpm.conf

三、压缩包的根目录拷贝php.ini-production到php安装目录/usr/local/php/etc下:

cp -a /root/php-7.xx.xx/php.ini-development /usr/local/php/etc/php.ini

手动启动php-fpm

先创建编译指定的www用户:useradd www(会自动创建同名用户组)

执行:/usr/local/php/sbin/php-fpm

表示已经启动了php-fpm了:ps aux|grep php-fpm |grep -v grep

php-fpm 开机启动

修改/usr/local/php/etc/php-fpm.conf
开启pid去掉pid = run/php-fpm.pid注释

php-fpm启动脚本,拷贝到/etc/init.d/目录下:
cp /root/php-7.3.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
授权chmod a+x /etc/init.d/php-fpm

ps aux|grep php-fpm
查看状态:/etc/init.d/php-fpm status
{start|stop|force-quit|restart|reload|status|configtest}

设置开机启动

#chkconfig --add /etc/init.d/php-fpm
#chkconfig php-fpm on

(配置user和groud为www的/usr/local/php/etc/php-fpm.d/www.conf否则mkdir不行)
(配置session存储/usr/local/php/etc/php.ini配置session.save_path = "/var/lib/php/session")

详细配置(含用phpize无需重新安装增加openssl模块):

cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -t
[root@localhost php-fpm.d]# service php-fpm start
ps aux|grep php-fpm
vim /etc/rc.local 
vim /etc/rc.d/rc.local
location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}

收尾配置

nginx 开机启动:

#vim /etc/init.d/nginx
(https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/)
Usage: /etc/init.d/nginx {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}
#chmod a+x /etc/init.d/nginx
#chkconfig --add /etc/init.d/nginx
#chkconfig nginx on

很重要?:/root/php-7.3.13/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

composer install --ignore-platform-reqs

当前用户的全局变量

# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
# ln -s /usr/local/php/bin/php /usr/local/bin/

安装了php7之后再安装php5的操作:
(待续...)

重启改为手动启动LNMPR的方式

创建~/start.sh文件,粘帖下面内容后执行sh start.sh即可手动启动

sudo systemctl start mariadb
/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx
/etc/init.d/redis start

注意这些路径都必须按本文的安装路径缺省

其他

  • php查看编译参数:

    /usr/local/php/bin/php -i |grep configure

  • File not found.

    一般都是与php-fpm衔接出错,注意fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;即可

  • 安装composer

    官网https://packagist.org/

    直接下载到当前目录:wget https://getcomposer.org/composer.phar

    下载完之后,拷贝到全局执行目录:cp -a composer.phar /usr/local/bin/composer

  • mysql和redis

    剩下的mysql和redis由本站点的其他笔记发布,搜索mariadbredis即可...

  • composer的安装和使用
# /usr/local/php/bin/php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
# /usr/local/php/bin/php composer-setup.php
直接安装:
# /usr/local/php/bin/php /root/composer.phar install

版权声明,转载请附上原文链接及本声明: https://blog.yongit.com/note/211000.html