Use LNMP build enterprise web site

Purpose:

Use LNMP framework to build a web site

First, prepare the environment

1, a Centos7 server, configure the IP address, server name nginx.web.com;

2, each server configured yum source;

3, ready to compile source code environment;

4, experimental package needed is available in the following ways.

Link: https: //pan.baidu.com/s/1pi1XsjFE8FL4LChfbDVoJg
extraction code: 04as

Second, the initial state of the server ready

1, configure the IP address 192.168.4.150 to the server (can set their own);

2, check the firewall is turned off, if not shut down using iptables -F Close

3, check selinux is closed, if not closed, may be used to temporarily modify command setenforce 0

Third, deploy Nginx service

1, the prepared package passed in a virtual machine

[Root @ nginx ~] # mkdir tools // Create a directory for the package

[root@nginx ~]# cd tools 

[Root @ nginx tools] # rz // upload tool, installed through yum install -y lrzsz

[Root @ nginx tools] # ls // Check whether the packages are uploaded successfully (a total of six packages)

cmake-2.8.6.tar.gz php-5.3.28.tar.gz

mysql-5.5.22.tar.gz SKYUC.v3.4.2.SOURCE.zip

nginx-1.6.0.tar.gz        ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

(Also can be networked using wget to download directly on the site)

2, the installation environment, and compile Nginx dependencies

[Root @ nginx ~] # yum -y install gcc gcc-c ++ make // mounting compiler environment

[Root @ nginx ~] # rpm -aq gcc gcc-c ++ make // check whether the package installed successfully

make-3.82-21.el7.x86_64

gcc-4.8.5-4.el7.x86_64

gcc-c++-4.8.5-4.el7.x86_64

[Root @ nginx ~] # yum -y install pcre-devel zlib-devel openssl-devel // installed Nginx dependencies

[root@nginx ~]# rpm -aq pcre-devel zlib-devel openssl-devel

pcre-devel-8.32-15.el7.x86_64

openssl-devel-1.0.1e-42.el7.9.x86_64

zlib-devel-1.2.7-15.el7.x86_64

3, to compile install Nginx:

Detection system is installed Apache service, if you need to uninstall Apache installation;

[root@nginx ~]# rpm -aq httpd   

(1) create a user program Nginx

[Root @ nginx ~] # useradd -M -s / sbin / nologin nginx // create user Nginx

[Root @ nginx ~] # tail -1 / etc / passwd; tail -1 / etc / group // check if the user is successfully created

(2) to compile and install

[Root @ nginx ~] # cd tools / // enter the directory for the package

[Root @ nginx tools] # tar xf nginx-1.6.0.tar.gz -C / usr / src / // nginx the package to extract the / usr / src directory

[Root @ nginx tools] # cd /usr/src/nginx-1.6.0/ // complete directory files are decompressed file

[root@nginx nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-file-aio  --with-http_mp4_module --with-http_ssl_module && make && make install  //编译安装

[Root @ nginx nginx-1.6.0] # echo $? // Check if a command is executed successfully, 0 for success

0

(3) modify the configuration file Nginx

[Root @ nginx ~] # cd / usr / local / nginx / conf / // enter the store configuration files directory

[Root @ nginx conf] # cp nginx.conf nginx.conf.bak // backup

[Root @ nginx conf] # vim nginx.conf // modify the configuration file, the following is the content of the modified file

2 user  nginx nginx;

5 worker_processes  1;

7 error_log  logs/error.log  info;

9 pid        logs/nginx.pid;

12 events {

13     use epoll; 

14     worker_connections  10240;

15 }

18 http {

19     include       mime.types;

20     default_type  application/octet-stream;

21

22     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

23                       '$status $body_bytes_sent "$http_referer" '

24                       '"$http_user_agent" "$http_x_forwarded_for"';

25

26     access_log  logs/access.log  main;

27

28     sendfile        on;

29     tcp_nopush     on;

36     server {

37         listen       80;

38         server_name  localhost;

39

40         charset utf-8;

41

42         access_log  logs/nginx.yunban.cn.access.log  main;

43

44         location / {

45             root   html;

46             index  index.html index.htm;

47         }

End modify save and exit!

(4) create a soft link

[root@nginx conf]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/

(5) changes to the system maximum number of open files

[root@nginx conf]# ulimit -HSn 65535

[root@nginx conf]# ulimit –n

65535

[root@nginx conf]# echo "ulimit -HSn 65535" >> /etc/profile

[root@nginx conf]# tail -1 /etc/profile

ulimit -HSn 65535

(6) configuration file syntax check

[root@nginx conf]# 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

4, start Nginx service, and is set to boot from the start

[root@nginx ~]# cd /usr/local/nginx/sbin

[root@nginx sbin]# ./nginx

[root@nginx sbin]# netstat -anput|grep 80  

5, test Nginx visits

Enter the server's ip address in the browser, the following page indicates success;

Fourth, install the MySQL service :

1, check whether the installation Mariadb database, if the installation is used to uninstall rpm, mounted dependencies

[Root @ nginx ~] # rpm -aq mariadb mariadb-server mariadb-client // Check whether the database installed MariaDB

[Root @ nginx ~] # yum -y install ncurses-devel // database installation dependencies

[[root@nginx ~]# rpm -aq ncurses-devel  

ncurses-devel-5.9-13.20130511.el7.x86_64

2, install cmake to build tools as MySQL

[root@nginx ~]# cd tools/

[root@nginx tools]# tar xf cmake-2.8.6.tar.gz -C /usr/src/

[root@nginx tools]# cd /usr/src/cmake-2.8.6/

[root@nginx cmake-2.8.6]# ./configure && gmake &&gmake install      //编译安装

[root@nginx cmake-2.8.6]# echo $?

0

3, compile and install MySQL database

[root@nginx cmake-2.8.6]# cd /root/tools/

[root@nginx tools]# tar xf mysql-5.5.22.tar.gz -C /usr/src/

[root@nginx tools]# cd /usr/src/mysql-5.5.22/

[root@nginx mysql-5.5.22]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install           //编译安装数据库

4, the configuration after installation

[root@nginx mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile 

[root@nginx mysql-5.5.22]# . /etc/profile 

[root@nginx mysql-5.5.22]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

Prepare the relevant configuration file:

[root@nginx~]# /bin/cp-p /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf

[root@nginx ~]# /bin/cp -p /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld

[Root @ nginx ~] # chmod + x /etc/init.d/mysqld // execute permissions granted

[root@nginx ~]# chkconfig --add mysqld

[root@nginx ~]# chkconfig mysqld on

5, initialize the database

[Root @ nginx ~] # useradd -M -s / sbin / nologin mysql // Create a mysql user

[Root @ nginx ~] # chown -R mysql: mysql / usr / local / mysql / // Modify belonging group

[root@nginx ~]# /usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

6, start the MySQL database, and create a password for the MySQL root user

[Root @ nginx ~] # /etc/init.d/mysqld start // Start the database

Starting MySQL... SUCCESS!

[Root @ nginx ~] # netstat -anptu | grep 3306 // see if the database start

[Root @ nginx ~] # mysqladmin -uroot password "123456"; history -c // create a password for the root user

7, log database

login successful!

Fifth, the deployment of PHP service

1, PHP installation service

[root@nginx ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel    

[root@nginx ~]# cd tools/

[root@nginx tools]# tar xf php-5.3.28.tar.gz -C /usr/src/

[root@nginx tools]# cd /usr/src/php-5.3.28/

[root@nginx php-5.3.28]# ./configure  --prefix=/usr/local/php5  --with-gd  --with-zlib --with-mysql=/usr/local/mysql/  --with-config-file-path=/usr/local/php5  --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib && make && make install                                //编译安装php服务

[root@nginx php-5.3.28]# echo $?

0

2, the adjustment and optimization of the installation

[root@nginx php-5.3.28]# cp -p /usr/src/php-5.3.28/php.ini-development /usr/local/php5/php.ini

[Root @ nginx php-5.3.28] # ln -s / usr / local / php5 / bin / * / usr / local / bin / // create a soft link

[root@nginx php-5.3.28]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/

3,  mounting ZendGuardLoader (PHP optimization module)

[root@nginx php-5.3.28]# cd /root/tools/

[root@nginx tools]#tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/

[root@nginx tools]cp /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/php5/lib/php/

[root@nginx tools]# echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1" >> /usr/local/php5/php.ini

[root@nginx tools]# tail -2 /usr/local/php5/php.ini

zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so

zend_loader.enable=1

4, configuration and start

[root@nginx tools]# cd /usr/local/php5/etc/

[root@nginx etc]# cp -p php-fpm.conf.default php-fpm.conf

[root@nginx etc]# vim php-fpm.conf

25 pid = run / php-fpm.pid // specified pid file location

140 user = nginx // user program

141 group = nginx // program group

217 pm.max_children = 50 // The maximum number of child processes

222 pm.start_servers = 20 // number of open startup process

227 pm.min_spare_servers = 5 // Minimum number of idle processes

232 pm.max_spare_servers = 35 // maximum number of idle processes

5, start PHP

[root@nginx etc]# php-fpm

[Root @ nginx etc] # netstat -anput | grep php // Check whether to activate php

6, the service control script written Nginx

[root@nginx etc]# vim /etc/init.d/nginx

#!/bin/bash
# chkconfig: 2345 99 20
# description: Nginx Server Control Script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php5/var/run/php-fpm.pid"
case "$1" in
        start)
                if [ -f $PIDF ];then
                        echo "Nginx is running.. Start it is error"
                elif [ -f $PIDF_FPM ];then
                        echo "PHP is running.. Start it is error"
                else
                        $PROG &>/dev/null
                        $PROG_FPM &>/dev/null
                fi
        ;;
        stop)
                if [ -f $PIDF ] && [ -f $PIDF_FPM ];then
                        kill -s QUIT $(cat $PIDF) &> /dev/null
                        kill -s QUIT $(cat $PIDF_FPM) &>/dev/null
                else
                        echo "Nginx or PHP is not running.. Stop it is error"
                fi
        ;;
        restart)
                $0 stop
                $0 start
        ;;
        reload)
                kill -s HUP $(cat $PIDF)
        ;;
        *)
                echo "Usage: $0 (start|stop|restart|reload)"
                exit 1
esac
exit 0

[Root @ nginx ~] # chmod + x /etc/init.d/nginx // execute permissions granted to the script

[root@nginx ~]# echo "/etc/init.d/nginx start">> /etc/rc.d/rc.local

[root@nginx ~]# chmod +x /etc/rc.d/rc.local

[root@nginx ~]# tail -1 /etc/rc.d/rc.local

/etc/init.d/nginx start

7, test scripts

[root@nginx ~]# /etc/init.d/nginx start

[Root @ nginx ~] # netstat -anput | egrep "nginx | ​​php" // see if a successful start

 8, configure Nginx support PHP parsing

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf

46             index  index.php index.html index.htm;

60         location ~ \.php$ {

61                 root html;

62                 fastcgi_pass 127.0.0.1:9000;

63                 fastcgi_index index.php;

64                 include fastcgi.conf;

65         }

End modify save and exit!

Whether [root @ nginx ~] # nginx -t // View configuration successfully

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

[Root @ nginx ~] # /etc/init.d/nginx reload // restart script

9. Test

[root@nginx ~]# vim /usr/local/nginx/html/index.php

<?php

phpinfo();

?>

10, the test results are as follows

11, test access to the database through PHP

[root@nginx ~]# vim /usr/local/nginx/html/test.php

[root@nginx ~]# cat /usr/local/nginx/html/test.php

<?php

$link=mysql_connect('localhost','root','123123');

if($link) echo "<h1>successful</h1>";

mysql_close();

?>

12, the test results are as follows

If you do not go to the following page to check whether the configuration file for errors;

Sixth, application deployment SKYUC

1, extract SKYUC, the deployment of the program code  

[Root @ nginx ~] # yum -y install unzip // Extract tool mounting

[root@nginx ~]# rpm -aq unzip

unzip-6.0-15.el7.x86_64

[root@nginx ~]# cd tools/

[root@nginx tools]# unzip SKYUC.v3.4.2.SOURCE.zip

[root@nginx tools]# cd SKYUC.v3.4.2.SOURCE

[root@nginx SKYUC.v3.4.2.SOURCE]# cp -rp wwwroot/ /usr/local/nginx/html/skyuc

[root@nginx SKYUC.v3.4.2.SOURCE]# cd /usr/local/nginx/html/skyuc/

[root@nginx skyuc]# chown -R nginx:nginx ./

2, create the database, and for authorization

[root@nginx ~]# mysql -uroot -p123123

mysql> create database skyucdb; // create a database named skyucdb the 

Query the OK, 1 Row affected (0.00 sec) 

MySQL> Grant All ON skyucdb to runskyuc * @ localhost IDENTIFIED by 'admin123';. // create runskyuc user password is admin123 

the OK Query, 0 rows affected (0.00 sec) 

MySQL> quit 

Bye

3, web interface to install

Click Next:

Fill in the information database, set the administrator:

Successful installation:

4, delete the install directory install:

[root@nginx ~]# cd /usr/local/nginx/html/skyuc/

[root@nginx skyuc]# rm -rf install/

5、登录页面:

管理员登录:

登录管理界面:

实验成功!(* ̄︶ ̄)

 

Guess you like

Origin www.cnblogs.com/hmm01031007/p/11569070.html