LNMP environment compile and install

Install nginx

I compile lnmp installed, download the installation package Nginx

wget http://nginx.org/download/nginx-1.13.4.tar.gz

Turn off the firewall and selinux

setenforce 0
service iptables stop

Check the installation dependencies 

(Run the following commands to install nginx library.)

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

Creating accounts and groups running nginx

You need to create an account before you install nginx run, the account can not directly log in

groupadd www
useradd www -s /sbin/nologin -g www

Nginx configuration Installation Options

About nginx installation options can refer to the official website of the parameter description, where only some simple configuration, specify only what its installation position, the other other with a default configuration

./configure  --prefix=/usr/local/nginx

Official website parameters Description: http://nginx.org/en/docs/configure.html

General Configuration :( put a line execution when execution)

./configure  
    --sbin-path=/usr/local/nginx/nginx
    --conf-path=/usr/local/nginx/nginx.conf
    --pid-path=/usr/local/nginx/nginx.pid
    --with-http_ssl_module
    --with-pcre=../pcre-8.41
    --with-zlib=../zlib-1.2.11
    --user=www --group=www

Compile and install

make && make install

Start, stop, restart

Sbin directory need to switch to the installation directory nginx

Start nginx

nginx

By ps -ef | grep nginx nginx has started to see success

Stop nginx

nginx -s stop

Restart

nginx -s reload

The default site testing

Access, local and remote access (access via IP), CentOS default remote access can not, because: 80 port is not open. Solution: Turn off the firewall or firewall rules temporarily empty!

Configuring nginx boot

The / usr / local / nginx / sbin / nginx command to the /etc/rc.d/rc.local file, rc.local file will be executed when the system starts. But CentOS7 proposed to add the service start-up service description file is written to the system service, because there is no default rc.local execute permissions, add execute permissions to it.

/etc/rc.d/ Vim the rc.local 
# Add the following parameters 
/ usr / bin / Nginx 
the chmod + X /etc/rc.d/rc.local

Here is one of a kind way, you can also use chkconfig nginx on, but this way, you need to start writing a script for nginx. It will be mentioned later.

Configuration environment variable

Echo $ PATH environment variable to view the
configuration environment variable, this is generally the server is not necessary. Here also briefly about

  VI / etc / Profile 
  # After editing the immediate environment variable effect liter, execute the following command 
  source / etc / profile

The nginx configured as a service

So that it can be carried out by service nginx restart to start, stop, restart, where the need to write a separate service startup script for nginx. Scripting details

After this a good deal, it is very easy to set up boot up.

chkconfig --add nginx
chkconfig nginx on

Nginx supports the PHP

Test whether the normal php file parsing

<?php
phpinfo();

When access will be prompted to download, indicating normal PHP file is not resolved!

Solution

Nginx resolved by modifying the site configuration file
to modify nginx configuration file (/usr/local/nginx/conf/nginx.conf)

# Copy the code below, the Server site configuration, and remove the front Notes 

#location ~ \ .php $ { 

#root HTML; 

#fastcgi_pass 127.0.0.1:9000 ; 

#fastcgi_index the index.php; 

#fastcgi_param SCRIPT_FILENAME web root directory $ fastcgi_script_name; # write here is not recommended death, can be used instead of $ document_root 

#include fastcgi_params; 

}

Php profile here can be properly parsed (php environment following installation, do not worry)

Set multi-site set up multiple sites, each site is recommended to separate configuration files to write, then, by  include /conf/vhosts/*.confloading the form

Here prepare two domain names:
www.a.com  resolve to server IP
www.b.com  resolve to the IP server

Create a site profile directory

mkdir /usr/local/nginx/conf/vhosts

edit nginx.conf

Add the following

include /usr/local/nginx/conf/vhosts/*.conf

Create a site directory

# Create www.a.com site directory 
mkdir / var / the WWW / www.a.com 
# create a test Home 
vim /var/www/www.a.com/ index.php # Input site domain name: www.a.com 

# create www.b.com site directory 
mkdir / var / the WWW / www.b.com  # create a test Home  vim /var/www/www.b.com/index.php # input site domain name: www.b.com

Create a site profile

Create a site profile www.a.com

Create Site # www.a.com profile 
mkdir / var / local / Nginx / the conf / vhosts / www.a.com.conf 
# following contents: 
Server { 
    the listen 80 ; 
    server_name www.a.com; # Set domain 
    index index.php index.html; # default home 
    root / var / the WWW / www.a.com; # sites catalog 
 # for the Load the Configuration Files . Block at The Server default  the include /etc/nginx/default.d/*.conf; # load extended configuration 
 LOCATION / {  } 
 error_page 404 /404.html;  LOCATION /40x.html = {  } 
 error_page 500 502 503 504 /50x.html;  LOCATION /50x.html = {  }  # the following is PHP support, can use the public files introduced LOCATION ~ \ .php $ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

Creating www.b.com  site profile

# Direct copy a site, and then make changes to 
cp ./www.a.com.conf ./www.b.com.conf

Restart nginx and two test sites

service nginx restart

Php mounting step under environment nginx

System Environment: 
CentOS 6.5 / 7.0 x86_64 
Fedora 20 x86_64

.Yum install a package dependencies

yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel openssl openssl-devel libxslt-devel
安装过显示Nothing to do

II. Install package libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
tar zxf libiconv-1.15.tar.gz
cd libiconv-1.15

Then compile

./configure --prefix = / usr / local / libiconv # ( in libiconv- . 1 the next directory .15)

Compiled for installation in this directory

make && make install

III. Configuring compile and install PHP-5.6.30.tar.gz

wget HTTP: // tw1.php.NET/get/php-5.6.30.tar.gz/from/this/mirror # (download / usr / local / src, the can, this is the recommended elsewhere) 
Music Videos Mirror PHP- 5.6 . 30 . the tar .gz
 the tar xzvf PHP- 5.6 . 30 . the tar .gz

Then configure

④(进到php-5.6.30解压后的目录里)

./configure \
--prefix=/usr/local/php \
--enable-fpm \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-zlib \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--with-curl \
--enable-ftp \
--with-libxml-dir

Under normal circumstances be wrong, usually what the package is not installed, installed just fine in accordance with the error message. Finally, the Xiang think you for what's on the same subject.

Then compile and install in this directory

make && make install

Four .php.ini Configuration

First, we need to configure the php.ini file is the 
installation directory has two files: php.ini -Development and php.ini- Production's 
php.ini - Production's online version to use 
php.ini - development using a development version 
we choose to carry out development configuration 

CP the php.ini-Development /usr/local/php/lib/php.ini

Five .php-fpm with nginx configuration because it runs php port is 9000, which is why the above nginx above configuration causes the horse

① copy PHP- FPM configuration file
     cp -R ./sapi/fpm/php-fpm.conf / usr / local / php / etc / PHP- fpm.conf 
② php will give us ready init.d.php - FPM
     cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php- fpm 
③ to PHP - adding service to chkconfig fpm list 
    chkconfig --add PHP- fpm 
④ set boot from the start 
    chkconfig PHP - fpm ON 
⑤ plus permission 
    chmod + the X-/etc/init.d/php- FPM 
⑥ start PHP - FPM 
    Service PHP - FPM start      
    a successful show PHP starting -fpm DONE

VI. Create a user (can be omitted, since nginx above already set up, execute again it does not matter, but will be reported this user already exists)

Creating www user 
 groupadd www 
 useradd -g www -s / sbin / nologin -M www

VII. PHP commands to add environment variables

① editor vim / etc / Profile 
② added in the last line of the PATH = $ the PATH: $ the HOME / bin: / usr / local / PHP / bin
Then save the above profile file, execute the following command 

Source / etc / profile (the environment variables to take effect) See the PHP version PHP -v

Php version information appears on ok, then nginx configure the domain name, location added index.php like, wrote the above. Open your browser and run their own virtual site settings, the display can access the php file just fine.

Guess you like

Origin www.cnblogs.com/hcfinal/p/11442142.html