CentOS7 compile and install L(A|N)MP environment

Compilation process and steps##

# Compile and install LAMP combination:
# httpd+php
# cgi
# pm(fastcgi): Php as an independent service
# httpd support for fastcgi protocol:
# httpd-2.2:Need to install additional fcgi module;
# httpd-2.4:Comes with fcgi module;
# Installation sequence:
# Sequence: mariadb–>httpd–>php
# The order of httpd and mariadb does not matter, PHP is the last, because the path of httpd must be specified when PHP is compiled

# Install development tools
yum groupinstall "Development tools"

Apache compile and install###

wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.41.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.7.0.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

Compilation of apr and pcre####

[ root@master httpd]# tar -xvf apr-1.7.0.tar.gz && cd apr-1.7.0[root@master apr-1.7.0]# ./configure --profix=/usr/local/apr
[ root@master apr-1.7.0]# make && make install

[ root@master httpd]# tar -xvf apr-util-1.6.1.tar.gz && cd apr-util-1.6.1[root@master apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr
[ root@master apr-util-1.6.1]# make && make install

[ root@master httpd]# tar -xvf pcre-8.43.tar.gz && cd pcre-8.43[root@master pcre-8.43]# ./configure --prefix=/usr/local/pcre
[ root@master pcre-8.43]# make && make install

httpd compilation####

# Required dependencies
ncurses-devel expat-devel zlib-static zlib-devel autoconf freetype 
libjpeg libjpeg-devel libpng libpng-del libxml2 libxml2-devel freetype-devel
curl-devel libtool libtool-ltdl libtool-ltdl-devel libevent libevent-devel 

# Compilation process
[ root@master httpd]# tar -xvf httpd-2.4.41.tar.gz 
[ root@master httpd]# cd httpd-2.4.41[root@master httpd-2.4.41]# ./configure --prefix=/usr/local/apache --enable-mods-shared=most --enable-headers --enable-mime-magic \
- - enable-proxy --enable-so --enable-rewrite --enable-proxy-fcgi --enable-cgi --enable-ssl --enable-proxy-http2 --enable-ssl \
- - enable-deflate --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util \
- - with-nghttp2=/usr/local/nghttp2 --enable-mpms-shared=all --enable-nonportable-atomics=yes --enable-remoteip --enable-http2 
[ root@master httpd-2.4.41]# make -j8 && make install

[ root@master httpd]# groupadd apache
[ root@master httpd]# useradd -g apache -r -M -s /usr/sbin/nologin apache
# Create a system account,Do not create a home directory, specify the group as apache, use nologin to create an apache user
[ root@master apache]# chown -R apache:apache ./*
[ root@master apache]# PATH=$PATH:/usr/local/apache
[ root@master apache]# export $PATH
[ root@master apache]# vim /etc/httpd/httpd.conf
User apache
Group apache

# You can copy apachectl to init.d directory
[ root@master ~]# ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd

# Configure how the daemon starts
[ root@master apache]# chown -R apache:apache ./*
[ root@master apache]# cp bin/apachectl /etc/init.d/httpd
[ root@master apache]# chkconfig --add httpd
[ root@master apache]# chkconfig httpd on
[ root@master apache]# chkconfig --list

# CentOS7 systemctl startup method
[ root@master ~]# vim /etc/systemd/system/httpd.service
[ Unit]
Description=Apache Server Daemon
Documentation=man:httpd  man:httpd(8) man:apachectl
After=network.target rsyslog.service

[ Service]
Type=forking
ExecStart=/etc/init.d/httpd -k start
ExecStop=/etc/init.d/httpd -k stop
ExecReload=/etc/init.d/httpd -k graceful
ExecRestart=/etc/init.d/httpd -k restart

[ Install]
WantedBy=multi-user.target

MySql compile and MariaDB installation###

MySql compile####

# Download source package
[ root@master httpd]# wget https://github.com/Kitware/CMake/releases/download/v3.16.2/cmake-3.16.2.tar.gz
[ root@master httpd]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
[ root@master httpd]# wget  http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
# Compile cmake
[ root@master httpd]# tar vxf cmake-3.13.4.tar.gz  && cd cmake-3.13.4[root@master cmake-3.13.4]# ./configure 
[ root@master cmake-3.13.4]# make && make install
# Initialize the boost library
[ root@master httpd]# tar xvf boost_1_59_0.tar.gz
[ root@master httpd]# cp -r boost_1_59_0 /usr/local/boost_1_59

#- - BEGIN--
# rely
cmake ncurses-devel gcc gcc-c++ pcre pcre-devel openssl openssl-devel
#- - END--

# Compile mysql
[ root@master httpd]# groupadd mysql #Create mysql user
[ root@master httpd]# useradd -M -g mysql -r -s /usr/sbin/nologin mysql
[ root@master httpd]# id mysql
uid=994(mysql) gid=1002(mysql) groups=1002(mysql)[root@master httpd]# tar xvf mysql-5.7.28.tar.gz && mysql-5.7.28[root@master httpd]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 \ #installation manual
- DWITH_BOOST=/usr/local/boost_1_59_0 \ #Boost library path
- DDOWNLOAD_BOOST=1 \ #If there is no boost library, whether to automatically download the boost library to the boost path,There is no need to add this to the local boost library
- DMYSQL_UNIX_ADDR=/data/mysql/tmp/mysql.sock \ #Unix socket storage directory
- DMYSQL_DATADIR=/mnt/data/data \ #Data storage directory
- DSYSCONFDIR=/etc/mysql \ #Configuration file installation directory
- DDEFAULT_CHARSET=utf8mb4 \ #Character set used by Mysql
- DDEFAULT_COLLATION=utf8mb4_general_ci \ #Mysql collation
- DWITH_EXTRA_CHARSETS=all \ #Extra character set
- DWITH_MYISAM_STORAGE_ENGINE=1 \ #Enable InnoDB
- DWITH_INNOBASE_STORAGE_ENGINE=1 \ #Enable ARCHIVE
- DWITH_MEMORY_STORAGE_ENGINE=1 \ #Enable MEMORY
- DWITH_READLINE=1 \ #Whether to support line-by-line reading
- DWITH_INNODB_MEMCACHED=1 \ #Whether to generate memcached shared library
- DWITH_DEBUG=OFF \ #Whether to enable build debugging
- DWITH_ZLIB=bundled \ #Use zlib bundled with the distribution library
- DENABLED_LOCAL_INFILE=1 \ #Control the built-in default functions of the local MySQL client library
- DENABLED_PROFILING=ON \ #Whether to enable query profiling code
- DMYSQL_MAINTAINER_MODE=OFF \ #Whether to enable the development environment specific to MySQL maintainers
- DMYSQL_TCP_PORT=3306 #Port used by MySQL
[ root@master httpd]# make -j8 && make install
# Compile configuration reference:
# https://zhuanlan.zhihu.com/p/60045437
# https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html

# Configuration
[ root@master local]# ln -sv mysql57 mysql #Establish soft connection
[ root@master bin]# PATH=$PATH:/usr/local/mysql/bin
[ root@master bin]# export PATH
[ root@master bin]#  mkdir -p /mnt/data/{data,logs,pids,share}

# Initialize the directory
[ root@master bin]# touch /mnt/data/pids/mysqld.pid
[ root@master bin]# touch /mnt/data/logs/mysqld.log
[ root@master data]# chown -R mysql:mysql /mnt/data/

# Modify the configuration file
[ root@master data]# vim /etc/my.cnf
[ mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
datadir=/mnt/data/data
socket=/mnt/data/tmp/mysql.sock

[ mysqld_safe]
log-error=/mnt/data/logs/mysqld.log
pid-file=/mnt/data/pids/mysqld.pid

[ client]default-character-set=utf8mb4

# Join init.d daemon
[ root@master mysql57]# cp support-files/mysql.server /etc/init.d/mysqld
[ root@master mysql57]# chkconfig --add mysqld
[ root@master mysql57]# chkconfig mysqld on
[ root@master mysql57]# chkconfig --list mysqld #Check whether to create a self-starting process

# Initializing the database requires opening the database to initialize
[ root@master data]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql57 --datadir=/mnt/data/data

# Safe initialization
[ root@master ~]# mysql_secure_installation 

# systemctl start mysql
[ root@master system]# vim /etc/systemd/system/mysqld.service 
[ Unit]
Description=MySQL Service
Documentation=man:mysqld man:mysqld(8)
After=network.target 

[ Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
ExecReload=/etc/init.d/mysqld reload
ExecRestart=/etc/init.d/mysqld restart

[ Install]
WantedBy=multi-user.target
[ root@slave system]# systemctl daemon-reload  #Overload management service

# Start the test
[ root@master system]# systemctl start mysqld.service 
[ root@master system]# systemctl status mysqld.service  
● mysqld.service - MySQL Service
 Loaded:loaded(/etc/systemd/system/mysqld.service; disabled; vendor preset: disabled)
 Active:active(running) since Thu 2020-01-0222:25:29 CST; 1s ago
  Docs: man:mysqld
   man:mysqld(8)
 Process:21577 ExecStart=/etc/init.d/mysqld start(code=exited, status=0/SUCCESS)
 Main PID:21587(mysqld_safe)
 CGroup:/system.slice/mysqld.service
   ├─21587/bin/sh /usr/local/mysql57/bin/mysqld_safe --datadir=/mnt/data/data --pid-file=/mnt/data/pids/mysqld.pid
   └─21751/usr/local/mysql57/bin/mysqld --basedir=/usr/local/mysql57 --datadir=/mnt/data/data --plugin-dir=/usr/local/mysql57/lib/plugin --u...[root@master system]# mysql
mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows inset(0.00 sec)

MariaDB binary package manual installation

# Create a running user
[ root@slave ~]# groupadd mysql
[ root@slave ~]# useradd -r -M -g mysql -s /usr/sbin/nologin mysql

[ root@slave local]# tar -xvf mariadb-10.4.11-linux-x86_64.tar.gz -C /usr/local/[root@slave local]# ln -sv mariadb-10.4.11-linux-x86_64/ mysql
[ root@slave mysql]# . scripts/mysql_install_db --datadir=/data/data  --user=mysql #Initialize the database directory

# Set environment variables and create log files
[ root@slave system]# PATH=$PATH:/usr/local/mysql/bin/[root@slave system]# mkdir /var/log/mariadb
[ root@slave system]# touch /var/log/mariadb/mariadb.log
[ root@slave system]# chown mysql:mysql /var/log/mariadb/mariadb.log
[ root@slave system]# touch /tmp/mysql.sock
[ root@slave system]# chown mysql:mysql /tmp/mysql.sock 

# Add configuration file
[ root#slave system]# vim /etc/my.cnf
[ mysqld]
port    =3306
socket  =/tmp/mysql.sock
datadir=/data/data
symbolic-links=0
innodb_file_per_table = on
skip_name_resolve = on
key_buffer_size = 128M
skip-external-locking
max_allowed_packet = 1M
table_open_cache =512
sort_buffer_size = 2m
read_buffer_size = 2M
read_rnd_buffer_size = 8M
query_cache_size = 32M

[ mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

# Copy startup script
[ root@slave mysql]# cp support-files/mysql.server /etc/init.d/mysqld

# Add systemctl management script
[ root@slave system]# vim /etc/systemd/system/mariadb.service
[ Unit]
Description=MariaDB Service
Documentation=man:mariadb
After=network.target

[ Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
ExecReload=/etc/init.d/mysqld reload
ExecRestart=/etc/init.d/mysqld restart

[ Install]
WantedBy=multi-user.target
[ root@slave system]# systemctl daemon-reload 

# Safe initialization
[ root@slave mysql]# ./bin/mysql_secure_installatio

PHP compilation and enabling FPM

# Compile dependency
libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel libicu-devel libzip-devel

# Download source package
[ root@master httpd]# wget http://mirror.cogentco.com/pub/php/php-7.0.9.tar.gz

# Establish running users and user groups
[ root@master php-7.0.9]# groupadd www
[ root@master php-7.0.9]# useradd -r -M -g www -s /sbin/nologin www

# Compilation process
[ root@master httpd]# tar -xvf php-7.0.9.tar.gz && cd php-7.0.9/

# Set compilation parameters
[ root@master php-7.0.9]# ./configure \
- - prefix=/usr/local/php7 --with-config-file-path=/etc/php --enable-fpm --with-fpm-user=www  --with-fpm-group=www \
- - enable-inline-optimization --disable-debug --disable-rpath --enable-shared --with-libxml-dir \
- - with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-zlib --with-iconv --with-bz2 --with-curl \
- - enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir \
- - with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext \
- - with-gmp --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-onig \
- - enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-readline --enable-session \
- - enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir \
- - with-xsl --enable-zip --with-pear --enable-opcache --with-mcrypt 
[ root@master httpd]# make -j8 && make install 

# Initialize the configuration file and start php-fpm
[ root@master php-7.0.9]# cp php.ini-production /etc/php/php.ini
[ root@master php-7.0.9]# cp /usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf
[ root@master php-7.0.9]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf

# Modify the configuration file
[ root@master php7]# vim etc/php-fpm.conf
[ global]
pid =/var/run/php-fpm.pid
error_log =/www/log/php-fpm.log
log_level = notice
[ www]
listen =/tmp/php-fpm.sock
listen.backlog =-1
listen.allowed_clients =127.0.0.1
listen.owner = www
listen.group = www
listen.mode =0666
user = www
group = www
pm = dynamic
pm.status_path =/status
pm.max_children =30
pm.start_servers =5
pm.min_spare_servers =5
pm.max_spare_servers =10
request_terminate_timeout =100
request_slowlog_timeout =30
slowlog =/www/log/slow.log
request_slowlog_timeout = 1s

# Add php-The fpm daemon runs
[ root@master ~]# vim /etc/systemd/system/php-fpm.service
[ Unit]
Description=The FastCGI Process Manager
Documentation=php-fpm service
After=rsyslog.target network.target

[ Service]
Type=simple
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[ Install]
WantedBy=multi-user.target

Compilation FAQ####

# libmcrypt is not installed
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

# Solution:yum install or compile and install
[ root@master php-7.0.9]# yum -y install libmcrypt-devel
# Compile and install
[ root@master httpd]# wget https://src.fedoraproject.org/repo/pkgs/libmcrypt/libmcrypt-2.5.8.tar.gz/0821830d930a86a5c69110837c55b7da/libmcrypt-2.5.8.tar.gz
[ root@master httpd]# mv download libmcrypt-2.5.8.tar.gz
[ root@master libmcrypt-2.5.8]# tar xvf libmcrypt-2.5.8.tar.gz  && cd libmcrypt-2.5.8[root@master libmcrypt-2.5.8]# ./configure --prefix=/usr

# problem
configure: error: Don t know how to define struct flock on this system,set--enable-opcache=no

# Solution
[ root@master httpd]# vim /etc/ld.so.conf
include /usr/local/lib  #Add this line
[ root@master httpd]# ldconfig  

php compilation parameter explanation

# Compilation parameter explanation
- - prefix=/usr/local/php                      //Specify the php installation directory--with-apxs2=/usr/local/apache/bin/apxs      //Integrate apache,//apxs function is to use mod_LoadModule instruction in so,//Load the specified module to apache, requiring apache to open the SO module--with-config-file-path=/usr/local/php/etc    //Specify php.ini position--with-MySQL=/usr/local/mysql                 //mysql installation directory, support for mysql--with-mysqli=/usr/local/mysql/bin/mysql_config
      //mysqli extension technology can not only call MySQL stored procedures and handle MySQL transactions,//It can also make access to the database more stable.--enable-safe-mode    //Turn on safe mode--enable-ftp          //Open ftp support--enable-zip          //Open support for zip--with-bz2            //Open support for bz2 files--with-jpeg-dir       //Turn on support for jpeg images--with-png-dir        //Open support for png images--with-freetype-dir   //Open support for freetype font library--without-iconv       //Turn off the iconv function, conversion between various character sets--with-libXML-dir     //Open the support of libxml2 library--with-XMLrpc         //Open xml-rpc's c language--with-zlib-dir       //Open the support of zlib library--with-readline       //Whether to open CLI or CGI--with-gd             //Open gd library support--enable-gd-native-ttf //Support TrueType string function library--with-curl            //Open the support of curl browsing tool--with-curlwrappers    //Use curl tool to open url stream--with-ttf             //Open freetype1.*Support, you can omit--with-xsl             //Open XSLT file support, expand libXML2 library, libxslt software is required--with-gettext         //Open gnu's gettext support, the coding library is used--with-pear            //Turn on the support of the pear command, for PHP extensions--enable-calendar      //Open calendar extension--enable-mbstring      //Multi-byte, string support--enable-bcmath        //Turn on image resizing,This module is used when zabbix monitoring is used--enable-sockets       //Open socket support--enable-exif          //Image metadata support--enable-magic-quotes  //Magic quote support--disable-rpath        //Close additional runtime files--disable-debug        //Turn off debug mode--with-mime-magic=/usr/share/file/magic.mime  //Magic header file location--enable-fastCGI       //php5.2 click to open--enable-opcache       //
- - enable-fpm                 //Type in PHP-This parameter is only available after fpm patch, the startup program php5 installed in CGI mode.3 or more use--enable-fastCGI             //Support fastcgi way to start PHP--enable-force-CGI-redirect  //Start PHP by redirection--with-ncurses         //Dynamic library supporting ncurses screen drawing and graphical interactive functions based on text terminals--enable-pcntl         //FreeTDS needs to be used, may be used only when linking mssql--with-mcrypt          //Extension of mcrypt algorithm--with-mhash           //Extension of mhash algorithm//The above library needs to be installed--with-gmp                     //Should support a norm--enable-inline-optimization   //Optimize thread--with-openssl                 //OpenSSL support, used in encrypted transmission--enable-dbase                 //Establish DBA as a shared module--with-pcre-dir=/usr/local/bin/pcre-config       //Perl's regular library installation location--disable-dmalloc
- - with-gdbm            //dba's gdbm support--enable-sigchild
- - enable-sysvsem
- - enable-sysvshm
- - enable-zend-multibyte  //Support zend multi-byte--enable-mbregex
- - enable-wddx 
- - enable-shmop
- - enable-soap

After specifying --with-apxs2=/usr/local/apache/bin/apxs, do not activate --enable-fpm and --enable-fastCGI, apxs loads PHP in php module mode.
After Mysql compiles the Mysql development library, there is no need to specify the mysql path.
PHP compilation has a basic dependency relationship. To compile PHP, you need to install XML extensions first, because the php5 core opens XML support by default. Other basic libraries need to be: GD -> zlib, Png, Jpg, if you need to support others, still The extension library needs to be compiled according to the actual situation, and the ttf library needs the support of the freetype library.

    • enable-magic-quotes is an extremely unrecommended parameter. Of course, if you need PHP to do the underlying work for you, it doesn't actually solve the problem thoroughly.
    • with-openssl requires the openssl library. mysqli is a MySQL driver provided by the MySQL team, with many practical functions and typical features. However, it is not the best choice for MySQL on the PHP platform. PDO has been proven to be a simple, highly concurrent, and easy to create and recycle standard interface. However, PDO has also experienced the memory overflow problem before 5.3. After 5.3, when reading Oracle's LOB resources, if the memory is not limited, the memory will still overflow.

In terms of detailed options, in addition to the installation introduction described above, other options can also be added during compilation.

Syntax: --with-apache=DIR
Description: Use this option to make **PHP
** Used in apache module mode, the string of DIR can be /usr/local/apache or other directories where apache is installed
Example: --with-apache=/var/lib/apache
fhttpd server module
Syntax: --with-fhttpd=DIR
Note: If you use fttpd server, you can use this command to compile PHP. Using modules to cooperate with the fttpd server can have better efficiency.

Syntax: --with-adabas=DIR
Note: This option needs to be added when the database system is Adabas D database. For details of the Adabas D database, please refer to http://www.adabas.com.
Example: --with-adabas=/usr/local/adabasd
dBase data sheet
Syntax: --with-dbase
Note: As long as this option is added, no other parameters or function libraries are needed, and PHP will allow the system to access dBase data tables.

Syntax: --with-filepro
Note: You can read the filePro database (read only) without specifying the database path and other function libraries.
mSQL database
Syntax: --with-msql=DIR
Description: Provide access to mSQL database. For more details, please refer to the mSQL website http://www.hughes.com.au.
Example: --with-msql=/usr/local/Hughes

Syntax: --with-mysql=DIR
Description: Provide access to MySQL database. For more details, please refer to the MySQL website http://www.tcx.se.
Example: --with-mysql=/usr/local/mysql

Syntax: --with-iodbc=DIR
Description: Provide ODBC database device to access back-end database. For more details, please refer to the iODBC website http://www.iodbc.org.
Example: --with-iodbc=/usr/local/iodbc

Syntax: --with-openlink=DIR
Description: Use OpenLink ODBC database device to access the back-end database. For more details, please refer to the OpenLink ODBC website http://www.openlinksw.com.
Example: --with-openlink=/usr/local/openlink

Syntax: --with-oracle=DIR
Explanation: Use Oracle database. The Oracle version must be 7.3 or higher. You can also use the environment variable ORACLE_HOME in the PHP program to specify the path of Oracle. For more information about Oracle, please refer to Oracle's website> http://www.oracle.com.
Example: --with-oracle=/export/app/oracle/product/7.3.2

Syntax: --with-pgsql=DIR
Explanation: Use PostgreSQL database. For more information about PostgreSQL, please refer to the PostgreSQL website http://www.postgreSQL.org or the Mirror website of Taiwan http://postgresql.ccit.edu.tw.
Example: --with-pgsql=/usr/local/pgsql

Syntax: --with-custom-odbc=DIR
Description: Use customized ODBC function library. Of course, you must specify the CUSTOM_ODBC_LIBS and CFLAGS variables when using this method. For example, use Sybase **SQL on QNX machine
** You may need to configure the system environment variables CFLAGS=-DODBC_QNX, LDFLAGS=-lunix and CUSTOM_ODBC_LIBS="-ldblib -lodbc" when Anywhere, and add --with-custom-odbc=/usr/lib/sqlany50 in the PHP configuration
Example: --with-custom-odbc=/usr/local/odbc

Syntax: --disable-unified-odbc
Explanation: Using this option will make all ODBC database drivers inoperative. This option does not need to specify the path, and the options affected by this option are --with-iodbc, --with-solid, --with-adabas, --with-velocis and --with-custom-odbc.

Syntax: --with-ldap=DIR
Note: If you want to use the Lightweight Directory Access Protocol (LDAP), you must turn on this option. For details about LDAP, you can refer to RFC1777 and RFC1778 in the RFC document.
Example: --with-ldap=/usr/local/ldap.

Syntax: --with-mcrypt=DIR
Note: After the mcrypt library is installed, you can add this option when compiling PHP, so that the program can use the codec function.
Example: --with-mcrypt=/usr/local/include

Syntax: --with-xml
Note: Turn on this option to support the XML parser library written by James Clark's.

Syntax: --enable-maintainer-mode
Note: This option is generally not turned on, unless it is useful for PHP developers.

Syntax: --with-system-regex
Note: If you need additional regular expression functions, you can add this option.

Syntax: --with-config-file-path=DIR
Description: Used to specify the path of php3.ini or php4.ini for PHP initialization.
Example: --with-config-file-path=/usr/local/lib

Syntax: --with-exec-dir=DIR
Note: Sometimes for system security considerations, the PHP program must be executed in which directory.
Example: --with-exec-dir=/usr/local/bin

Syntax: --enable-debug
Note: This option is generally not used unless it is more useful when developing PHP programs. It can display additional error messages.

Syntax: --enable-safe-mode
Note: The default value is on, which can provide more protection for system security.

Syntax: --enable-track-vars
Description: Let PHP be able to track the three variables HTTP_GET_VARS, HTTP_POST_VARS and HTTP_COOKIE_VARS, which are generally enabled.

Syntax: --enable-magic-quotes
Description: The program can automatically add the backslash lead-in character when it is executed.

Syntax: --enable-debugger
Description: Open the built-in PHP debugger. At present, this function is still in the experimental stage and not yet mature.
Discard path
Syntax: --enable-discard-path
Description: Turn on this option, **user
**You cannot read files related to system security such as .htaccess through the browser.

Syntax: --enable-bcmath
Description: Turn on high-precision functions. This function library must be installed first for this option to be effective.

Syntax: --enable-force-cgi-redirect
Example: If you use CGI VERSION mode to execute PHP settings, turning on this option will increase security. For example, users who read http://my.host/cgi-bin/php/secret/doc.html may encounter hacker-level users who are more familiar with the PHP system.
The following URL http://my.host/secret/doc.html has been entered to read related information. If PHP and Apache are compiled together to make PHP a part of Apache, you do not need to add this option.
Do not use short tags
Syntax: --disable-short-tags
Explanation: After configuring this option, PHP programs cannot use short tags, and must use long tags.

Detailed php-fpm parameter configuration####

pid = run/php-fpm.pid
# pid setting, default var in the installation directory/run/php-fpm.pid, it is recommended to open

error_log = log/php-fpm.log
# Error log, default var in the installation directory/log/php-fpm.If log is set to syslog, the log will be sent to the syslogd service instead of being written to the file.

syslog.facility = daemon 
# Write the log into the system log. Linux is not familiar enough, so just ignore it for now.

syslog.ident = php-fpm 
# The system log indicates that if there are multiple fpm processes running, this is needed to distinguish who the log belongs to.

log_level = notice
# Error level.Available levels are:alert (must be processed immediately),error (error condition),warning (warning condition),notice (general important information),debug (debugging information).default: notice.

emergency_restart_threshold =60
emergency_restart_interval = 60s
# Expressed in emergency_restart_PHP with SIGSEGV or SIGBUS errors in the interval set value-If the number of cgi processes exceeds emergency_restart_threshold, php-fpm will restart gracefully. These two options generally keep the default values.

process_control_timeout =0
# Set the timeout period for the child process to receive multiplexed signals from the main process.Available units:s(second),m(Minute),h(hour),Or d(day)Default unit:s(second).Defaults:0.

daemonize = yes
# Execute fpm in the background,The default value is yes, it can be changed to no for debugging. In FPM, you can use different settings to run multiple process pools. These settings can be set individually for each process pool.

listen =127.0.0.1:9000
# The fpm listening port, which is the address processed by php in nginx, is generally the default value. Available formats are:'ip:port','port','/path/to/unix/socket'.Each process pool needs to be set.

listen.backlog =-1
# The socket queue size that has not been accepted,-1 on FreeBSD and OpenBSD, other platforms default to 65535. It is important when high concurrency is set. Reasonable settings will process queued requests in time; too large a backlog will be too much. After processing, nginx will wait for a timeout to disconnect the socket connection with fpm. Just a cup. Do not use it-1. It is recommended to be above 1024, preferably a power of 2.
# A pool shares a backlog queue, and all pool processes accept connections in this queue.
# The maximum number is limited by the system configuration cat/proc/sys/net/core/somaxconn, system configuration modification: vim/etc/sysctl.conf, add net.core.somaxconn =2000, the maximum is 2000, and then the maximum backlog of PHP can reach 2000.

listen.allowed_clients =127.0.0.1
# To allow access to the IP of the FastCGI process, set any as an unrestricted IP. If you want to set up nginx of other hosts to also access this FPM process, set the IP that can be accessed locally. The default value is any. Each address is separated by a comma.If it is not set or empty, any server is allowed to request a connection

listen.owner = www
listen.group = www
listen.mode =0666
# Unix socket setting options, if you use tcp to access, just comment here.

user = www
group = www
# Account and group that started the process

pm = dynamic 
# For dedicated servers, pm can be set to static.
# How to control the child process, the options are static and dynamic. If you choose static, then pm.max_children specify a fixed number of child processes. If dynamic is selected, it is determined by the open parameters:
pm.max_children 
# , The maximum number of child processes
#- - BEGIN--
Calculation: min_spare_servers +(max_spare_servers - min_spare_servers)/2
pm.start_servers 
# , The number of processes at startup
pm.min_spare_servers 
# , To ensure the minimum number of idle processes, if the idle process is less than this value, create a new child process
pm.max_spare_servers 
# , To ensure the maximum number of idle processes, if the idle process is greater than this value, this will be cleaned up
#- - END--
pm.max_requests =1000
# Set the number of requests served before each child process is reborn.Very useful for third-party modules that may have memory leaks.If set to'0'Keep accepting requests.Equivalent to PHP_FCGI_MAX_REQUESTS environment variable.Defaults:0.

pm.status_path =/status
# URL of FPM status page.If not set,You cannot access the status page.Defaults: none.munin monitoring will use

ping.path =/ping
# Ping URL of FPM monitoring page.If not set,You cannot access the ping page.This page is used to externally detect whether FPM is alive and can respond to requests.Please note that it must start with a slash(/)。

ping.response = pong
# Used to define the response of the ping request.Text returned as HTTP 200/plain text.Defaults: pong.

request_terminate_timeout =0
# Set the timeout abort time for a single request.This option may affect php.ini settings'max_execution_time'For some special reasons, it is not useful to stop the running script.Set as'0'Means'Off'.You can try to change this option when 502 errors often occur.

request_slowlog_timeout = 10s
# After a request for the set timeout period, the corresponding PHP call stack information will be completely written into the slow log.Set as'0'Means'Off'

slowlog = log/$pool.log.slow
# Logging of slow requests,Cooperate with request_slowlog_timeout use

rlimit_files =1024
# Set the rlimit limit of the file open descriptor.Defaults:The system-defined value default open handle is 1024, ulimit can be used-n view, ulimit-n 2048 modified.

rlimit_core =0
# Set the maximum limit value of core rlimit.Available value:'unlimited', 0 or positive integer.Defaults:System defined value.

chroot =
# Chroot directory at startup.The defined directory needs to be an absolute path.If not set,Chroot is not used.

chdir =
# Set the startup directory, it will automatically Chdir to this directory when starting.The defined directory needs to be an absolute path.Defaults:The current directory, or/Directory (when chrooted)

catch_workers_output = yes
# Redirect stdout and stderr during operation to the main error log file.If not set,stdout and stderr will be redirected to according to FastCGI rules/dev/null.Defaults:air

**More detailed configuration reference: **https://www.zybuluo.com/phper/note/89081

Nginx+php-fpm+Mysql integration###

# Compile and install nginx
[ root@master ~]# wget https://mirrors.sohu.com/nginx/nginx-1.16.1.tar.gz
[ root@master ~]# tar xvf nginx-1.16.1.tar.gz && nginx-1.16.1[root@master nginx-1.16.1]# mkdir /etc/nginx
[ root@master nginx-1.16.1]# mkdir /var/log/nginx/[root@master nginx-1.16.1]# mkdir /var/lock/[root@master nginx-1.16.1]# touch /var/log/nginx/access.log
[ root@master nginx-1.16.1]# touch /var/log/nginx/error.log

[ root@master nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx --pid-path=/run/nginx.pid \
- - lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-http_realip_module \
- - with-http_image_filter_module --with-http_sub_module --with-pcre --with-http_gzip_static_module \
- - with-http_random_index_module --with-http_degradation_module --with-http_gzip_static_module \
- - with-http_random_index_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log \
- - with-threads --with-stream --with-stream_ssl_module --with-file-aio --http-client-body-temp-path=/tmp/nginx/body \
- - http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fcgi
[ root@master nginx-1.16.1]# make -j8 && make install

# Modify the configuration file
[ root@master sbin]# vim /etc/nginx/nginx.conf 
user  www www;
index index.php index.html;
root /html;
access_log  /var/log/nginx/main.access.log  main;
location ~ \.php$ {
 fastcgi_pass   127.0.0.1:9000;
 fastcgi_index  index.php;
 fastcgi_param  SCRIPT_FILENAME  /html$fastcgi_script_name;
 include        fastcgi_params;}

Test Results####

[ root@master sbin]# elinks 127.0.0.1/echo.php
 is pho!                                                                                                                            

# mysql test
[ root@master sbin]# elinks 127.0.0.1/mysql_test.php
 connect ok!  

# phpinfo
[ root@master sbin]# elinks 127.0.0.1/info.php
 PHP logo                     
 PHP Version 7.0.9                                                                                                                        
 System                            Linux master 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 615:49:49 UTC 2019 x86_64                
 Build Date                        Jan 4202020:08:36'./configure''--prefix=/usr/local/php7''--with-config-file-path=/etc/php''--enable-fpm''--with-fpm-user=www''--with-fpm-group=www''--enable-inline-optimization''--disable-debug''--disable-rpath''--enable-shared''--with-xmlrpc''--with-openssl''--with-mhash''--with-pcre-regex''--with-zlib''--with-iconv''--with-bz2''--with-curl''--enable-exif''--enable-fileinfo''--enable-filter''--with-pcre-dir''--enable-ftp''--with-gd'               
 Configure Command                 '--with-openssl-dir''--with-jpeg-dir''--with-png-dir''--with-freetype-dir''--enable-gd-jis-conv''--with-gettext''--with-gmp''--enable-json''--enable-mbstring''--enable-mbregex''--enable-mbregex-backtrack''--with-onig''--enable-pdo''--with-mysqli=mysqlnd''--with-pdo-mysql=mysqlnd''--with-zlib-dir''--with-readline''--enable-session''--enable-simplexml''--enable-sockets''--enable-sysvmsg''--enable-sysvsem''--enable-sysvshm''--enable-wddx''--with-libxml-dir''--with-xsl''--enable-zip''--with-pear''--enable-opcache''--with-mcrypt'                                  
 Server API                        FPM/FastCGI                                                                                      
 Virtual Directory Support         disabled                                                                                         
 Configuration File(php.ini) Path /etc/php                                                                                         
 Loaded Configuration File         /etc/php/php.ini                                                                                 
 Scan this dir for additional .ini(none)                                                                                           
 files                                                                                                                              
 Additional .ini files parsed(none)                                                                                           
 PHP API                           20151012                                                                                         
 PHP Extension                     20151012                                                                                         
 Zend Extension                    320151012                                                                                        
 Zend Extension Build              API320151012,NTS                                                                                 
 PHP Extension Build               API20151012,NTS                                                                                  
 Debug Build                       no                                                                                               
 Thread Safety                     disabled                                                                                         
 Zend Signal Handling              disabled                                                                                         
 Zend Memory Manager               enabled                                                                                          
 Zend Multibyte Support            provided by mbstring                                                                             
 IPv6 Support                      enabled                                                                                          
 DTrace Support                    disabled                                                                                         
 Registered PHP Streams            https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip          
 Registered Stream Socket          tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2

Apache+php-fpm+MySQL integration###

# Apache configuration php parsing
[ root@master ~]# vim /etc/httpd/httpd.conf 
# Modify running user
User www
Group www

# Turn on the module
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule dir_module modules/mod_dir.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

# Annotation Center Host
# DocumentRoot "/usr/local/apache/htdocs" #Comment this line to prevent multiple virtual host conflicts

# Add file parsing
DirectoryIndex index.html index.php

# Open document
# Server-pool management(MPM specific)
Include /etc/httpd/extra/httpd-mpm.conf
# Various default settings
Include /etc/httpd/extra/httpd-default.conf
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf

# Add php file parsing
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

# Add host profile
IncludeOptional /etc/httpd/conf.d/*.conf
ServerLimit 400

# Configure virtual host to parse php files
[ root@master ~]# vim /etc/httpd/conf.d/www.test.com.conf 
< VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot "/html"
 ServerName 1.www.test.com
 ServerAlias www.test.com
 ErrorLog "/www/log/error.log"
 CustomLog "/www/log/access.log" combined

 < FilesMatch \.php$>
  SetHandler "proxy:unix:/tmp/php-fpm.sock|fcgi://localhost"
  # ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9000/html/$1" #Note that it will be forwarded to php globally-fpm,And can only use port mode, cannot use unix sock mode
 < /FilesMatch>
 < Directory "/html">
  SetOutputFilter DEFLATE
  Options FollowSymLinks
  AllowOverride All
  Require all granted
  DirectoryIndex index.php index.html
 < /Directory>
< /virtualHost>

Test Results####

# mysql connection test results
[ root@master html]# cat /html/mysql_test.php 
<? php
$mysql =newmysqli("127.0.0.1","root","root");if(!$mysql){
 echo "connect error!";
 $mysql=null;}else{
 echo "connect ok!";
 $mysql->close();}?>[root@master html]# elinks 127.0.0.1/mysql_test.php
 connect ok!

# phpinfo test results
[ root@master php7]# elinks 127.0.0.1/info.php
 PHP logo                                                                                                                                            
 PHP Version 7.0.9                                                                                                                                  
 System                              Linux master 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 615:49:49 UTC 2019 x86_64                          
 Build Date                          Jan 4202020:08:36'./configure''--prefix=/usr/local/php7''--with-config-file-path=/etc/php''--enable-fpm''--with-fpm-user=www''--with-fpm-group=www''--enable-inline-optimization''--disable-debug''--disable-rpath''--enable-shared''--with-xmlrpc''--with-openssl''--with-mhash''--with-pcre-regex''--with-zlib''--with-iconv''--with-bz2''--with-curl''--enable-exif''--enable-fileinfo''--enable-filter''--with-pcre-dir''--enable-ftp''--with-gd''--with-openssl-dir''--with-jpeg-dir'      
 Configure Command                   '--with-png-dir''--with-freetype-dir''--enable-gd-jis-conv''--with-gettext''--with-gmp''--enable-json''--enable-mbstring''--enable-mbregex''--enable-mbregex-backtrack''--with-onig''--enable-pdo''--with-mysqli=mysqlnd''--with-pdo-mysql=mysqlnd''--with-zlib-dir''--with-readline''--enable-session''--enable-simplexml''--enable-sockets''--enable-sysvmsg''--enable-sysvsem''--enable-sysvshm''--enable-wddx''--with-libxml-dir''--with-xsl''--enable-zip''--with-pear''--enable-opcache''--with-mcrypt'                                                                         
 Server API                          FPM/FastCGI                                                                                                
 Virtual Directory Support           disabled                                                                                                   
 Configuration File(php.ini) Path   /etc/php                                                                                                   
 Loaded Configuration File           /etc/php/php.ini                                                                                           
 Scan this dir for additional .ini(none)                                                                                                     
 files                                                                                                                                          
 Additional .ini files parsed(none)                                                                                                     
 PHP API                             20151012                                                                                                   
 PHP Extension                       20151012                                                                                                   
 Zend Extension                      320151012                                                                                                  
 Zend Extension Build                API320151012,NTS                                                                                           
 PHP Extension Build                 API20151012,NTS                                                                                            
 Debug Build                         no                                                                                                         
 Thread Safety                       disabled                                                                                                   
 Zend Signal Handling                disabled                                                                                                   
 Zend Memory Manager                 enabled                                                                                                    
 Zend Multibyte Support              provided by mbstring                                                                                       
 IPv6 Support                        enabled                                                                                                    
 DTrace Support                      disabled                                                                                                   
 Registered PHP Streams              https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip                    
 Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2                                            
 Registered Stream Filters           zlib.*, bzip2.*, convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower,      
          string.strip_tags, convert.*, consumed, dechunk                                                            
                                                
 Zend logo This program makes use of the Zend Scripting Language Engine:                                                                        
 Zend Engine v3.0.0,Copyright(c)1998-2016 Zend Technologies                       

The copyright belongs to: Lord Long Zhijie
Link to this article: https://i7dom.cn/215/2020/05/make-lanmp.html
All original articles on this site are licensed under [Creative Commons Attribution-Non-commercial Use-Same Method Sharing 4.0 International License Agreement] (http://creativecommons.org/licenses/by-nc-sa/4.0/). You are free to reprint and modify, but please be sure to indicate the source of the article and author's signature and state that the article is not original and cannot be used for commercial purposes.

Recommended Posts

CentOS7 compile and install L(A|N)MP environment
CentOs7.3 compile and install Nginx 1.9.9
Centos compile and install Git
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS 6 compile and install python 3
Centos6.5 compile and install LNMP architecture web environment
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 6.x compile and install Nginx
Linux CentOS6 compile and install Pyt
Compile and install libmodbus library under CentOS7
CentOS7.5 source code compile and install mysql5.7.29
Centos7 compile and install MySQL8 problem record
Compile and install nodejs and yum in Centos8
CentOS7.4 source code compile and install MySQL8.0
Install centos7 and connect
Centos6.9 install npm environment
CentOS8 deploys LNMP environment to compile and install mysql8.0.29 tutorial details
Centos7.2 compile and install way to build phpMyAdmin
centos7 install python3 and ipython
Know Linux and install CentOS
CentOS 7 install JAVA environment (JDK 1.8)
CentOS 7 install Mono and MonoDevelop
Ubuntu 16.04 compile and install PHP 7.2
ubuntu18.04 compile and install python3.8
CentOS install nginx+tomcat+java+mysql operating environment
CentOS6.5 install Java 8 and Tomcat8
Centos6.5 install and configure mongodb
CentOS7 install python3 and pip3
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack confluence
CentOS6 install and crack Jira 7
Centos compile and install LAMP (apache-2.4.7 + mysql-5.5.35 + php 5.5.8) + Redis
Compile and install Lnmp shell script under Linux centos
Centos 7 install jdk and package service service
CentOS7 yum install and start mysql
Install and configure keepalived under CentOS 5.9
Compile and install the open source EDA tool-Surelog on CentOS8
CentOS 8 install Git and basic configuration
CentOS7.3 install iptables and detailed use
CentOS quickly install Python3 and pip3
CentOS7 yum install and start mysql
CentOS 8 - install and configure NFS service
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos7 uninstall openJdk, and install JDK1.8
Install Python3 and ansible under CentOS8
Install and use docker under CentOS 6.8
1.5 Install Centos7
CentOS7 install and use SQL Server
How to compile and install PHP and Nginx in Ubuntu environment
Configure python3 environment on centos7 and
CentOS Minimal install and configure TIPS
Install Python3 and Py under CentOS7
Install and configure FreeIPA in Centos7
Compile and install QEMU under Ubuntu
virtualBox install centos, and build tomcat
Install Mono 3.2 and Jexus 5.4 under CentOS 6.3