Centos7. Construction of LNMP Environment under X

Source: Internet
Author: User
Tags apache php mcrypt

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 preparatory work, first to replace the CENTOS7 firewall into iptables, you can see the following links

CENTOS7 Firewall changed to Iptables

After modifying into iptables, you can clear the filter rules in iptables and then close the SELinux service. Remember not to forget to install GCC gcc-c++ wget net-tools and other functions first.

Install MARIADB First

It should take a long time to compile the database, so I downloaded the binary package that was already compiled, and the download version is mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1. Download the binary package to the/USR/LOCAL/SRC directory:

[Email protected] ~]# cd/usr/local/src/

[Email protected] 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. Unzip the tarball into the/usr/local directory:

[Email protected] src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz-c/usr/local/

3. Create MARIADB Data initialization directory/data/mysql:

[Email protected] src]# mkdir-p/data/mysql

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

[[email protected] src]# useradd-r-s/sbin/nologin MySQL; chown-r mysql.mysql/data/mysql/

5. Rename the extracted mariadb directory:

[Email protected] src]# mv/usr/local/mariadb-10.0.13-linux-x86_64//usr/local/mysql

6. Enter the renamed directory and initialize the MARIADB:

[Email protected] src]# cd/usr/local/mysql/

[Email protected] 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.0M

........................................................................

The latest information about MariaDB are available at http://mariadb.org/.

You can find additional information about the MySQL part at:

Http://dev.mysql.com

Support MariaDB development by buying Support/new features from

Skysql Ab. can contact us on [email protected]

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 being looked up with RESOLVEIP.

Workaround: vim/etc/hosts add 192.168.1.242 test4 on the last line

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

Workaround: yum-y Install Libaio-devel Libaio

7, copy the configuration file to/etc directory before overwriting the MY.CNF:

[email protected] mysql]# CP support-files/my-large.cnf/etc/my.cnf

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

8. Copy the MySQL startup script file into the/ETC/INIT.D directory and rename it to mysqld:

[email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld

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

[Email protected] mysql]# chmod 755!$

chmod 755/etc/init.d/mysqld

9. Edit the startup script to define the DataDir path:

[Email protected] mysql]# Vim/etc/init.d/mysqld

Define the data storage path:

Datadir=/data/mysql

10, put mariadb command into the $path

[Email protected] ~]# path= $PATH:/etc/init.d/#当前有效, restarting the shell will expire

[Email protected] ~]# echo "Export path= $PATH:/etc/init.d/" >>/etc/profile

[Email protected] ~]# echo "Export path= $PATH:/usr/local/mysql/bin/" >>/etc/profile

[Email protected] ~]# source!$


11. Start MARIADB:

[[email protected] mysql]#/etc/init.d/mysqld start

Starting MySQL. success!

Step two, start installing PHP

Here to first declare, for Nginx PHP installation and for Apache PHP installation is different, because Nginx PHP is fastcgi in the way of combining nginx, can be understood as Nginx proxy php fastcgi, and Apache is calling PHP as its own module. Similarly, PHP official: http://www.php.net/downloads.php

Download PHP

[Email protected] src]# CD/USR/LOCAL/SRC

[Email protected] src]# wget http://am1.php.net/distributions/php-5.5.23.tar.gz

Unzip PHP

[Email protected] src]# tar zxf php-5.5.23.tar.gz

Create a related account

[Email protected] src]# useradd-s/sbin/nologin php-fpm

Configuring compilation parameters

[Email protected] src]# CD php-5.5.23

[Email protected] src]# yum-y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel Libcurl-dev El

[Email protected] 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--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.

Workaround: Yum-y Install Libxml2-devel

Error: Configure:error:Please Reinstall the Libcurl distribution-easy.h should be in <curl-dir>/include/curl/

Workaround: Yum-y Install Libcurl-devel

Error: Configure:error:jpeglib.h not found.

Workaround: Yum-y Install Libjpeg-turbo-devel

Error: Configure:error:png.h not found.

Workaround: Um-y Install Libpng-devel

Error: Configure:error:freetype-config not found.

Workaround: Configure:error:mcrypt.h not found. Please reinstall Libmcrypt.

Error: Configure:error:mcrypt.h not found. Please reinstall Libmcrypt.

Workaround: Yum-y Install Libmcrypt-devel


Install PHP

[[email protected] 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 executed correctly.

Modifying a 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 = 50

Pm.start_servers = 20

Pm.min_spare_servers = 5

Pm.max_spare_servers = 35

Pm.max_requests = 500

Rlimit_files = 1024

After you save the configuration file, verify that the configuration is correct by:

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

If a word like "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

Detect whether to start:

PS aux |grep php-fpm

See if there are a lot of processes (about 20 or more).

Installing 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.

Workaround: Yum-y Install Pcre-devel

Error:./configure:error:the HTTP gzip module requires the Zlib library.

Workaround: Yum install-y zlib-devel


Compiling Nginx

Make

Installing Nginx

Make install


Write Nginx startup scripts and join 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 "$" 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 the Merlot:

chmod 755/etc/init.d/nginx

Chkconfig--add Nginx

If you want to start the boot, please do:

Chkconfig Nginx on

Change Nginx Configuration

First, empty the original configuration file:

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

The ">" symbol is meant for redirection, and it is used alone to quickly empty a text document.

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

Write the following content:

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 _referer" "$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;

}


}


}

Once the configuration is saved, verify that the configuration file has errors:

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

If the display reads as follows, the configuration is correct, otherwise you will need to modify the configuration file according to the error message:

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 you cannot 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:

[Email protected] nginx]# Curl localhost/2.php

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

Important: If you do not resolve, check the 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 will be able 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.


This article is from "Microsoft Technology Online" blog, please make sure to keep this source http://bjwxjy.blog.51cto.com/525755/1707438

Centos7. Construction of LNMP Environment under X

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.