Install the latest LNMP environment in CentOS 7 source code

Source: Internet
Author: User
Tags mcrypt

Install the latest LNMP environment in CentOS 7 source code

As the company requires the latest version of ZABBIX2.4.4 to require the latest version of CentOS7 and the latest version of LNMP environment, I am exploring to use the latest version of environment to build the 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, make some preparations. First, replace the centos7 firewall with iptables. For more information, see the following link.
Change centos7 firewall to iptables

After modification to iptables, you can clear the filter rules in iptables, and then disable the selinux service. Do not forget to install gcc-c ++ wget net-tools and other functions first.

First install mariadb

It should take a long time to compile the database, so here I download the binary package that has been compiled, download version for mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1. Download the binary package to the/usr/local/src directory:
[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
2. decompress the package to the/usr/local directory:
[Root @ centos74 src] # tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz-C/usr/local/
3. Create the mariadb data initialization directory/data/mysql:
[Root @ centos74 src] # mkdir-p/data/mysql
4. Add the System user mysql. Do not log on to the system. Modify the master and Group of the mariadb data initialization directory to mysql:
[Root @ centos74 src] # useradd-r-s/sbin/nologin mysql; chown-R mysql. mysql/data/mysql/
5. Rename the extracted mariadb directory:
[Root @ centos74 src] # mv/usr/local/mariadb-10.0.13-linux-x86_64 // usr/local/mysql
6. Enter the renamed directory and initialize 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 memory heap is disabled
140906 2:03:19 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140906 2:03:19 [Note] 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.0 M
........................................ ................................
The latest information about MariaDB is available at http://mariadb.org /.
You can find additional information about the MySQL part:
Http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL AB. can You contact 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 not be looked up with resolveip.
Solution: Add 192.168.1.242 test4 to the last line of vim/etc/hosts.
Error:./bin/mysqld: error while loading shared libraries: libaio. so.1: cannot open shared object file: No such file or directory
Solution: yum-y install libaio-devel libaio
7. Copy the configuration file to the/etc directory to overwrite my. cnf:
[Root @ centos74 mysql] # cp support-files/my-large.cnf/etc/my. cnf
Cp: overwrite "/etc/my. cnf "? Y
8. Copy the mysql STARTUP script file to the/etc/init. d directory and rename it mysqld:
[Root @ centos74 mysql] # cp support-files/mysql. server/etc/init. d/mysqld
At the same time, the permission to modify the startup script is 755:
[Root @ centos74 mysql] # chmod 755! $
Chmod 755/etc/init. d/mysqld
9. Edit the startup script and define the datadir path:
[Root @ centos74 mysql] # vim/etc/init. d/mysqld
Define the data storage path:
Datadir =/data/mysql
10. Place the built-in commands of mariadb into the $ PATH
[Root @ localhost ~] # PATH = $ PATH:/etc/init. d/# currently valid, it will expire after shell restart
[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 2: install php

Here, we must first declare that php installation for Nginx is different from php installation for apache, because php In Nginx is combined with nginx in fastcgi mode, it can be understood that nginx acts as the proxy for php fastcgi, while apache calls php as its own module. Similarly, php official: http://www.php.net/downloads.php
Download php
[Rot @ localhost src] # cd/usr/local/src
[Root @ localhost src] # wget http://am1.php.net/distributions/php-5.5.23.tar.gz
Decompress php
[Root @ localhost src] # tar zxf php-5.5.23.tar.gz
Create related account
[Root @ localhost src] # useradd-s/sbin/nologin php-fpm
Configure compilation Parameters
[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 libcurl-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 -- -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 -- enable-exif -- 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 shoshould be in <curl-dir>/include/curl/
Solution: yum-y install libcurl-devel
Error: configure: error: Invalid Lib. h not found.
Solution: yum-y install libjpeg-turbo-devel
Error: configure: error: png. h not found.
Solution: um-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

 


Install php
[Root @ localhost php-5.3.27] # make & make install
If the preceding steps are not completely correctly executed, the next step cannot be performed. Use echo $? Check whether the result is "0". If not, the execution is not correct.
Modify configuration file
Cp php. ini-production/usr/local/php/etc/php. ini
Vim/usr/local/php/etc/php-fpm.conf
Write the following content into 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 = 50
Pm. start_servers = 20
Pm. min_spare_servers = 5
Pm. max_spare_servers = 35
Pm. max_requests = 500
Rlimit_files = 1024
After saving the configuration file, check whether the configuration is correct:
/Usr/local/php/sbin/php-fpm-t
If "test is successful" is displayed, the configuration is correct.
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 start up, execute:
Chkconfig php-fpm on
Check whether startup is Enabled:
Ps aux | grep php-fpm
Check 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
Decompress nginx
Tar zxvf nginx-1.7.12.tar.gz
Configure 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


Compile nginx
Make
Install nginx
Make install


Compile the nginx STARTUP script and add it to the system service.
Vim/etc/init. d/nginx
Write the following content:
#! /Bin/bash
# Chkconfig:-30 21
# 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-rf/dev/shm/nginx_temp
RETVAL =$?
Echo
Return $ RETVAL
}


Reload (){
Echo-n $ "Reloading $ prog :"
Killproc-p $ NGINX_PID $ NGINX_SBIN-HUP
RETVAL =$?
Echo
Return $ RETVAL
}


Restart (){
Stop
Start
}


Configtest (){
$ NGINX_SBIN-c $ NGINX_CONF-t
Return 0
}


Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Reload)
Reload
;;
Restart)
Restart
;;
Configtest)
Configtest
;;
*)
Echo $ "Usage: $0 {start | stop | reload | restart | configtest }"
RETVAL = 1
Esac


Exit $ RETVAL
After saving, change the settings:
Chmod 755/etc/init. d/nginx
Chkconfig -- add nginx
To start the instance, run the following command:
Chkconfig nginx on
Change nginx Configuration
First, clear the original configuration file:
>/Usr/local/nginx/conf/nginx. conf
">" Indicates redirection. You can use it to quickly clear a text document.
Vim/usr/local/nginx/conf/nginx. conf
Write the following content:
User 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_referer" "$ http_user_agent "';
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 30;
Client_header_timeout 3 m;
Client_body_timeout 3 m;
Send_timeout 3 m;
Connection_pool_size 256;
Client_header_buffer_size 1 k;
Large_client_header_buffers 8 4 k;
Request_pool_size 4 k;
Output_buffers 4 32 k;
Post pone_output 1460;
Client_max_body_size 10 m;
Client_body_buffer_size 256 k;
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 1 k;
Gzip_buffers 4 8 k;
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 saving the configuration, check whether the configuration file has an error:
/Usr/local/nginx/sbin/nginx-t
If the following content is displayed, the configuration is correct. Otherwise, you must modify the configuration file 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 cannot be started, check the "/usr/local/nginx/logs/error. log" file and check whether nginx is started:
Ps aux | grep nginx
Check whether a process exists.

Test whether to parse the PHP File

Create a test file:
Vim/usr/local/nginx/html/2.php
The content is as follows:
<? Php echo phpinfo ();?>
Test:
[Root @ localhost nginx] # curl localhost/2.php
Or open http: // YourServerIPAddress/2.php in the browser.

Important: If the parsing fails, check the log to find that the connection to php is not available, my php version is 5.5.23, to compare the new version, you need to add in the php/etc/php-fpm.conf File
Listen. owner = nobody
Listen. group = nobody
In these two cases, restart the Service to use php.
The reason is/tmp/php-fcgi.sock this file has no read permission
At this point, the source code compilation and installation of the latest LNMP environment are complete.

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Build and install the LNMP production environment in CentOS 6.4

Practical Production Environment-LNMP architecture compilation and installation + SSL encryption implementation

LNMP full-featured compilation and installation for CentOS 6.3 notes

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

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.