centos installation lnmp environment (source installation)

Posted by lnt on Mon, 16 Dec 2019 20:26:35 +0100

lnmp environment construction

Preconditions

  1. Operating system installation: CentOS 6.8 64 bit minimum installation.
  2. Configure IP, DNS, gateway and host name
  3. Configure firewall and open ports 80 and 3306
Close access wall
service iptables stop
 /etc/init.d/iptables restart? Restart the firewall to make the configuration effective

1 turn off SELinux

vi /etc/selinux/configurations
SELINUX=enforcing #Annotate

SELINUXTYPE=targeted #Annotate

SELINUX=disabled #increase
:wq! #Save exit
setenforce 0 #Make configuration effective immediately

System conventions

Storage location of software source code package / lnmp/src
 Source package compilation and installation location / usr/local / software name
 Database data file storage path / data/mysql

System package version

lnmp installation package

Install compilation tools and library files

Use CentOS yum Command one click installation
yum install -y make apr* autoconf automake curl curl-devel gcc gcc-c++ cmake gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libarchive libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison

Software installation

1. Install cmake

cd /lnmp/src/cmake-2.8.7
tar -zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure --prefix=/usr/local/cmake
make #compile
make install #install
vim /etc/profile stay path Add in path cmake Execution file path
export PATH=$PATH:/usr/local/cmake/bin
source /etc/profile Make configuration effective immediately

2. Install pcre

cd /lnmp/src/
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure
mkdir /usr/local/pcre #Create installation directory

make && make install

3. Install libmcrypt

cd /lnmp/src/libmcrypt-2.5.8
tar -zxvf libmcrypt-2.5.8.tar.gz
./configure #to configure
make #compile
make install #install

4. Install gd Library

cd /lnmp/src/
tar zxvf gd-2.0.36RC1.tar.gz
cd gd-2.0.36RC1
./configure --enable-m4_pattern_allow --prefix=/usr/local/gd --with-jpeg=/usr/lib --with-png=/usr/lib --with-xpm=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib 
make #compile
make install #install

5. Install Mysql

groupadd mysql #Add mysql group
useradd -g mysql mysql -s /sbin/nologin #Create the user mysql and join the mysql group. mysql users are not allowed to log in to the system directly
mkdir -p /var/mysql/data #Create MySQL database storage directory
chown -R mysql:mysql /var/mysql/data #Set MySQL database directory permission

tar -zxvf mysql-5.5.28.tar.gz #decompression

cd mysql-5.5.28.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306

make
make install
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #Copy the configuration file (Note: if there is a my.cnf under the / etc directory by default, you can directly overwrite it)

vi /etc/my.cnf #Edit the configuration file and add it in the [mysqld] section
datadir = /var/mysql/data #Add MySQL database path
./scripts/mysql_install_db --user=mysql #Generate mysql system database
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #Add Mysql to system startup
chmod 755 /etc/init.d/mysqld #Add execution permission
chkconfig mysqld on #chkconfig mysqld on 
vi /etc/rc.d/init.d/mysqld #edit
basedir=/usr/local/mysql #MySQL program installation path
datadir=/var/mysql/data #MySQl database storage directory
service mysqld start #Start, it may not be able to write pid file. Please add mysql user permission to / usr/local/mysql
chown -R mysql:mysql /usr/local/mysql

vi /etc/profile #Add mysql service to system environment variable: add the following line at the end
export PATH=$PATH:/usr/local/cmake/bin:/usr/local/mysql/bin
source /etc/profile #Make configuration effective immediately

mkdir /var/lib/mysql #Create directory
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #Add soft link
mysql_secure_installation #Set the Mysql password and press Y to enter the password twice according to the prompt
/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #Or change the password directly
//Now, mysql installation is complete!
cd /lnmp/src
tar -zxvf nginx-1.11.5.tar.gz
groupadd www #Add www group
useradd -g www www -s /sbin/nologin #Create nginx operation account www and join the www group. www users are not allowed to log in to the system directly
cd /lnmp/src/
wget https://www.openssl.org/source/openssl-1.1.0b.tar.gz
tar -zxvf openssl-1.1.0b.tar.gz
cd nginx-1.11.5
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/lnmp/src/openssl-1.1.0b --with-pcre=/lnmp/src/pcre-8.39 --with-http_ssl_module
//Note: - - with-pcre=/lnmp/src/pcre-8.39 points to the path to decompress the source package, not the path to install it, otherwise an error will be reported

6. Install nginx

make
make install
/usr/local/nginx/sbin/nginx #start nginx 

//If an error is reported: Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
//Use the command to close the program occupying port 80

sudo fuser -k 80/tcp
//Set nginx to start
vi /etc/rc.d/init.d/nginx #Edit the startup file to add the following
=======================================================
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginxc daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
=======================================================
:wq! #Save exit
chmod 775 /etc/rc.d/init.d/nginx #Give file execution permission
chkconfig nginx on #Set startup
/etc/rc.d/init.d/nginx restart #Restart Nginx
service nginx restart
=======================================================

7. Install php

cd /lnmp/src
tar -jxvf php-7.0.7.tar.bz2
cd php-7.0.7
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mysqlnd --with-mysql-sock=/usr/local/mysql/mysql.sock --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-pdo-mysql=/usr/local/mysql/

make #Compile, if the error of make: * * * [ext / FileInfo / libmagic / appendix. Lo] is encountered, add the parameter – - disable FileInfo
make install #install

cd /lnmp/src/php-7.0.7
cp php.ini-production /usr/local/php7/etc/php.ini #Copy php configuration file to installation directory
rm -rf /etc/php.ini #Delete the system's own configuration file
ln -s /usr/local/php7/etc/php.ini /etc/php.ini #Add soft link
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default
/usr/local/php7/etc/php-fpm.conf #Copy template file as PHP FPM configuration file
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

vi /usr/local/php7/etc/php-fpm.d/www.conf #edit

user = www #Set PHP FPM running account to www
group = www #Set PHP FPM running group to www

vim /usr/local/php7/etc/php-fpm.conf
pid = run/php-fpm.pid #Cancel previous semicolon

//Join the service and start up, set PHP FPM to start up
#cp /lnmp/src/php-7.0.7/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #Copy PHP FPM to the startup directory
chmod +x /etc/rc.d/init.d/php-fpm #Add execution permission
chkconfig php-fpm on #Set startup

vi /usr/local/php7/etc/php.ini #Edit profile
It's not forbidden here
 Find: disable "functions=
Ame, getservtype, disk \ total \ space, POSIX \ ctrmid, POSIX \ get _last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setp gid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

List the functions that can be disabled in PHP. If some programs need to use this function, you can delete it and disable it

Found:; date.timezone=
Change to: date.timezone = PRC ා set time zone
 Find: expose_php = On
 Modify to: expose? php = off? Disable the display of php version information
 Find: short_open_tag = Off
 Modify to: short ﹐ open ﹐ tag = on ﹐ support php short tag

8. Configure nginx to support php

vi /usr/local/nginx/conf/nginx.conf
Modify the / usr/local/nginx/conf/nginx.conf configuration file as follows

user www www; #In the first line, remove the comment and modify the Nginx running group to WWW; it must be the same as the user and group configuration in / usr/local/php/etc/php-fpm.conf, otherwise PHP runs in error
user www www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;
root /www;
index index.php;

location ~ [^/]\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

mkdir -p /data/www
chown www:www /data/www/ -R #Set directory owner
chmod 700 /data/www -R #Set directory permissions
Server related operation command
service nginx restart #Restart nginx
service mysqld restart #Restart mysql
/usr/local/php/sbin/php-fpm #Start PHP FPM
/etc/rc.d/init.d/php-fpm restart #Restart PHP FPM
/etc/rc.d/init.d/php-fpm stop #Stop PHP FPM
/etc/rc.d/init.d/php-fpm start #Start PHP FPM

Topics: MySQL PHP Nginx cmake