1、 Compile and install lnmp based on CentOS7.4 source code
System environment CentOS 7.4
Minimal system installation, only some common packages (vim, lirzs, gcc, wget, bash-completion) are installed*
nginx version 1.17.0
mysqlVersion 5.7.20
php version 7.2.6
1.1 Download network yum source
[ root@centos7_4 ~]# wget http://mirrors.aliyun.com/repo/Centos-7.repo -P/etc/yum.repos.d/ #Here is Ali’s network source, epel extension source, and You can install Ali's, but Ali's epel source is incomplete, so the following will directly use yum to install the network epel source
[ root@centos7_4 ~]# yum -y install epel-release
[ root@centos7_4 ~]# ls /etc/yum.repos.d/
back Centos-7.repo CentOS-Media.repo epel.repo epel-testing.repo
[ root@centos7_4 ~]# yum clean all;yum makecache
2 Compile and install nginx from source code
2.1 Install dependent packages:
[ root@centos7_4 ~]# yum -y install gcc gcc-c++ autoconf automake zlibzlib-devel openssl openssl-devel pcre*
2.2 Create nginx running user
[ root@centos7_4 ~]# useradd -M -s /sbin/nologin nginx
Download pcre package
[ root@centos7_4 ~]# wgethttps://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip
[ root@centos7_4 ~]# unzip pcre-8.42.zip -d /usr/local/src/
2.3 Download the nginx source package and unzip it
[ root@centos7_4 ~]# wget http://nginx.org/download/nginx-1.17.0.tar.gz
[ root@centos7_4 ~]# tar zxf nginx-1.17.0.tar.gz -C /usr/local/src/
[ root@centos7_4 ~]# cd /usr/local/src/nginx-1.17.0/
[ root@centos7_4 nginx-1.17.0]# ./configure --prefix=/usr/local/nginx \ #installation path
2.4 Compile and install
[ root@centos7_4 nginx-1.17.0]# echo $?
0
[ root@centos7_4 nginx-1.17.0]# make
[ root@centos7_4 nginx-1.17.0]# echo $?
0
[ root@centos7_4 nginx-1.17.0]# make install
[ root@centos7_4 nginx-1.17.0]# echo $?
0
2.5 Modify configuration file
[ root@centos7_4 nginx-1.17.0]# vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; #Modify users and groups
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #Modify path
include fastcgi_params;
}
2.6 Add environment variables to optimize nginx service
[ root@centos7_4 ~]# /usr/local/nginx/sbin/nginx-t #Check whether nginx syntax is correct
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax isok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test issuccessful
[ root@centos7_4 ~]# /usr/local/nginx/sbin/nginx #Installed startup path
[ root@centos7_4 ~]# vim /etc/profile #Add environment variables
export PATH=$PATH:/usr/local/nginx/sbin
[ root@centos7_4 ~]# source /etc/profile
[ root@centos7_4 ~]# nginx
[ root@centos7_4 ~]# netstat -antup|grep nginx
tcp 0 00.0.0.0:80 0.0.0.0:* LISTEN 7417/nginx: master
[ root@centos7_4 ~]# vim/etc/init.d/nginx #Configuration startup script
#! /bin/bash
nginx=/usr/local/nginx/sbin/nginx
case $1 in
start)
netstat -anptu | grep nginx
if [ $? -eq 0 ]
then
echo "nginx service is already running"
else
echo "nginx Service started successfully "
$nginx
fi
;;
stop)
$nginx -s stop
if [ $? -eq 0 ]
then
echo "nginx service closed successfully"
else
echo "nginx server stop fail,try again"
fi
;;
status)
netstat -anlpt | grep nginx
if [ $? -eq 0 ]
then
echo "nginx server is running"
else
echo "nginx service not started "
fi
;;
restart)
$nginx -s reload
if [ $? -eq 0 ]
then
echo "nginx service restart successfully "
else
echo "nginx server restart failed"
fi
;;
*)
echo "please enter {start restart status stop}"
;;
esac
[ root@centos7_4 ~]# chmod +x /etc/init.d/nginx
[ root@centos7_4 ~]# chkconfig --add nginx
[ root@centos7_4 ~]# chkconfig nginx on
Configure nginx to start as a daemon
[ root@centos7_4 ~]# vim /lib/systemd/system/nginxd.service
[ Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[ Service]
Type=forking
EnvironmentFile=/usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
KillSignal=SIGCONT
PrivateTmp=true
[ Install]
WantedBy=multi-user.target
[ root@centos7_4 ~]# systemctl daemon-reload
[ root@centos7_4 ~]# systemctl restart nginxd.service
[ root@centos7_4 ~]# systemctl enabled nginxd.service
3 Install MySQL from source code
3.1 Uninstall the mariadb that comes with the system*
[ root@centos7_4 ~]# yum -y remove mariadb* boost-*
3.2 Install dependencies
[ root@centos7_4 ~]# yum install -y cmake make gcc gcc-c++ bison ncursesncurses-devel
3.3 Download source package
[ root@centos7_4 ~]# wgethttps://cdn.mysql.com/archives/mysql-5.7/mysql-boost-5.7.20.tar.gz
3.4 Unzip the source package
[ root@centos7_4 ~]# tar zxf mysql-boost-5.7.20.tar.gz -C /usr/local/src/
3.5 Configure compile and install
[ root@centos7_4 ~]# cd /usr/local/src/mysql-5.7.20/
[ root@centos7_4 mysql-5.7.20]# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
DMYSQL_DATADIR=/usr/local/mysql/data \
DDOWNLOAD_BOOST=1 \
DWITH_BOOST=/usr/local/src/mysql-5.7.20/boost/boost_1_59_0 \
DSYSCONFDIR=/etc \
DWITH_MYISAM_STORAGE_ENGINE=1 \
DWITH_INNOBASE_STORAGE_ENGINE=1 \
DWITH_MEMORY_STORAGE_ENGINE=1 \
DWITH_ARCHIVE_STORAGE_ENGINE=1 \
DWITH_FEDERATED_STORAGE_ENGINE=1 \
DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
DWITH_PARTITION_STORAGE_ENGINE=1 \
DWITH_READLINE=1 \
DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
DMYSQL_TCP_PORT=3306 \
DENABLED_LOCAL_INFILE=1 \
DENABLE_DTRACE=0 \
DEXTRA_CHARSETS=all \
DDEFAULT_CHARSET=utf8 \
DDEFAULT_COLLATION=utf8_general_ci \
DMYSQL_USER=mysql \
Compile and install
[ root@centos7_4 mysql-5.7.20]# make
[ root@centos7_4 mysql-5.7.20]# make install
3.6 Create database user and data directory
[ root@centos7_4 ~]# useradd -M -s /sbin/nologin -r mysql
[ root@centos7_4 ~]# mkdir -p /usr/local/mysql/data #Create data storage directory
[ root@centos7_4 ~]# chown -R mysql.mysql /usr/local/mysql/ #Change the owner array to MySQL
3.7 Configure my.cnf file
[ root@centos7_4 ~]# vim/etc/my.cnf #The following is a simple configuration
[ mysqld]
basedir=/usr/local/mysql #mysql path
datadir=/usr/local/mysql/data #Data storage path
port=3306 #Port
socket=/usr/local/mysql/mysql.sock #The path where mysqlsocket is located
symbolic-links=0
character-set-server=utf8 #coding
pid-file=/usr/local/mysql/mysqld.pid #path where pid is located
log-error=/var/log/mysqld.log #The path where the log is located
3.8 Configure MySQL startup script
[ root@centos7_4 mysql]# cp /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld #Copy the startup script to /etc/init.d
[ root@centos24 mysql-5.7.20]# ll /etc/init.d/mysqld #has execute permission by default
[ root@centos7_4 mysql]# chkconfig --addmysqld #Add to boot entry
[ root@centos7_4 mysql]# chkconfig mysqldon #Add boot from start
[ root@centos7_4 mysql]# vim/etc/init.d/mysqld #Modify the path
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[ root@centos7_4 mysql]# vim/etc/profile #Configure environment variables
export PATH=$PATH:/usr/local/mysql/bin
[ root@centos7_4 mysql]# source/etc/profile #Load variables take effect immediately
Configure MySQL startup script, this and the above two options can be
[ root@centos7_4 system]# vim mysqld.service
[ Unit]
Description=MySQL DBMS
[ Service]
LimitNOFILE=10000
Type=simple
User=mysql
Group=mysql
PIDFile=/usr/local/mysql/mysqld.pid
ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data
ExecStop=/bin/kill -9 $MAINPID
[ Install]
WantedBy=multi-user.target
[ root@centos7_4 system]# chmod +xmysqld.service #Add execution authority
[ root@centos7_4 system]# systemctl enable mysqld.service #Set boot up
3.9 Safely initialize the database
[ root@localhost init.d]# touch /var/log/mysqld.log
[ root@localhost log]# chown mysql:mysql mysqld.log
[ root@centos7_4 ~]# /usr/local/mysql/bin/mysqld --initialize-insecure--user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data #This After initialization, the database has no password
If you want to assign a temporary password after initialization, you can remove the red part of --initialize-insecure. After initialization, you can assign a temporary password.
[ root@centos7_4 ~]# /etc/init.d/mysqldstart #Start the database
Starting MySQL. SUCCESS!
[ root@centos7_4 ~]# mysql-uroot #Log in to the database to modify the root user password
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4 Compile and install PHP from source code
4.1 Install dependencies
[ root@centos7_4 ~]# yum -y install php-mcrypt libmcryptlibmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devellibjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devellibjpeg-devel php-ldap openldap-devel openldap-servers openldap-clientsfreetype-devel gmp-devel
4.2 Download the PHP source package
[ root@centos7_4 ~]# wgethttp://mirrors.sohu.com/php/php-7.2.6.tar.bz2
4.3 Unzip the compressed package
[ root@centos7_4 ~]# tar zxf php-7.2.6.tar.gz2 -C /usr/local/src/
[ root@centos7_4 ~]# cd /usr/local/src/php-7.2.6/
4.4 Generate configuration file
[ root@centos7_4 php-7.2.6]# ./configure --prefix=/usr/local/php \ #installation path
configure: error: Cannot find ldap libraries in /usr/lib. #Solution
[ root@centos7_4 php-7.2.6]# cp -frp /usr/lib64/libldap* /usr/lib/ #Reconfiguration
4.5 Compile and install
[ root@centos7_4 php-7.2.6]# make
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol'ber_strdup'
/usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing fromcommand line
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
[ root@centos7_4 php-7.2.6]# vim Makefile #Add'-llber' at the end of a line starting with EXTRA_LIBS
EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz-ljpeg -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcrypto-lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl-lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl-lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto-lcrypt -llber
[ root@centos7_4 php-7.2.6]# make
[ root@centos7_4 php-7.2.6]# echo $?
0
[ root@centos7_4 php-7.2.6]# make install
[ root@centos7_4 php-7.2.6]# echo $?
0
4.6 Configure php configuration file
Move the location of the php configuration file and modify the name
[ root@centos7_4 php-7.2.6]# cp/usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf
Copy the php.ini file
[ root@centos7_4 php-7.2.6]# cp /usr/local/src/php-7.2.6/php.ini-production/usr/local/php/etc/php.ini
4.7 Copy the php startup script to /etc/init.d/
[ root@centos7_4 php-7.2.6]# cp/usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Add execution permissions, add to the startup item and set the card to start
[ root@centos7_4 php-7.2.6]# chmod +x /etc/init.d/php-fpm
[ root@centos7_4 php-7.2.6]# chkconfig --add php-fpm
[ root@centos7_4 php-7.2.6]# chkconfig php-fpm on
Start php-fpm
[ root@centos7_4 ~]# /etc/init.d/php-fpm start
Starting php-fpm done
[ root@centos7_4 ~]# vim /usr/local/nginx/conf/nginx.conf
43 location / {
44 root html;
45 index index.php index.html index.htm;
46 }
[ root@centos7_4 ~]# service nginx restart #Restart nginx service
Write php detection file
[ root@centos7_4 ~]# vim /usr/local/nginx/html/index.php
php phpinfo(); ?>[ root@centos7_4 ~]# netstat -antup|grep php-fpm
tcp 0 0127.0.0.1:9000 0.0.0.0:* LISTEN 128974/php-fpm: mas
Test by browser
Recommended Posts