LNMP the process of building the environment with source code (detailed)

Source: Internet
Author: User
Tags configuration php gmp gz file mcrypt openldap
This article brings the content is about LNMP to the source of the way to record the environment building process (detailed), there is a certain reference value, the need for friends can refer to, I hope to help you.

LNMP refers to the environment under Linux to build a website with Php+mysql+ngix.

Nginx is a high-performance HTTP and reverse proxy server, also a IMAP/POP3/SMTP proxy server. Nginx can be used not only as a Web server, but also as a load balancer.

MySQL is an open source free data software, MySQL is a small relational database management system, its small size, fast, low total cost of ownership, especially open source, many small and medium-sized web sites in order to reduce the total cost of ownership of the site and chose MySQL as the site database.

PHP, is the abbreviation of English Super Text preprocessing language hypertext preprocessor. PHP is an HTML embedded language, is a server-side execution of embedded HTML document scripting language, its source code is written in C language, so the style is similar to C language, is widely used to build small and medium-sized websites.

The following is a record of the construction process of the LNMP environment, the main Linux environment is the CentOS virtual image.

"Nginx Installation"

The latest Nginx stable version is 1.14.0, the URL is http://nginx.org/en/download.html, can be directly downloaded in Windows and then RZ upload to Linux, can also be directly downloaded in wget way, the following list of download is the latter.

CD/USR/SRC          #一般将源码放在此目录下wget http://nginx.org/download/nginx-1.14.0.tar.gz  #安装

Note: Nginx installation relies on Zlib-devel pcre-devel openssl-devel These packages, so we need to install the Nginx before installing these packages, in order to avoid errors in the installation process.

Yum-y Install Zlib-devel pcre-devel openssl-devel

........

The general source installation is divided into 4 steps ( 解压 tar command) 预编译 (configure under the source package), (make 编译 ), and 编译安装 (make install).

1. Decompression

TAR-ZXVF nginx-1.14.0.tar.gz   #这里解释下加压参数, Z for gzip (that is, later. gz file) x for pressurization, V for details,-F to use profile or device (required parameter)


2. Pre-compilation

When we precompile, we usually take some parameters that we want to install, such as enabling a feature and disabling a feature:

Go to the source package directory for precompilation:

CD nginx-1.14.0./configure--prefix=/data/webserver/nginx\   # Specify the installation directory as/usr/local/nginx--with-openssl=/usr/ Include/openssl\  # Enable ssl--with-pcre\                          # enable regular expression--with-http_stub_status_module        # Install programs that can view nginx status

......

3. Compiling

./configure refers to the execution of files in the current directory configure , which we can compile and install once the precompilation is complete:

Make   #编译

....

4. Installation

Make install #安装

....

After the installation is complete, we can view the installed files in the appropriate directory:

Ls/data/webserver/nginx

Then you can start the Nginx:

/data/webserver/nginx/sbin/nginx   #启动nginx/data/webserver/nginx/sbin/nginx-s stop #停止nginx/data/webserver/ Nginx/sbin/nginx-s relaod #重启nginx


#由图可知nginx已启动

Netstat-antlp¦grep  #nginx占用TCP的80端口由图也可知nginx已启动

"MySQL Installation"

At this point, Nginx has been installed to start, and then we install MySQL, similar, we still need to install the MySQL dependency package:

Yum-y install wget  cmake gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  OpenSSL openssl-devel

.......

Then we download the source code:

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.11.tar.gz

.......

To create a MySQL user:

Groupadd MySQL useradd-r-g mysql-s/bin/false MySQL

To create the installation directory and Data directory:

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

Unzip the source package:

TAR-ZXF mysql-boost-8.0.11.tar.gz-c/usr/local

Compile & Install:

Cd/usr/local/mysql-8.0.11cmake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/usr/local/mysql/data-dsysconfdir=/etc-dmysql_tcp_port= 3306-dwith_boost=/usr/local/mysql-8.0.11/boost make  && make install

After the installation is successful we can start MySQL:

Cd/usr/local/mysqlbin/mysqld_safe--user=mysql

Start successfully, connect MySQL

Bin/mysql-uroot-p

The password required to enter the connection at this time, compared to the old version of the MySQL installation of the default password is empty, but the version after 5.7 has a default password, because we do not know, so after shutting down the MySQL service (can directly query the process according to the process number kill or/etc/init.d/mysql stop ), turn the MySQL service back on by using the Skip password method instead.

Bin/mysqld_safe--user=mysql & Skip-grant-tables

Re-connect

Bin/mysql-uroot

Change Password after successful connection

mysql> UPDATE user SET Password=password (' NewPassword ') where user= ' root ';mysql> FLUSH privileges;

When you restart the MySQL service, you can connect MySQL with your account password.

"PHP Installation"

First install the PHP dependency package, or in the process of compiling and installing PHP7 will appear a variety of error, after the installation is completed can enter the next link.

Install the expansion pack and update the system kernel:

Yum Install epel-release-yyum Update

Install PHP dependent components (including nginx dependencies), the front nginx and MySQL installed can be ignored, or can be directly copied run, will skip the installed dependencies:

Yum-y install wget vim pcre pcre-devel OpenSSL openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel LIBP ng Libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses Ncurses-devel Curl Curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost- Devel Bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-d Evel ReadLine readline-devel GMP gmp-devel libcurl libcurl-devel openjpeg-devel


........

Create users and groups, and download the PHP installation package decompression:

Cd/tmpgroupadd wwwuseradd-g www wwwwget http://cn2.php.net/distributions/php-7.2.0.tar.gztar xvf php-7.2.1.tar.gzcd php-7.2.0

Set the variables and start compiling the source code:

cp-frp/usr/lib64/libldap*/usr/lib/./configure--prefix=/data/webserver/php \--with-config-file-path=/data/ Webserver/php/etc \--enable-fpm \--with-fpm-user=www \--with-fpm-group=www \--enable-mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--enable-mysqlnd-compression-support \--with-iconv-dir \--with-freetype-dir \-- With-jpeg-dir \--with-png-dir \--with-zlib \--with-libxml-dir \--enable-xml \--disable-rpath \--enable-bcmath \-- Enable-shmop \--enable-sysvsem \--enable-inline-optimization \--with-curl \--enable-mbregex \--enable-mbstring \-- Enable-intl \--with-mcrypt \--with-libmbfl \--enable-ftp \--with-gd \--enable-gd-jis-conv \--enable-gd-native-ttf \-- With-openssl \--with-mhash \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-zip \--enable-soap \-- With-gettext \--disable-fileinfo \--enable-opcache \--with-pear \--enable-maintainer-zts \--with-ldap=shared \-- WITHOUT-GDBM \

Start installation

Make-j 4 && make install

To complete the post-installation configuration php.ini file:

CP php.ini-development/data/webserver/php/etc/php.inicp/data/webserver/php/etc/php-fpm.conf.default/data/ webserver/php/etc/php-fpm.confcp/data/webserver/php/etc/php-fpm.d/www.conf.default/data/webserver/php/etc/ Php-fpm.d/www.conf

To modify php.ini related parameters:

vim/data/webserver/php/etc/php.iniexpose_php = Offshort_open_tag = Onmax_execution_time = 300max_input_time = 300memory_limit = 128mpost_max_size = 32mdate.timezone = asia/shanghaimbstring.func_overload=2

Restart PHP, this LNMP environment has been built.

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.