Configure the Lnmp environment with the source code in ubuntu16 and ubuntu16lnmp

Source: Internet
Author: User
Tags imap intl mcrypt openssl library sapi systemtap xsl

Configure the Lnmp environment with the source code in ubuntu16 and ubuntu16lnmp

Recently, the system was upgraded to the long-term support version of ubuntu16 and the lnmp environment was redeployed.

Specify the directory source code directory/usr/local/src

Mysql/usr/local/mysql

Php/usr/local/php

Nginx/usr/local/nginx

  MysqlVersion 5.7.14

 

Essential packages and tools

Gcc/g ++: MySQL 5.6 starts and needs to be compiled using g ++.

Bison: MySQL syntax parser must use bison for compilation.

Libncurses5-dev: for terminal operations of the Development Kit. (Note: Debian/Ubuntu need to install libncurses5-dev; Redhat need to install ncurses-devel)
Zlib: MySQL uses zlib for compression

 

Feature package

Libxml2: supported by XML input/output.

Openssl: Use openssl Secure Sockets for communication.

Dtrace: used to diagnose MySQL problems.

Cmake: Start with MySQL 5.5 and use cmake for project management. cmake requires version 2.8 or later.

 

Sudo apt-get install gcc

Sudo apt-get install libxml2

Sudo apt-get install libncurses5-dev (bison)

Install cmake https://cmake.org/download/

 

Create a source package directory

Mkdir/usr/local/src

 

Extract

Tar zxvf cmake-3.6.1.tar.gz

Music cmake-3.6.1/usr/local/src

Cd cmake-3.6.1

 

Compile and install

./Configure make & make install

 

Add Environment Variables

Vim ~ /. Bashrc

Add

Export PATH = "/usr/local/src/cmake-3.6.1/bin/cmake: $ PATH"

 

Boost library is required from MySQL 5.7.5, download Boost library http://sourceforge.net/projects/boost/files/boost/

Tar zxvf boost_000059_0.tar.gz

Mv boost_000059_0/usr/local/

 

Create a Mysql system user group and user, and the database storage directory:

Mkdir-p/usr/local/mysql/

Mkdir-p/usr/local/mysql/data/

 

Create another mysql socket file storage directory as needed. If you want to re-specify the storage location, you need to re-compile

Groupadd mysql add mysql user group

Useradd mysql-g mysql Add a mysql user and specify a mysql user group

Chown-R mysql: mysql/usr/local/mysql/change the permissions of the specified directory and Its subdirectories to mysql users and mysql user groups.

 

Mysql official

Http://dev.mysql.com/downloads/mysql/Select the compiled version

Tar zxvf mysql-5.7.14.tar.gz

Cd mysql-5.7.14

Compile

Cmake. -DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/usr/local/mysql/data-DWITH_INNOBASE_STORAGE_ENGINE = 1-runtime = 1-runtime = 1-runtime = 1-runtime = 1 -Keys = 1-keys = 1-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci-keys = all-DENABLED_LOCAL_INFILE = 1-keys =/usr/local/mysql/data/mysql. sock-DCOMPILATION_COMMENT = "string"-DENABLED_PROFILING = 1-DOPTIMIZER_TRACE = 1-DWITH_DEBUG = 1-DWITH_BOOST =/usr/local/boost

Make & make install

 

Create Database Service

In mysql 5.5 and 5.6, the mysqld_db_install command is used for initialization. After mysql 5.7, the database initialization has changed and requires the mysqld command for initialization:

/Usr/local/mysql/bin/mysqld -- initialize -- user = mysql -- basedir =/usr/local/mysql -- datadir =/usr/local/mysql/data/

--- Add the -- user = mysql parameter to the root initialization operation to generate a random password (note that the password is used for saving logon)

After database initialization, modify the permissions again:

Chown-R mysql: mysql/usr/local/mysql/data

 

Prepare the configuration file and start the mysql Service

Copy the default configuration file to/etc

Cp/usr/local/mysql/support-files/my-default.cnf/etc/my. cnf

Change file permissions to mysql users and groups

Sudo chown mysql: mysql/etc/my. cnf

Modify the configuration file

Vim/etc/my. cnf

[Client]
Port = 3306
Socket =/usr/local/mysql/data/mysql. sock

[Mysqld]
Port = 3306
Socket =/usr/local/mysql/data/mysql. sock
Basedir =/usr/local/mysql
Datadir =/usr/local/mysql/data

 

Start mysql in the background

/Usr/local/mysql/bin/mysqld_safe -- user -- defaults-file/etc/my. cnf

 

View mysql ports or processes

Netstat-altn | grep 3306 or ps-ef | grep mysql

Tcp6 0 0: 3306: * LISTEN

 

Use the initial random password to log on and change the password.

/Usr/local/mysql/bin/mysql-uroot-p

Mysql> set password for root @ localhost = password ('new password ');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

Add the service and copy the startup script to the/etc/init. d directory.

Cd/usr/local/mysql/
Cp support-files/mysql. server/etc/init. d/mysql

 

Set permissions

Sudo chmod 755/etc/init. d/mysql

 

Install ubuntu startup Service Management

Sudo apt-get install sysv-rc-conf

Sudo sysv-rc-conf mysql on

 

Make mysql. service available

Systemctl enable mysql. service

 

Enable or disable the mysql Service

Sudo/etc/init. d/mysql {stop | start} or sudo service mysql start | stop

 

Configure Environment Variables

Sudo vim ~ /. Bashrc

Export PATH = "/usr/local/mysql/bin/: $ PATH"

Export PATH

 

Nginx version 1.10.1

Preparations

Zlib library http://www.zlib.net/

Tar-xvf zlib-1.2.8.tar.gz-C/usr/local/src

Mv/usr/local/src/zlib-1.2.8/usr/local/src/zlib

Generate shared library

Cd/usr/local/src/zlib

./Configure -- shared & make test & make install

Cp zutil. h/usr/local/include

Cp zutil. c/usr/local/include

Mkdir/usr/local/zlib

./Configure -- prefix =/usr/local/zlib

Add to dynamic link library

Add/usr/local/zlib/lib to/etc/ld. so. conf

Ldconfig

 

Need pcre Library http://www.pcre.org/

Tar zxvf pcre-8.39.tar.gz-C/usr/local/src

Mv/usr/local/src/pcre-8.39/usr/local/src/prce

Cd/usr/local/prce

./Configure & make install

 

Ssl features require openssl library http://www.openssl.org/source/ download 1.0.g

Tar zxvf openssl-1.0.2g.tar.gz-C/usr/local/src

Cd/usr/local/openssl-1.0.2g

./Config -- prefix =/usr/local/shared

Make test & make install

Add to dynamic link library

Add/usr/local/lib to/etc/ld. so. conf

Ldconfig

 

Add nginx users and user groups

Groupadd www

Useradd www-g www

Chown-R www: www/usr/local/nginx

 

Official nginx http://nginx.org/

Tar zxvf nginx-1.10.1.tar.gz-C/usr/local/src

Cd/usr/local/src/nginx-1.10.1

Compile and install

. /Configure -- prefix =/usr/local/nginx -- with-openssl =/usr/local/src/openssl-1.0.2g -- with-pcre =/usr/local/src/pcre --- zlib =/usr/local/src/zlib -- pid-path =/usr/local/nginx. pid -- with-http_ssl_module -- with-http_stub_status_module

Make & make install

 

Start the nginx Service

/Usr/local/nginx/sbin/nginx

View nginx Processes

Ps-ef | grep nginx

Close and restart the service

/Usr/local/nginx/sbin/nginx-s stop, quit, reopen, reload

Create nginx Startup Script

Vim/etc/init. d/nginx

#! /bin/sh# Default-Start:     2 3 4 5# Default-Stop:      0 1 6# Short-Description: starts the nginx web serverPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDESC="nginx daemon"NAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME.confPIDFILE=/usr/local/nginx/$NAME.pidSCRIPTNAME=/etc/init.d/$NAME set -e[ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running"} do_stop() { kill -INT `cat $PIDFILE` || echo -n "nginx not running"} do_reload() { kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"} case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;;esac exit 0

  

Save settings

: Wq

Update Permissions

Sudo chmod 755/etc/init. d/nginx

Sudo sysv-rc-conf nginx on

Nginx start, stop, restart command

/Etc/init. d/nginx {start | stop | reload | restart}

 

Configure nginx to support php

Vim/usr/local/nginx/conf/nginx. conf

 

Location /{

Root/www;

Index index.html index.htm index. php;

}

Location ~ \. Php $ {

Root/www;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME/Www$ Fastcgi_script_name;

Include fastcgi_params;

}

// Note: simheiWwwFor the web root directory, change it to the corresponding directory.

 

PHP

Apt-get install php 7 php5.6

Php 7

 

Apt-get install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext

 

Python 5.6

 

Sudo apt install software-properties-common

Sudo add-apt-repository ppa: ondrej/php

Sudo apt-get update

Sudo apt-get install php5.6

Sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml

 

5.6.25 compile, install, and install necessary Dependencies

T1lib (php font class extension) 116t1lib-5.1.2.tar.gz http://www.t1lib.org/

Extract

Tar zxvf t1lib-5.1.2.tar.gz-C/usr/local/src

D/usr/local/src t1lib-5.1.2

./Configure

Error message: X11/Xaw/Label. h: No such file or directory

 

Libxaw library missing

Sudo apt-get install libxaw7-dev

./Configure & make without_doc & make install

 

Download the php5.6.25 source code package from the official website.

Tar zxvf php-5.6.23.tar.gz-C/usr/local/src

Cd/usr/local/src/

 

Compile and install

. /Configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/etc -- with-mysql-sock =/usr/local/ mysql/data/mysql. sock -- enable-mbstring -- enable-mysqlnd -- with-mysql = mysqlnd -- with-mysqli =/usr/local/mysql/bin/mysql_config -- with-mysqli = mysqlnd -- with-pdo -mysql = mysqlnd -- enable-fpm -- with-fpm-group = www -- with-fpm-user = www -- enable-bcmath -- enable-soap -- enable-calendar -- with-pcre-dir =/usr/local/src/pcre -- with-mcrypt -- enable-xml -- with-xmlrpc -- with-xsl -- enable-sockets -- enable-opcache -- with-gd -- with-jpeg-dir -- with-png-dir -- with-xpm-dir -- with-freetype-dir -- enable-gd-native-ttf -- enable-dtrace -- with-openssl -- with-kerberos -- with-openssl-dir =/usr/local/src/openssl-1.0.2g -- enable-zip -- with-zlib-dir =/usr/local/src/ zlib -- with-t1lib =/usr/local/share/t1lib -- with-libxml-dir -- with-iconv-dir -- with-libzip -- enable-intl -- with-curl = DIR -- enable -ftp

 

The message "Cannot find sys/sdt. h which is required for DTrace support" is displayed.

Install the SystemTap SDT for some dTrace Development versions according to the official instructions.

Apt-cache search SystemTap SDT

Apt-get install systemtap-sdt-dev

 

Prompt curl compilation failed

Apt-get install libcurl4-gnutls-dev

Apt-get install curl php5.6-curl

 

Prompt to reinstall libzip

Apt-get install libzip-dev

 

Clear the previously compiled executable files and configuration files, and re-compile

Make clean

 

. /Configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/etc -- with-mysql-sock =/usr/local/ mysql/data/mysql. sock -- enable-mbstring -- enable-mysqlnd -- with-mysql = mysqlnd -- with-mysqli =/usr/local/mysql/bin/mysql_config -- with-mysqli = mysqlnd -- with-pdo -mysql = mysqlnd -- enable-fpm -- with-fpm-group = www -- with-fpm-user = www -- enable-bcmath -- enable-soap -- enable-calendar -- with-pcre-dir =/usr/local/src/pcre -- with-mcrypt -- enable-xml -- with-xmlrpc -- with-xsl -- enable-sockets -- enable-opcache -- with-gd -- with-jpeg-dir -- with-png-dir -- with-xpm-dir -- with-freetype-dir -- enable-gd-native-ttf -- enable-dtrace -- with-openssl -- with-kerberos -- with-openssl-dir =/usr/local/src/openssl-1.0.2g -- enable-zip -- with-zlib-dir =/usr/local/src/ zlib -- with-t1lib =/usr/local/share/t1lib -- with-libxml-dir -- with-iconv-dir -- with-libzip -- enable-intl -- with-curl = DIR -- -imap -- with-imap-ssl -- enable-ftp

 

Test

Make & make test

Installation after testing

Make install

 

Configure php to start with the System

Copy php. ini from source file to directory

Cp php. ini-development/usr/local/php/etc/php. ini

Copy php-fpm.conf

Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

 

Php-fpm is automatically started with the System

Sudo cp./sapi/fpm/init. d. php-fpm/etc/init. d/php-fpm

Sudo sysv-rc-conf php-fpm on

Sudo cp./sapi/fpm/init. d. php-fpm/usr/local/php/sbin/init. d. php-fpm

Sudo chmod 755/etc/init. d/php-fpm

 

Add read and execution rights

Cd/usr/local/php/sbin/

Chmod 755 init. d. php-fpm

 

Php script service enabled, stopped, restarted, STATUS Command

./Init. d. php-fpm {start | stop | force-quit | restart | reload | status}

 

Add System Variables

Vim ~ /. Bashrc

Export PATH = "/usr/local/php/bin/: $ PATH"

Export PATH = "/usr/local/php/sbin/: $ PATH"

Export PATH

Change the PHP user group to www

Chown-R www: www/usr/local/php

View port

Sudo netstat-tulpn

 

Php-fpm.conf Configuration

Pm. max_children = 5

Pm. start_servers = 2 Number of sub-processes started at startup

Pm. min_spare_servers = 1 the minimum number of sub-processes in idle "idle" State. If the number of idle processes is smaller than this value, the corresponding sub-processes will be created

Pm. max_spare_servers = 3 maximum number of idle sub-processes. If the number of idle sub-processes exceeds this value, the corresponding sub-processes will be killed.

 

Create a phpinfo () file in the nginx web directory. the browser outputs this screen to indicate that the configuration is successful.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.