Installation nginx + php + mysql detailed tutorial environment under linux

We did not talk much on the code

linux environment: centos 7.0 64 Wei

nginx: nginx-1.8.0.tar.gz

php: php-7.1.1.tar.gz

mysql: mysql-5.6.21.tar.gz

libxml2:libxml2-2.9.1.tar.gz

openssl:openssl-1.0.1e.tar.gz

zlib:zlib-1.2.3.tar.gz

pcre:pcre-8.36.tar.gz

Here the desired compression package I have downloaded well, and pro-test available

Link: https: //pan.baidu.com/s/1Ge1ucbld37zXy_nRgFTU1Q
extraction code: w3by

First, the preparatory work

1. Create an installation directory

Here creation / www / web for the deposit program code; / www / source environment installation directory; / www / lnmp for the installation software

Create an installation directory command:

mkdir -p /www/{lnmp,source,web}

2, the upper upload software downloaded using ftp (or other tools) / www / lnmp, and decompress:

[root@localhost lnmp]# cd /www/lnmp/
[root@localhost lnmp]# find ./*.tar.gz -exec tar zxvf {} \;

3, installation tools

Here with yum install it in the process of compiling the required build tools and applets, such as: gcc, gd libraries, cmake, and so on. So many small software, we do not need to compile and install, because the software is installed, the future does not modify the operation is merely a tool.

yum install -y gcc gcc-c++ make sudo autoconf libtool-ltdl-devel gd-devel \
        freetype-devel libxml2-devel libjpeg-devel libpng-devel \
        openssl-devel curl-devel patch libmcrypt-devel \
        libmhash-devel ncurses-devel bzip2 \
        libcap-devel ntp sysklogd diffutils sendmail iptables unzip cmake

Note: This may be the following error

Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  71 M RSS (370 MB VSZ)
    Started: Sat Feb 11 18:45:08 2017 - 00:34 ago
    State  : Running, pid: 3033

This is because yum is running, we need to stop yum, yum stop command as follows:

[root@localhost ~]# kill /var/run/yum.pid

After stopping yum, yum install further above.

 

4. Create a user

We need to create two users, one for start mysql, for a start nginx

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r mysql -g mysql
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -r www -g www

Here we have successfully created two user groups and mysql www, mysql also created two users and www. Now our preparatory work has been done, the following is installed lnmp environment.

 

Second, install nginx

Before installing nginx, we need to install three dependencies:

pcre: When using the nginx rewrite module requires pcre library support

openssl: When using ssl function, you need the support of openssl library

zlib: when using gzip module requires zlib library support.

These three modules are our common, so this three dependencies or to be installed.

 

1, install pcre

[root@localhost lnmp]# cd /www/lnmp/pcre-8.36
[root@localhost pcre-8.36]# ./configure
[root@localhost pcre-8.36]# make
[root@localhost pcre-8.36]# make install

Note: The use linux just here to talk about friends, after the above ./configure is press the "Enter", and then wait for the configuration, after the configuration, and then enter the make, then "Enter" and wait for compiling, compiled good , type make install it. Too many code compilation process arise, I copy down the whole bad. Haha! ! !

 

2, install openssl

[root@localhost pcre-8.36]# cd /www/lnmp/openssl-1.0.1e
[root@localhost openssl-1.0.1e]# ./config
[root@localhost openssl-1.0.1e]# make
[root@localhost openssl-1.0.1e]# make install

 

3, install zlib

[root@localhost openssl-1.0.1e]# cd /www/lnmp/zlib-1.2.3
[root@localhost zlib-1.2.3]# CFLAGS="-O3 -fPIC" ./configure
[root@localhost zlib-1.2.3]# make && make install

 

4, install nginx

When installing nginx, the parameters may be more. However, I recommend the most simplified installation. nginx has many modules, which module if not, try not to install, we enter nginx source directory can use ./configure --help to see what the compiler parameters. Too many parameters, there is not introduced one by one, to see if you can help or want to learn on their own Baidu. However, commonly used are the following:

--prefix = PATH the directory to be installed

--sbin-path = PATH Specifies the path to nginx binary file is not specified, then the path dependence --prefix option

--conf-path = PATH if not specified on the command line configuration file, you will find the configuration file to the path specified by --prefix

--error-log-path = PATH Error file path, nginx written to the error log file address

--pid-path = <path> pid file location nginx master writing process, usually var / run under 

Users --user = <user> worker processes running

Group --group = <group> worker processes run

--with-http_ssl_module open ssl module

--with-zlib = DIR source directory provided zlib

--with-openssl = DIR source directory provided openssl

--with-pcre = DIR source directory provided pcre

After compiling complete understanding of the parameters, we compile and install

[root@localhost zlib-1.2.3]# cd /www/lnmp/nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --help // 这是查看帮助的命令
[root@localhost nginx-1.8.0]# ./configure --user=www --group=www --prefix=/www/source/nginx --with-pcre=/www/lnmp/pcre-8.36 --with-zlib=/www/lnmp/zlib-1.2.3 --with-openssl=/www/lnmp/openssl-1.0.1e
[root@localhost nginx-1.8.0]# make && make install

After installing, we can see with ls / www / source, found a nginx, instructions have been installed successfully.

[root@localhost nginx-1.8.0]# ls /www/source/nginx
[root@localhost nginx-1.8.0]#

After a successful installation, you need to configure, configure to not explain, after a good php after security, together explain configuration.

 

 

Third, install mysql

Here begin the installation mysql, but I personally feel is the best mysql installed. Because the compiler parameters do not need much (in fact there are a lot of compiler parameters), we can manually modify the configuration file in the future. If you want to know, you can view http://laowafang.blog.51cto.com/251518/1294964/ , the feeling is still very detailed written.

 

1, the installation process

Mysql installation is very simple, after mysql 5.5 use cmake to compile, however, at the beginning of the preparatory work, we have installed cmake, so rest assured that use the following command to install it, the process of installing mysql a bit longer to prepare a little heart .

[root@localhost nginx-1.8.0]# cd /www/lnmp/mysql-5.6.21
[root@localhost mysql-5.6.21]# cmake -DCMAKE_INSTALL_PREFIX=/www/source/mysql
[root@localhost mysql-5.6.21]# make
[root@localhost mysql-5.6.21]# make install

 

2, the configuration mysql

After you have installed and can not be used directly, we have to configure it to boot into the installed directory.

[root @ localhost mysql-5.6.21] # cd / the WWW / Source / mysql / 
[root @ localhost mysql] # RM -f /etc/my.cnf // delete the system comes with mysql configuration file 
[root @ localhost mysql ] # chown -R & lt MySQL: MySQL ./ 
[the root @ localhost MySQL] // # ./scripts/mysql_install_db mounted --user = MySQL database 
[MySQL the root @ localhost] # -R & lt chown the root: the root ./* 
[the root @ localhost mysql] # chown -R mysql: mysql ./data/

We will be copied to /etc/init.d/ under ./support-files/mysql.server

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

Linux modify environment variables, and finally adding an in / etc / profile file 

export PATH="/www/source/mysql/bin:$PATH"

[root @ localhost MySQL] # vim / etc / Profile 
[root @ localhost MySQL] # Source / etc / Profile // this one is to make the configuration take effect immediately 
[root @ localhost mysql] # service mysqld start // Start MySQL 
Starting MySQL. . [OK]

Here you can directly manipulate the database, just installed mysql root is no password, (mysql 5.7 have just installed a password), such as:

 

Fourth, install php

Before installing php, but also a mounting dependencies libxml2

 

1, install libxml2

[root@localhost mysql]# cd /www/lnmp/libxml2-2.9.1
[root@localhost libxml2-2.9.1]# ./configure --with-python=no
[root@localhost libxml2-2.9.1]# make && make install

Special Note: If this error occurs, you can use the following methods, other software, if at the time of installation, is the same reason

/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `.ro  
data' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [libxml2.la] 错误 1
make[2]: Leaving directory `/lnmp/libxml2-2.9.1'
make[1]: *** [all-recursive] 错误 1
make[1]: Leaving directory `/lnmp/libxml2-2.9.1'
make: *** [all] 错误 2

Solution:

./configure --with-python=no --enable-shared=no --with-pic=PIC

 

2, installation php7.1

php compiler parameters are also many, here is not introduced one by one, you can use ./configure --help to see, where the arguments are as follows:

--prefix to install directory

--enable-fpm fpm start mode, the required opening nginx

--enable-fpm-user fpm startup account

--enable-fpm-group fpm startup account group

--with-openssl openssl open

--with-libxml-dir open libxml

--with-zlib zlib open

--enable-mbstring开启 mbstring

--with-mysqli=mysqlnd 开启 mysqli

--with-pdo-mysql 开启 pdo mysql

--with-gd gd library open

--enable-sockets 开启 sockets

--with-curl open curl

--enable-maintainer-zts open maintainer zts, after the installation of multi-threaded, then this must be open

[root@localhost libxml2-2.9.1]# cd /www/lnmp/php-7.1.1
[root@localhost php-7.1.1]# ./configure --prefix=/www/source/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=/www/source/mysql/ --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-sockets --with-curl --enable-maintainer-zts
[root@localhost php-7.1.1]# make
[root@localhost php-7.1.1]# make test // 测试完之后,输入 n
[root@localhost php-7.1.1]# make install

So far, all of the software has been installed, let's explain, environment configuration

 

Fifth, environment configuration

 

1, php configuration

[root@localhost php-7.1.1]# cd /www/source/php/
[root@localhost php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@localhost php]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
[root@localhost php]# cp /www/lnmp/php-7.1.1/php.ini-production lib/php.ini

 

2, start php-fpm

[root@localhost php]# /www/source/php/sbin/php-fpm

 

3, nginx configuration

[root@localhost php]# cd /www/source/nginx/conf/
[root@localhost conf]# vim nginx.conf

 

Nginx.conf saved in the server as follows

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  logs/host.access.log  main;

    root    /www/web;
    index   index.html index.php;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  /www/web$fastcgi_script_name;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        include        fastcgi_params;
    }
}

 

4, start nginx

[root@localhost conf]# /www/source/nginx/sbin/nginx

 

Sixth, the test environment

Create a index.php in / www / web / directory, as follows:

<?php
phpinfo();

 

Modify index.php owned group

[root@localhost php]# chown -R www:www /www/web/

Open a browser to access localhost, you can see the following page, indicating that the environment has been set up successfully.

 

This blog is not a small series of original, but Xiaobian pro-test, is really available, along with archive, welcome your reference.

Guess you like

Origin www.cnblogs.com/phpxj/p/11587381.html