CentOS 7 source code installs the latest version of LNMP environment

Posted by cryp7 on Sat, 22 Jan 2022 14:57:35 +0100

The environment version is as follows:

System: CentOS 7 x86_ sixty-four

NGINX: nginx-1.7.12

Database: mariadb-10.0.13

PHP: php-5.5.23

First, make some preparations. First, replace the firewall of CentOS 7 with iptables. See the following link

Change CentOS 7 firewall to iptables

After modifying to iptables, you can clear the filtering rules in iptables, and then close selinux service. Remember not to forget to install gcc-c + + WGet net tools and other functions first.

First install mariadb

It takes a long time to compile the database, so I download the compiled binary package here. The download version is mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1. Download the binary package to / usr/local/src Directory:

[root@centos74 ~]# cd /usr/local/src/
[root@centos74 src]# wget http://ftp.osuosl.org/pub/mariadb/mariadb-10.0.13/bintar-quantal-amd64/mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

2. Unzip the compressed package to / usr/local directory:

[root@centos74 src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz -C /usr/local/

3. Create mariadb data initialization directory / data/mysql:

[root@centos74 src]# mkdir -p /data/mysql

4. Add the system user mysql and prohibit logging in to the system. At the same time, modify the primary and group of the mariadb data initialization directory to mysql:

[root@centos74 src]# useradd -r -s /sbin/nologin mysql ;chown -R mysql.mysql /data/mysql/

5. Rename the extracted mariadb Directory:

[root@centos74 src]# mv /usr/local/mariadb-10.0.13-linux-x86_64/ /usr/local/mysql

6. Enter the renamed directory and initialize mariadb:

[root@centos74 src]# cd /usr/local/mysql/
[root@centos74 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MariaDB/MySQL system tables in '/data/mysql' ...
140906  2:03:19 [Note] InnoDB: Using mutexes to ref count buffer pool pages
140906  2:03:19 [Note] InnoDB: The InnoDB memory heap is disabled
140906  2:03:19 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140906  2:03:19 [Note] InnoDB: Compressed tables use zlib 1.2.3
140906  2:03:19 [Note] InnoDB: Using Linux native AIO
140906  2:03:19 [Note] InnoDB: Using CPU crc32 instructions
140906  2:03:19 [Note] InnoDB: Initializing buffer pool, size = 128.0M
........................................................................
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at sales@skysql.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

WARNING: The host 'test4' could not be looked up with resolveip

Solution: vim /etc/hosts add 192.168.1.242 test4 in the last line

Error reported:/ bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

Solution: Yum - y install libaio devel libaio

7. Copy the configuration file to the / etc directory and overwrite the previous my cnf:

[root@centos74 mysql]# cp support-files/my-large.cnf /etc/my.cnf

cp: overwrite "/ etc/my.cnf"? y

8. Copy the mysql startup script file to / etc / init D directory and rename it mysqld:

[root@centos74 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

At the same time, the permission to modify the startup script is 755:

[root@centos74 mysql]# chmod 755 !$
chmod 755 /etc/init.d/mysqld

9. Edit the startup script and define the datadir path:

[root@centos74 mysql]# vim /etc/init.d/mysqld

Define data storage path:

datadir=/data/mysql

10. Put mariadb's own command into $PATH

[root@localhost ~]# PATH=$PATH:/etc/init.d/#Currently valid, restart the shell and it will become invalid
[root@localhost ~]# echo "export PATH=$PATH:/etc/init.d/" >>/etc/profile
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile
[root@localhost ~]# source !$

11. Start mariadb:

[root@centos74 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

Step 2: start installing php

First of all, there is a difference between the PHP installation for nginx and that for apache, because PHP in nginx combines nginx in the way of fastcgi. It can be understood that nginx proxies PHP's fastcgi, and apache calls PHP as its own module. Similarly, the official download address of PHP is: http://www.php.net/downloads.php

Download php

[rot@localhost src]# cd /usr/local/src
[root@localhost src]# wget http://am1.php.net/distributions/php-5.5.23.tar.gz

Unzip php

[root@localhost src]# tar zxf php-5.5.23.tar.gz

Create relevant accounts

[root@localhost src]# useradd -s /sbin/nologin php-fpm

Configure compilation parameters

[root@localhost src]# cd php-5.5.23
[root@localhost src]# yum -y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel 
[root@localhost php-5.5.23]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
 Error: configure: error: xml2-config not found. Please check your libxml2 installation.
terms of settlement: yum -y install libxml2-devel
 Error: configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
terms of settlement: yum -y install libcurl-devel
 Error: configure: error: jpeglib.h not found.
terms of settlement: yum -y install libjpeg-turbo-devel
 Error: configure: error: png.h not found.
terms of settlement: yum -y install libpng-devel
 Error: configure: error: freetype-config not found.
terms of settlement: yum -y install freetype-devel
 Error: configure: error: mcrypt.h not found. Please reinstall libmcrypt.
terms of settlement: yum -y install libmcrypt-devel
 install php
[root@localhost  php-5.3.27]# make && make install

If each of the above steps is not fully executed correctly, the next step cannot be carried out. Use echo $? Check whether the result is "0". If not, it is not executed correctly.

Modify profile

cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf

Write the following into the file:

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

After saving the configuration file, check whether the configuration is correct:

/usr/local/php/sbin/php-fpm -t

If the words "test is successful" appear, the configuration is OK.

Start PHP FPM

cp /usr/local/src/php-5.5.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start

If you want it to start, execute:

chkconfig php-fpm on

Detect whether to start:

ps aux |grep php-fpm

See if there are many processes (about 20).

Installing nginx

Download nginx

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.7.12.tar.gz

Unzip nginx

tar zxvf nginx-1.7.12.tar.gz

Configure compilation parameters

cd nginx-1.7.12
./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module  --with-pcre

Error reported:/ configure: error: the HTTP rewrite module requires the PCRE library.

Solution: Yum - y install PCRE devel

Error reported:/ configure: error: the HTTP gzip module requires the zlib library.

Solution: Yum install - y zlib devel

Compiling nginx

make

Installing nginx

make install

Write nginx startup script and add system services

vim /etc/init.d/nginx

Write the following:

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
 echo -n $"Starting $prog: "
 mkdir -p /dev/shm/nginx_temp
 daemon $NGINX_SBIN -c $NGINX_CONF
 RETVAL=$?
 echo
 return $RETVAL
}
stop() {
 echo -n $"Stopping $prog: "
 killproc -p $NGINX_PID $NGINX_SBIN -TERM
 rm -rf /dev/shm/nginx_temp
 RETVAL=$?
 echo
 return $RETVAL
}
reload(){
 echo -n $"Reloading $prog: "
 killproc -p $NGINX_PID $NGINX_SBIN -HUP
 RETVAL=$?
 echo
 return $RETVAL
}
restart(){
 stop
 start
}
configtest(){
 $NGINX_SBIN -c $NGINX_CONF -t
 return 0
}
case "$1" in
 start)
 start
 ;;
 stop)
 stop
 ;;
 reload)
 reload
 ;;
 restart)
 restart
 ;;
 configtest)
 configtest
 ;;
 *)
 echo $"Usage: $0 {start|stop|reload|restart|configtest}"
 RETVAL=1
esac
exit $RETVAL

After saving, change permissions:

chmod 755 /etc/init.d/nginx
chkconfig --add nginx

If you want to start up, execute:

chkconfig nginx on

Change nginx configuration

First empty the original configuration file:

> /usr/local/nginx/conf/nginx.conf

">" means redirection. Using it alone can quickly empty a text document.

vim /usr/local/nginx/conf/nginx.conf

Write the following:

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
 use epoll;
 worker_connections 6000;
}
http
{
 include mime.types;
 default_type application/octet-stream;
 server_names_hash_bucket_size 3526;
 server_names_hash_max_size 4096;
 log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
 '$host "$request_uri" $status'
 '"$http_referer" "$http_user_agent"';
 sendfile on;
 tcp_nopush on;
 keepalive_timeout 30;
 client_header_timeout 3m;
 client_body_timeout 3m;
 send_timeout 3m;
 connection_pool_size 256;
 client_header_buffer_size 1k;
 large_client_header_buffers 8 4k;
 request_pool_size 4k;
 output_buffers 4 32k;
 postpone_output 1460;
 client_max_body_size 10m;
 client_body_buffer_size 256k;
 client_body_temp_path /usr/local/nginx/client_body_temp;
 proxy_temp_path /usr/local/nginx/proxy_temp;
 fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
 fastcgi_intercept_errors on;
 tcp_nodelay on;
 gzip on;
 gzip_min_length 1k;
 gzip_buffers 4 8k;
 gzip_comp_level 5;
 gzip_http_version 1.1;
 gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
 listen 80;
 server_name localhost;
 index index.html index.htm index.php;
 root /usr/local/nginx/html;
 location ~ \.php$ {
 include fastcgi_params;
 fastcgi_pass unix:/tmp/php-fcgi.sock;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
 }
}
}

After saving the configuration, first check whether there are errors in the configuration file:

/usr/local/nginx/sbin/nginx  -t

If the following contents are displayed, the configuration is correct. Otherwise, the configuration file needs to be modified according to the error prompt:

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

Start nginx:

service nginx start

If it cannot be started, please check the "/ usr/local/nginx/logs/error.log" file to check whether nginx is started:

ps aux |grep nginx

See if there is a process.

Test whether the php file is parsed

To create a test file:

vim /usr/local/nginx/html/2.php

The contents are as follows:

<?php echo phpinfo();?>

Test:

[root@localhost nginx]# curl localhost/2.php

Or open it with a browser http://YourServerIPAddress/2.php

Important: if it can't be parsed, check the log and find that I can't connect to php. My php version is 5.5.23. The newer version needs to be in php / etc / php FPM Add to conf file

listen.owner = nobody
listen.group = nobody

These two lines, restart the service and you can use php

The reason is / TMP / PHP fcgi The sock file does not have read permission

So far, the compilation and installation of the latest version of LNMP environment source code has been completed