CentOS7 compile and install the new LNMP environment _linux

Source: Internet
Author: User
Tags apache php chmod curl fpm mcrypt mkdir iptables

Because the company requires the latest version of the ZABBIX2.4.4 need the latest version of the system CENTOS7 and the new version of the LNMP environment, so I feel the use of a new version of the environment to build a LNMP system, the environment version is as follows:

    • System: CentOS 7 x86_64
    • nginx:nginx-1.7.12
    • Database: mariadb-10.0.13
    • php:php-5.5.23

First of all to do some preparation work, first of all, to replace the CENTOS7 firewall into iptables, you can see the following links

CENTOS7 Firewall Settings Iptables

After modifying the iptables, you can clear the filter rules in the iptables and then close the SELinux service. Remember to install GCC gcc-c++ wget net-tools, and so on.

First install MARIADB

The database should be compiled for a long time, so I am here to download the compiled binary package, download version of mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1, download the binary package to the/USR/LOCAL/SRC directory:

Copy Code code as follows:
[Root@centos74 ~]# cd/usr/local/src/
[Root@centos74 src]# wget http://ftp.osuosl.org/pub/mariadb/mariadb-10.0.13/bintar-quantal-amd64/ Mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz[/code]

2. Extract the compressed package into the/usr/local directory:

[Code] [Root@centos74 src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz-c/usr/local/


3, the creation of MARIADB data initialization directory/data/mysql:

Copy Code code as follows:
[Root@centos74 src]# mkdir-p/data/mysql

4, add system user MySQL, prohibit landing system, at the same time, the MARIADB data initialization directory owners and groups are modified to MySQL:

Copy Code code as follows:
[root@centos74 src]# useradd-r-s/sbin/nologin MySQL; chown-r mysql.mysql/data/mysql/

5, rename the extracted mariadb directory:

Copy Code code as follows:
[Root@centos74 src]# mv/usr/local/mariadb-10.0.13-linux-x86_64//usr/local/mysql

6, enter the renamed directory, initialize the MARIADB:

[Root@centos74 src]# cd/usr/local/mysql/[root@centos74 mysql]#./scripts/mysql_install_db--datadir=/data/mysql--
User=mysql Installing Mariadb/mysql system tables in '/data/mysql ' ...  140906 2:03:19 [note] innodb:using mutexes to ref count buffer pool pages 140906 2:03:19 [note] innodb:the InnoDB  Heap is disabled 140906 2:03:19 [note] innodb:mutexes and rw_locks use GCC atomic builtins 140906 2:03:19 [] InnoDB:  Compressed tables use zlib 1.2.3 140906 2:03:19 [note] innodb:using Linux native AIO 140906 2:03:19 [note] Innodb:using CPU CRC32 Instructions 140906 2:03:19 [note] innodb:initializing buffer pool, size = 128.0M ... ...............
............................................
The latest information about MARIADB is available at http://mariadb.org/. Can find additional information about the MySQL part at:http://dev.mysql.com Support mariadb development by buying Su Pport/new features from Skysql Ab. You can contacts us about this at sales@skysql.coM. Alternatively consider joining our community based development effort:http://mariadb.com/kb/en/
 contributing-to-the-mariadb-project/

Error: Warning:the host ' test4 ' could is looked up with RESOLVEIP.
Workaround:vim/etc/hosts add 192.168.1.242 on the last line test4

Error:./bin/mysqld:error while loading shared libraries:libaio.so.1:cannot open Shared object file:no such file or direct Ory
Solution:yum -y install libaio-devel libaio

7, copy the configuration file to the/ETC directory coverage before the MY.CNF:

Copy Code code as follows:
[ROOT@CENTOS74 mysql]# CP support-files/my-large.cnf/etc/my.cnf

CP: Do you want to overwrite "/etc/my.cnf"? Y

8, copy the MySQL boot script file to the/ETC/INIT.D directory and rename it to mysqld:

Copy Code code as follows:
[ROOT@CENTOS74 mysql]# CP Support-files/mysql.server/etc/init.d/mysqld

The permission to modify the startup script at the same time is 755:

Copy Code code as follows:
[root@centos74 mysql]# chmod 755!$
chmod 755/etc/init.d/mysqld

9, edit the startup script, define the DataDir path:

Copy Code code as follows:
[Root@centos74 mysql]# Vim/etc/init.d/mysqld

To define the data store path:
Datadir=/data/mysql

10, the mariadb with the command into the $path

[Root@localhost ~]# path= $PATH:/etc/init.d/#当前有效, restarting the shell fails
[root@localhost ~]# echo "Export path= $PATH:/etc/ init.d/">>/etc/profile
[root@localhost ~]# echo" Export path= $PATH:/usr/local/mysql/bin/">>/etc/ Profile
[root@localhost ~]# source!$

11, start mariadb:

[Root@centos74 mysql]#/etc/init.d/mysqld start

Starting MySQL. success!

Step two, start installing PHP

Here to declare, for nginx PHP installation and for the Apache PHP installation is a difference, because Nginx PHP is fastcgi way to combine nginx, can be understood as nginx agent of PHP fastcgi, And Apache is the use of PHP as its own module to invoke. Similarly, the PHP official download address: http://www.php.net/downloads.php

Download PHP

[Rot@localhost src]# cd/usr/local/src
[root@localhost src]# wget

Unzip PHP

[Root@localhost src]# tar zxf php-5.5.23.tar.gz

Create a related account

[Root@localhost src]# useradd-s/sbin/nologin php-fpm

Configuring compilation parameters

Copy Code code as follows:
[Root@localhost src]# CD php-5.5.23
[root@localhost src]# yum-y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel
[Root@localhost php-5.5.23]#./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc-- ENABLE-FPM--with-fpm-user=php-fpm--with-fpm-group=php-fpm--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd-- With-mysqli=mysqlnd--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-freetype-dir--with-iconv-dir- -with-zlib-dir--with-mcrypt--enable-soap--enable-gd-native-ttf--enable-ftp--enable-mbstring-- Disable-ipv6--with-pear--with-curl--enable-bcmath--enable-mbstring--enable-sockets--with-gd--with-libxml-dir=/ Usr/local--with-gettext

Error:configure:error:xml2-config not found. Please check your LIBXML2 installation.
Solution:yum -y install libxml2-devel

Error:configure:error:Please Reinstall the Libcurl distribution-easy.h should is in <curl-dir>/include/curl/
Solution:yum -y install libcurl-devel

Error:configure:error:jpeglib.h not found.
Solution:yum -y install libjpeg-turbo-devel

Error:configure:error:png.h not found.
Solution:yum -y install libpng-devel

Error:configure:error:freetype-config not found.
Solution:configure:error:mcrypt.h not found. Please reinstall Libmcrypt.

Error:configure:error:mcrypt.h not found. Please reinstall Libmcrypt.
Solution:yum -y install libmcrypt-devel

Installing PHP

[Root@localhost php-5.3.27]# make && make install

Each of these steps, if not fully executed correctly, then the next step is not possible, using the echo $? See if the result is "0", if not, it is not done correctly.

Modify configuration file

CP Php.ini-production/usr/local/php/etc/php.ini
vim/usr/local/php/etc/php-fpm.conf

Write the following to the file:

[Global]
PID =/usr/local/php/var/run/php-fpm.pid
error_log =/usr/local/php/var/log/php-fpm.log
[www]
listen =/ Tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
Listen.owner = nobody listen.group
= nobody
PM = Dynamic
Pm.max_children = Pm.start_servers = +
pm.min_spare_servers = 5
pm.max_spare_ Servers =
Pm.max_requests = +
Rlimit_files = 1024

After you save the configuration file, the correct way to verify the configuration is:

/usr/local/php/sbin/php-fpm -t

If the word "test is successful" appears, there is no problem with the configuration.

Start PHP-FPM

CP/USR/LOCAL/SRC/PHP-5.5.23/SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM
chmod 755/etc/init.d/php-fpm
Service PHP-FPM Start


If you want it to boot, execute:

chkconfig php-fpm on

To detect whether to start:

ps aux |grep php-fpm

See if there are many processes (about 20 or more).

Install Nginx

Download Nginx

cd/usr/local/src/
wget http://nginx.org/download/nginx-1.7.12.tar.gz

Decompression Nginx

tar zxvf nginx-1.7.12.tar.gz

Configuring compilation parameters

CD nginx-1.7.12
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_ Sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre

Error :./configure:error:the HTTP Rewrite module requires the PCRE library.
Solution:yum -y install pcre-devel

Error :./configure:error:the HTTP gzip module requires the Zlib library.
Solution:yum install -y zlib-devel

Compiling Nginx

make

Install Nginx

make install

Write Nginx startup scripts and join the system services

vim /etc/init.d/nginx

Write the following:

#!/bin/bash # chkconfig:-description:http service. # Source Function Library. /etc/init.d/functions # Nginx Settings nginx_sbin= "/usr/local/nginx/sbin/nginx" nginx_conf= "/usr/local/nginx/conf/"
    Nginx.conf "nginx_pid="/usr/local/nginx/logs/nginx.pid retval=0 prog= "Nginx" Start () {echo-n $ "starting $prog:"
    Mkdir-p/dev/shm/nginx_temp daemon $NGINX _sbin-c $NGINX _conf retval=$? echo return $RETVAL} stop () {echo-n $ "stopping $prog:" Killproc-p $NGINX _pid $NGINX _sbin-term rm-r
    F/dev/shm/nginx_temp retval=$? echo return $RETVAL} reload () {echo-n $ "reloading $prog:" Killproc-p $NGINX _pid $NGINX _sbin-hup Retv
    Al=$? echo return $RETVAL} restart () {Stop start} configtest () {$NGINX _sbin-c $NGINX _conf-t return 0} CA
 Se "in start" start;;
 stop) stop;;
 reload) reload;;
 restart) restart;;
 Configtest) configtest;; *) echo $ "UsaGE: $ {start|stop|reload|restart|configtest} "retval=1 Esac exit $RETVAL

 

After saving, change permissions:

chmod 755/etc/init.d/nginx
chkconfig--add nginx

If you want to boot up, follow:

Chkconfig Nginx on

Change Nginx Configuration

First empty the original configuration file:

>/usr/local/nginx/conf/nginx.conf

The symbol ">" is meant to be redirected, used alone, to quickly empty a text document.

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

Write the following:

User nobody nobody;
Worker_processes 2;
Error_log/usr/local/nginx/logs/nginx_error.log Crit;
Pid/usr/local/nginx/logs/nginx.pid;

Worker_rlimit_nofile 51200;
  events {use Epoll;
Worker_connections 6000;
  } http {include mime.types;
  Default_type Application/octet-stream;
  Server_names_hash_bucket_size 3526;
  Server_names_hash_max_size 4096; Log_format combined_realip ' $remote _addr $http _x_forwarded_for [$time _local] ' $host ' $request _uri ' $status ' "$http _r
  Eferer "" $http _user_agent "";
  Sendfile on;
  Tcp_nopush on;
  Keepalive_timeout 30;
  Client_header_timeout 3m;
  Client_body_timeout 3m;
  Send_timeout 3m;
  Connection_pool_size 256;
  Client_header_buffer_size 1k;
  Large_client_header_buffers 8 4k;
  Request_pool_size 4k;
  Output_buffers 4 32k;
  Postpone_output 1460;
  Client_max_body_size 10m;
  Client_body_buffer_size 256k;
  Client_body_temp_path/usr/local/nginx/client_body_temp;
  Proxy_temp_path/usr/local/nginx/proxy_temp; Fastcgi_temp_path/usr/locAl/nginx/fastcgi_temp;
  Fastcgi_intercept_errors on;
  Tcp_nodelay on;
  gzip on;
  Gzip_min_length 1k;
  Gzip_buffers 4 8k;
  Gzip_comp_level 5;
  Gzip_http_version 1.1;

Gzip_types text/plain application/x-javascript text/css text/htm application/xml;
  server {Listen 80;
  server_name localhost;
  Index index.html index.htm index.php;

  root/usr/local/nginx/html;
    Location ~ \.php$ {include fastcgi_params;
    Fastcgi_pass Unix:/tmp/php-fcgi.sock;
    Fastcgi_index index.php;
  Fastcgi_param Script_filename/usr/local/nginx/html$fastcgi_script_name;

 }

}

}

After you save the configuration, verify that the configuration file has errors:

/usr/local/nginx/sbin/nginx-t

If the display reads as follows, the configuration file is configured correctly, otherwise you will need to modify the profile according to the error prompt:

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

Start Nginx:

Service Nginx Start

If it does not start, check the "/usr/local/nginx/logs/error.log" file to see if Nginx is started:

PS aux |grep nginx

See if there is a process.

Test whether PHP files are parsed

To create a test file:

vim/usr/local/nginx/html/2.php

The contents are as follows:

<?php echo phpinfo ();? >

Test:

[Root@localhost nginx]# Curl localhost/2.php

Or use the browser to open http://YourServerIPAddress/2.php

Important: If not resolved, check log found not connected to PHP, my PHP version is 5.5.23, compare the new version, need to add in the php/etc/php-fpm.conf file

Listen.owner = Nobody
Listen.group = nobody

These two lines, and then restart the service to use PHP

The reason is/tmp/php-fcgi.sock this file does not have Read permission

At this point, the latest version of the LNMP Environment source code compiled installation completed

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.