Ali Cloud Centos 7.7 1gb LNMP installed

Original address: 3pub.cn/index.php/a… Before writing Tencent cloud Centos installation PHP development environment article for a long time recently to buy a new server re-installed tread pit

It’s hard to install! The initial operating system selected Centos6.5 memory 512MB encountered various pits in the installation process, it was too hard to fill up, yum source expired. Php7.4 sqllite3 and compile time various memory problems. The best solution to the above problem is to add money to upgrade the configuration

System to check the

$ lscpuArchitecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 1 On-line CPU(s) list: 0 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model Name: Intel(R) Xeon(R) Platinum 8269CY CPU @2.50 GHz Stepping: 7 CPU MHz: 2500.000 BogoMIPS: 5000.00 Hypervisor Vendor: KVM Virtualization Type: Full L1d cache: 32K L1i cache: 32K L2 cache: 1024K L3 cache: 36608K NUMA node0 CPU(s): 0 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic  movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat avx512_vnni
$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
$ getconf LONG_BIT
64 # 

Copy the code

Yum install dependencies

$yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel enchant-devel pam-devel libc-client libc-client-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel sqlite-devel libaio

$ yum install -y glibc.i686 or yum install -y glibc.i386   # You don't have to
Copy the code

Creating a swap partition

Run free-m to check the memory usage

$ free -m
              total        used        free      shared  buff/cache   available
Mem:            990         271         616           0         102         597
Swap:             0           0           0
Copy the code

Create a file of 2GB size

$ mkdir -p /opt/images
$ dd if=/dev/zero of=/opt/images/swap bs=1024 count=20480002048000+0 Records in 2048000+0 Records out 2097152000 bytes (2.1 GB) Copied, 18.6413s, 113 MB/sCopy the code

Change the created file into a SWAP partition

$ mkswap /opt/images/swap
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=56051496-4f81-47f0-85bf-e4d850714726
Copy the code

Enable the SWAP file

$ swapon /opt/images/swap
swapon: /opt/images/swap: insecure permissions 0644, 0600 suggested.
Copy the code
$ free -m
              total        used        free      shared  buff/cache   available
Mem:            990         274          62           0         653         572
Swap:          1999           0        1999
Copy the code

Ali cloud source pit needs to be modified according to the following method

Repo and epel.repo files in /etc/ym.repos. D/are modified

The CentOS - Base. In the repo file under http://mirrors.aliyun.com/centos/ http://mirrors.aliyuncs.com/centos/ Modified into http://mirrors.cloud.aliyuncs.com/centos/ http://mirrors.aliyun.com/centos-vault/centos/ the epel. 'in the file Enabled = 1 modification enabled = 0Copy the code

Create users and user groups

$ groupadd www
$ useradd -g www www     Create WWW user to WWW user group
Copy the code

Nginx

$ cd /usr/local/src/
$Wget HTTP: / / http://nginx.org/download/nginx-1.9.8.tar.gz
$The tar - xf nginx - 1.9.8. Tar. Gz

Copy the code

Download pcRE and compile:www.linuxfromscratch.org/blfs/view/s…

$Wget HTTP: / / https://downloads.sourceforge.net/pcre/pcre-8.41.tar.bz2
$The tar JXF pcre - 8.41. Tar..bz2
$ cdPcre - 8.41 -
$ ./configure --prefix=/usr/local/pcre --enable-utf8 --enable-unicode-properties
$ make && make install
Copy the code

Start loading nginx modules and compile parameters

$ cd /usr/local/ SRC/nginx - 1.9.8
$ ./configure --prefix=/usr/local/nginx --user=www --group=www  --with-http_stub_status_module --with-http_ssl_module  --with-pcre=/usr/local/ SRC/pcre - 8.41 
$ make && make install
Copy the code

Set up soft chain Nginx to support global calls

$ ln -s /usr/local/nginx/sbin/nginx  /usr/bin/nginx
$ nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Copy the code

Redis

$ cd /usr/local/src
$Wget HTTP: / / http://download.redis.io/releases/redis-6.2.2.tar.gz
$The tar xf redis - 6.2.2. Tar. Gz 
$ cdRedis - 6.2.2
$ mkdir -p /usr/local/redis/bin
$ mkdir -p /usr/local/redis/etc
$ make && make installMake [1] : brigade directory ` / usr/local/SRC/redis - 6.2.2 / SRC '
$ cp redis.conf /usr/local/redis/etc/
$ cd /usr/local/ SRC/redis - 6.2.2 / SRC
$ mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server redis-check-rdb redis-sentinel redis-trib.rb /usr/local/redis/bin

$ ln /usr/local/redis/bin/redis-server /usr/bin/redis-server
$ ln /usr/local/redis/bin/redis-cli /usr/bin/redis-cli
#Configure the daemon and its password vim /usr/local/redis/etc/redis.conf
#Requirepass password // Comments open
#Daemonize no daemonize yes
$ redis-server /usr/local/redis/etc/redis.conf
$ netstat -tunple Check whether process 6379 is occupied by redis-server

Copy the code

Mysql

Unloading, mysql,

$  rpm -aq|grep -i 'mysql'; # Retrieve output for all mysql related uninstall below
$RPM -e mysql - community - libs - compat - 5.7.21-1. El6. X86_64
$RPM -e mysql - community - the client - 5.7.21-1. El6. X86_64.#Delete the mysql service: the chkconfig -- the list | grep -i mysql
$ chkconfig --del mysql
Copy the code
$ cd /usr/local/src
#Server and related tools
$Wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.33-1.el7.x86_64.rpm;
#Client and related tools
$Wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.33-1.el7.x86_64.rpm;
#Public file for the server and client
$Wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.33-1.el7.x86_64.rpm;
#Client shared libraries 
$Wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.33-1.el7.x86_64.rpm;
Copy the code

Install in the following order because there are dependencies between them

# common --> libs --> clients --> server
$RPM -ivh mysql-community-common-5.7.33-1.el7.x86_64. RPM --force --nodeps
$RPM -ivh mysql-community-libs-5.7.33-1.el7.x86_64. RPM --force --nodeps
$RPM -ivh mysql-community-client-5.7.33-1.el7.x86_64. RPM --force --nodeps
$RPM -ivh mysql-community-server-5.7.33-1.el7.x86_64. RPM --force --nodeps
Copy the code

Cause: This is due to an old version of GPG keys installed by yum

Refer to the address: www.cnblogs.com/royfans/p/7…

Inspection installation

$ which mysql
/usr/bin/mysql
$ mysql -VMysql Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using EditLine wrapper Installing mysql system tables.... /bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 解决 : yum install -y libaioCopy the code

Start the mysql service

$ systemctl start mysqld
Copy the code

Start service exception throw error detection error log

$ tail -n 100 /var/log/mysqld.log
2021-04-26T20:03:15.474974Z 0 [Warning] Failed to open optimizer cost constant tables
2021-04-26T20:03:15.475065Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
Copy the code

CNF datadir=/var/lib/mysql datadir=/opt/mysql/data

Changing the Mysql password

Viewing temporary Passwords

$ grep password /var/log/mysqld.log
2021-04-23T21:34:34.260324Z 1 [Note] A temporary password is generated for root@localhost: Dn.Z-4srP1)A
$ mysql -h root -p 
set password = password("asasd");
Copy the code

PHP

Install PHP7.4 and PHP8

$ cd /usr/local/src
$Wget https://www.php.net/distributions/php-7.4.16.tar.gz - no - check - certificate
$The tar ZXF PHP - 7.4.16. Tar. Gz 
$Wget https://www.php.net/distributions/php-8.0.3.tar.gz - no - check - certificate
$The tar XZF PHP - 8.0.3. Tar. Gz 
$ mkdir -p /usr/local/php7
$ mkdir -p /usr/local/php8
Copy the code

Install libmcrypt library

$ cd /usr/local/src
$Wget HTTP: / / ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
$The tar xf libmcrypt - 2.5.7. Tar. Gz
$ cdLibmcrypt - 2.5.7
$ ./configure
$ make && make install
Copy the code

Configure: WARNING: unrecognized options: –with-mcrypt php7.2 does not support these options

Libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.

$ cd /usr/local/src
$Wget HTTP: / / ftp://xmlsoft.org/libxml2/libxml2-2.9.1.tar.gz
$The tar ZXF libxml2-2.9.1. Tar. Gz
$ cdLibxml2-2.9.1
$ ./configure
$ make && make install
Copy the code

Install the TCLSH method

Download the source code to www.tcl.tk/software/tc… Gz: tar -xzvf tcl8.5.19-src.tar.gz: tar -xzvf tcl8.5.19-src.tar.gz: tar -xzvf tcl8.5.19-src.tar.gz: tar -xzvf tcl8.5.19-src.tar.gz: tar -xzvf tcl8.5.19-src.tar.gz: tar -xzvf tcl8.5.19-src.tar

$Wget HTTP: / / https://prdownloads.sourceforge.net/tcl/tcl8.5.19-src.tar.gz
$The tar - XZVF tcl8.5.19 - SRC. Tar. Gz
$ cd /usr/local/ SRC/tcl8.5.19 / Unix
$ ./configure --prefix=/usr/tcl
$ make && make installCreate a soft link: Create a shortcut name TCLSH and put it in the directory usr/bin ln /usr/tcl/bin/tclsh8.5 /usr/bin/tclshCopy the code

Start compiling PHP

PHP 7.4

$ cd /usr/local/src/php
$ cd /usr/local/ SRC/PHP - 7.4.16
$ ./configure  --prefix=/usr/local/php7/ --with-config-file-path=/usr/local/php7/etc  --with-config-file-scan-dir=/usr/local/php7/etc/conf.d --enable-fpm --with-fpm-user=www  --with-fpm-group=www --enable-soap --with-openssl --with-openssl-dir  --with-zlib --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom  --enable-exif --enable-ftp  --enable-gd --with-gettext --with-gmp --with-mhash --enable-mbstring --enable-pdo --with-pdo-mysql --with-zlib-dir --with-readline --enable-session  --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem  --enable-sysvshm --with-xsl  --enable-mysqlnd   --with-mysqli --without-pear --enable-pcntl --enable-bcmath

Copy the code

Compile cast No wrong package ‘oniguruma found reference: www.limstash.com/articles/20…

Solution:

$Yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.6-1.el7.remi.x86_64.rpm
$Yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.6-1.el7.remi.x86_64.rpm

$ make && make installMake sure you have enough memory before compilingCopy the code

PHP 8.0

$ cd /usr/local/ SRC/PHP - 8.0.3
$ ./configure  --prefix=/usr/local/php8/ --with-config-file-path=/usr/local/php8/etc  --with-config-file-scan-dir=/usr/local/php8/etc/conf.d --enable-fpm --with-fpm-user=www  --with-fpm-group=www --enable-soap --with-openssl --with-openssl-dir  --with-zlib --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom  --enable-exif --enable-ftp  --enable-gd --with-gettext --with-gmp --with-mhash --enable-mbstring --enable-pdo --with-pdo-mysql --with-zlib-dir --with-readline --enable-session  --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem  --enable-sysvshm --with-xsl  --enable-mysqlnd   --with-mysqli --without-pear --enable-pcntl --enable-bcmath

$ make && make install
$ php8 --versionPHP 8.0.3 (cli) (built: Apr 27 2021 05:45:18) (NTS) Copyright (c) The PHP Group Zend Engine V4.0.3, Copyright (c) Zend TechnologiesCopy the code

Install PHP extensions

Redis extension

$Wget HTTP: / / https://pecl.php.net/get/redis-5.3.4.tgz
$The tar xf redis - 5.3.4. TGZ
$ cdRedis - 5.3.4
$ /usr/local/php7/bin/phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

$ ./configure  --with-php-config=/usr/local/php7/bin/php-config
$ make && make install. Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
$ make clean
$ /usr/local/php8/bin/phpize
$ ./configure  --with-php-config=/usr/local/php8/bin/php-config
$ make && make install. Installing shared extensions: /usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/Copy the code

Mongo extension

$Wget HTTP: / / https://pecl.php.net/get/mongodb-1.9.1.tgz
$The tar xf mongo - 1.9.1. TGZ 
$ cdMongo - 1.9.1

$ ./configure  --with-php-config=/usr/local/php7/bin/php-config
$ make && make install. Installing shared extensions: /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
$ make clean
$ /usr/local/php8/bin/phpize
$ ./configure  --with-php-config=/usr/local/php8/bin/php-config
$ make && make install. Installing shared extensions: /usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/Copy the code

Swoole extension

$Wget HTTP: / / https://pecl.php.net/get/swoole-4.6.6.tgz
$ /usr/local/php7/bin/phpize
$ ./configure  --with-php-config=/usr/local/php7/bin/php-config
$ make && make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/
Installing header files:          /usr/local/php7/include/php/

$ make clean
$ /usr/local/php8/bin/phpize
$ ./configure  --with-php-config=/usr/local/php8/bin/php-config
$ make && make install
Installing shared extensions:     /usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/
Installing header files:          /usr/local/php8/include/php/
Copy the code

The php.ini configuration

$ vim /usr/local/php7/etc/php.ini

extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/swoole.so
extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/redis.so
extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20190902/mongodb.so

$ vim /usr/local/php8/etc/php.iniextension=/usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/swoole.so extension=/usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/redis.so extension=/usr/local/php8/lib/php/extensions/no-debug-non-zts-20200930/mongodb.so disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pc ntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last _error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setprior ity,pcntl_async_signals,phpinfo,eval,passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_al ter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,copy,extract,pcnt l_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_ wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_err or,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, pcntl_async_signals,phpinfo,eval,passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter, ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,copy,extractCopy the code

Start the service

#Start the redis
$ redis-server /usr/local/redis/etc/redis.conf	
#Start PHP-fpm on port 9000 by default
$ /usr/local/php7/sbin/php-fpm -c /usr/local/php7/etc/php.ini -y /usr/local/php7/etc/php-fpm.conf  # -t parameter detection
#Start the nginx
$ nginx # nginx-t detection

#Mysql has been started
$ systemctl start mysqld
Copy the code