Establish LNMP environment and lnmp Environment

Source: Internet
Author: User

Establish LNMP environment and lnmp Environment

LNMPEnvironment Construction

Linux + Nginx + MySQL + PHP

PHP is a scripting language, which is widely used in Chinese and even the world.

Nginx is a web service software, and apache is a type of software. Currently, more and more enterprises are using nginx.

MySQL is currently the most popular small relational database service.

Unlike LAMP, N in LNMP indicates Nginx (similar to a web service software of Apache. Currently, this type of environment has many applications. Nginx was designed to provide a fast, efficient, and concurrent web service software. Nginx is superior to Apache in processing static pages. However, Nginx does not have much advantage over Apache in Processing dynamic pages. However, many fans are still keen on Nginx. As Nginx technology matures, it is becoming increasingly popular in the web service software field.

Install MySQL

The steps are exactly the same as those for installing mysql in LAMP.

1. Download mysql to/usr/local/src/

[Root @ CentOS100src] # wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz

This is a 64-bit package. A 32-bit system uses a 32-bit package:

Http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icciglibc23.tar.gz

2. decompress the downloaded package.

[Root @ cento100 src] # tar-xvzf mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz

3. Move the decompressed package to/usr/local/and change it to mysql.

[Root @ cento100 src] # mv mysql-5.1.40-linux-x86_64-icc-glibc23/usr/local/mysql

4. Create a mysql user

[Root @ cento100 src] # useradd-s/sbin/nologin mysql

5. Create a mysql database folder and modify the master and group

[Root @ cento100 mysql] # mkdir-p/data/mysql; chown-R mysql: mysql/data/mysql

6. initialize the database

[Root @ CentOS101 mysql] #./scripts/mysql_install_db -- user = mysql -- datadir =/data/mysql

. /Scripts/mysql_install_db is a file in the database folder. -- user defines the master of the database and -- datadir defines where the database is installed. We recommend that you store the file in a partition in a large space, this directory needs to be created by itself. If two "OK" statements are displayed after execution, the execution is correct. The problem can be solved based on the problem (the final solution is attached !)

7. Copy the configuration file

[Root @ CentOS101 mysql] # cp support-files/my-large.cnf/etc/my. cnf

8. Copy the startup script file and modify its attributes.

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

[Root @ CentOS101 mysql] # chmod 755/etc/init. d/mysqld

9. Modify the Startup Script

[Root @ CentOS101 mysql] # vim/etc/init. d/mysqld

"Datadir =/data/mysql" is the place to be modified (the directory defined during database initialization)

Add the startup script to the system service items, set the startup to start mysql

[Root @ CentOS101 mysql] # chkconfig -- add mysqld

[Root @ CentOS101 mysql] # chkconfig mysqld on

[Root @ CentOS101 mysql] # service mysqld start

If it cannot be started, check the error log under/data/mysql/. This log is usually the host name. err. The command to check whether mysql is started is:

[Root @ CentOS101 mysql] # ps aux | grep mysqld

 

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. In LNMP, mysql must be installed before PHP is installed. Php official: http://www.php.net/downloads.php

1. Download php

[Root @ CentOS5 src] # wget http://am1.php.net/distributions/php-5.3.27.tar.gz

2. Decompress php

[Root @ CentOS5 src] # tar-xvzf php-5.3.27.tar.gz

3. Create an account

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

4. Configure compilation Parameters

[Root @ localhost src] # cd php-5.3.27

[Root @ localhost php-5.3.27] # make clean

This command is used to clear some files generated when PHP is installed, so as to avoid confusion with the previous compilation.

[Root @ localhost php-5.3.27] #. /Configure -- prefix =/usr/local/php_nginx -- with-config-file-path =/usr/local/php_nginx/etc -- enable-fpm -- with-fpm-user = php -fpm -- with-fpm-group = php-fpm -- with-mysql =/usr/local/mysql -- with-mysql-sock =/tmp/mysql. sock-- 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 -- enable-zend-multibyte -- disable-ipv6 -- with-pear -- with-curl -- with-openssl

The configuration parameters are somewhat different from the previous ones,-- Enable-fpmRequired. The fpm file cannot be generated without adding.-- With-config-file-pathSpecifies the path of the php configuration file, that is, the path of php. ini.

Error message:

Configure: error: Please reinstall the libcurl distribution-

Easy. h shoshould be in <curl-dir>/include/curl/

Solution:

Yum install-y libcurl-devel

5. Compile php

[Root @ localhost php-5.3.27] # make

In this step, we usually encounter some errors.

/Usr/bin/ld: cannot find-Lltdl

Collect2: ld returned 1 exit status

Make: *** [sapi/fpm/php-fpm] Error 1

Solution:

Yum install-y libtool-ltdl-devel

6. install php

[Root @ localhost php-5.3.27] # make install

If the preceding steps are not completely correctly executed, the next step cannot be performed. Do you still remember to determine whether the execution is correct? Use echo $? Check whether the result is "0". If not, the execution is not correct.

7. Copy the configuration file

[Root @ localhost php-5.3.27] # cp php. ini-production/usr/local/php_nginx/etc/php. ini

[Root @ localhost php-5.3.27] # cp sapi/fpm/php-fpm.conf/usr/local/php_nginx/etc/

After saving the configuration file, check whether the configuration is correct:

/Usr/local/php_nginx/sbin/php-fpm-t

If "test is successful" is displayed, the configuration is correct.

8. Start php-fpm

First copy the Startup File cp/usr/local/src/php-5.3.27/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

Netstat-lnp | grep php

Tcp 0 0 127.0.0.1: 9000 0.0.0.0: * LISTEN 11265/php-fpm

Install nginx

Nginx official website (http://nginx.org), from the official website can see nginx update speed is very fast, it also reflects the fact that the current use of nginx to run the site of the Company or more people.

(Recently nginx reported a security vulnerability, the impact of a wide range of CVE-2013-4547, so the old version of the previous need to upgrade, 1.4.4, 1.5.7 and later versions no problem)

1. Download nginx

Cd/usr/local/src/

Wget http://nginx.org/download/nginx-1.6.2.tar.gz

2. Decompress nginx

Tar-xvzf nginx-1.6.2.tar.gz

3. Configure compilation Parameters

Cd nginx-1.4.4

./Configure -- prefix =/usr/local/nginx -- with-pcre

An error occurred while editing:

Checking for PCRE library... not found

Checking for PCRE library in/usr/local/... not found

Checking for PCRE library in/usr/include/pcre/... not found

Checking for PCRE library in/usr/pkg/... not found

Checking for PCRE library in/opt/local/... not found

Pcre is missing. pcre is used to support regular expressions. solution:

Yum install-y pcre-devel

4. Compile nginx

Make

5. Install nginx

Make install

Nginx is relatively small, so it will be installed soon and there will be no errors.

6. Start nginx. nginx is very small and does not start the service file.

/Usr/local/nginx/sbin/nginx

View: ps aux | grep nginx

Netstat-lnp | grep nginx

Test: access the local IP address directly from a browser

7. Change nginx Configuration

Configuration File Location:/usr/local/nginx/conf/nginx. conf

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

Modify:

Events {

Worker_connections 4096;

}

This value is generally adjusted to a large number.

 

The configuration of "server {}" is a virtual host, and the "location" in the server needs to be changed:

Location /{

Root/web/123;

Index index.html index.htm index. php;

}

Root specifies the virtual host Directory, which is replaced with the discuz directory installed during LAMP. Open and modify the following location and php-related content:

Location ~ \. Php $ {

Root/web/123;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME/web/123 $ fastcgi_script_name;

Include fastcgi_params;

 

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

Reload nginx:

/Usr/local/nginx/sbin/nginx-s reload

If it cannot be started, view the "/usr/local/nginx/logs/error. log" file.

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.