Linux: LNMP (source package installation)

Linux

virtual machine

VMware: install centos7_Bao Haichao-GNUBHCkalitarro's Blog-CSDN Blog 

physical machine

linux: install centos linux on the real machine (emergency: solve stuck in the installation interface) {look for mirror image--uqi production--boot u disk--solve stuck in the installation interface--installation configuration}_Install centos7 stuck in the installation interface _Bao Haichao-GNUBHCkalitarro's Blog-CSDN Blog


 Nginx

Linux: nginx basic construction (source package)_Bao Haichao-GNUBHCkalitarro's Blog-CSDN Blog 


mysql

 First install the environment install cmake

Prepare cmake source package, mysql source package,

yum -y install ncurses-devel perl* gcc-c++

 tar zxvf /root/cmake-2.8.6.tar.gz -C /usr/src/

 cd /usr/src/cmake-2.8.6

./configure &&gmake &&gmake install 

Install the mysql source package

tar zxvf mysql-5.6.36.tar.gz -C /usr/src/ 

cd /usr/src/mysql-5.6.36/ 

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc 

 make &&make install

# process is slow

Do not exit the directory after compiling

cp -f support-files/my-default.cnf /etc/my.cnf 

cp support-files/mysql.server /etc/rc.d/init.d/mysqld 

chmod +x /etc/rc.d/init.d/mysqld

chkconfig --add mysqld 

echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile 

source /etc/profile

groupadd mysql 

useradd -M -s  /sbin/nologin mysql -g mysql 

chown -R mysql:mysql /usr/local/mysql 

cd /usr/local/mysql/scripts/ 

 /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

/etc/rc.d/init.d/mysqld start 

mysqladmin -u root password 123         


 PHP

yum -y install libxmlyum -y install libxml2-devel gd zlib-devel libjpeg-devel libpng-devel2-devel gd zlib-devel libjpeg-devel libpng-devel 

 tar xf php-5.5.38.tar.gz -C /usr/src

 cd /usr/src/php-5.5.38/

./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib

 make && make install

Do not switch directories after compiling and installing 

cp php.ini-development /usr/local/php5/php.ini 

ln -s /usr/local/php5/bin/* /usr/local/bin/

ln -s /usr/local/php5/sbin/* /usr/local/sbin/ 

 

 Install ZendGuardLoader:

PHP speeds up loading modules, which can be skipped if not needed

 tar xf zend-loader-php5.5-linux-x86_64_update1.tar.gz 

 cd zend-loader-php5.5-linux-x86_64

cp ZendGuardLoader.so /usr/local/php5/lib/php/ 

 vim /usr/local/php5/php.ini

Add at the bottom

zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1


Configure nginx to support php

cd /usr/local/php5/etc/

useradd -M -s /sbin/nologin php 

vim php-fpm.conf 

write inside

[global]
pid = run/php-fpm.pid
[www]
listen = 127.0.0.1:9000
user = php
group = php
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35 

 /usr/local/php5/sbin/php-fpm   

#Test can start php-fpm

killall -9 php-fpm 

# Close php-fpm

Write a script to start LNMP

vi /etc/init.d/lnmp 

to write

#!/bin/bash
# chkconfig: 35 95 30
# description: This script is for LNMP Management!
NGF=/usr/local/nginx/sbin/nginx
NGP=/usr/local/nginx/logs/nginx.pid
FPMF=/usr/local/php5/sbin/php-fpm
FPMP=/usr/local/php5/var/run/php-fpm.pid
case $1 in 
   start)
      $NGF &&echo "nginx is starting! "
      $FPMF && echo "php-fpm is starting! "
   ;;
   stop)
      kill -QUIT $(cat $NGP) &&echo "nginx is stoped! "
      kill -QUIT $(cat $FPMP) &&echo "php-fpm is stoped! "
   ;;
   restart)
      $0 stop
      $0 start
   ;;
   reload)
      kill -HUP $(cat $NGP) 
      kill -HUP $(cat $FPMP)
   ;;
   status)
      netstat -utpln |grep nginx &>/dev/null 
      if [  $? -eq 0 ]
      then
         echo "nginx is running! "
      else
         echo "nginx is not running! "
      fi
      netstat -upltn |grep php-fpm &>/dev/null 
      if [ $? -eq 0 ]
      then
         echo "php-fpm is runing! "
      else
         echo "php-fpm is not running! "
      fi
   ;;
   *)
      echo "Usage $0 {start|stop|status|restart}"
      exit 1
   ;;
esac
exit 0

 chmod +x /etc/init.d/lnmp 

chkconfig --add lnmp 

systemctl start lnmp 

# start | stop | restart


Create a test php page 

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

Find the server module and write it in the module

 location ~ \.php$ {
            root /usr/local/nginx/html/www;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

  

mkdir /usr/local/nginx/html/www 

vim /usr/local/nginx/html/www/aaa.php 

 to write

<?php
$link=mysqli_connect('localhost','root','123');
if($link) echo "<h1>mysql connected success ! its ok !!</h1>";
mysqli_close($link);
?>

/etc/init.d/lnmp restart

 

 restart successfully

In Linux , the PHP access used to connect to the M ysql database through the N ginx service is successful

Guess you like

Origin blog.csdn.net/w14768855/article/details/131462466