Build LNMP Environment under Linux

Source: Internet
Author: User
Tags fpm gz file install php openssl library

premise: Assume that readers who read this article already have basic Linux usage skills to solve system installation problems and software installation techniques.

Note: This article involves the main installation package (need to download the use of) installation package, at the end of this article will give the Baidu cloud disk link, need to use, you can freely download.

Recommendation: It is recommended to read this article first, understand the relationship between Nginx components before installing, so that the chest has the overall situation, and then further operation.

The machine configuration where the installation is located:

    • Linux kernel version: 2.6.32
    • Linux distributions: CentOS 6.4 64-bit
    • System memory: 1G.
    • 2G is recommended for virtual machines. Compiling will be quick.

Baidu Cloud Disk: Link: http://pan.baidu.com/s/1o8SyQ2e Password: I6HK

0. Add users required to run the software
groupadd nginxuseradd -g nginx nginxgroupadd mysqluseradd -g mysql mysql
1. Install GCC and C + + compilers.
yum -y install gcc gcc-c++
2. Understanding Dependency Relationships

Nginx requires support from third-party libraries:

Gzip is used to compress Web pages. gzip requires zlib library.

Rewrite is used to implement Web page redirection functionality. Rewrite requires pcre (Perl Compatible Regular Expression) library.

SSL is an encrypted library. If the HTTPS.SSL function requires the OpenSSL library

3, solve the nginx dependency relationship
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

So now that you have installed the zlib OpenSSL Pcere package, why do you want to install the Zlib-devel package?

Devel package is mainly for development use, the package contains at least the following 2 things.

1. header file

2. Link library

Take Zlib and Zlib-devel as an example.
If you are installing a program that is based on zlib development, you only need to install zlib.
If you want to change the source code of glib, you need to use Glib-devel.
In this article we have to install zlib, because we are not sure that there is no such library in our machine, so we will install the zlib-devel.
Since Yum will automatically resolve dependencies, it should install itself even if the-devel is not installed. As an understanding principle, it is recommended that you install it manually.

4. Installing Nginx
mkdir -p  /usr/local/webserver/source cd /usr/local/webserver/source

Download the nginx-1.8.0.tar.gz file from Baidu Cloud disk after the article.

tar -xf nginx-1.8.0.tar.gz                                      //解压文件cd nginx-1.8.0./configure --help                                              //查看编译

Options

4.1 Configuring Nginx
4.2 Installing Nginx
make && make install/usr/local/webserver/nginx/sbin/nginx -V                          //查看nginx的版本信息/usr/local/webserver/nginx/sbin/nginx -h                          //查看nginx的帮助信息/usr/local/webserver/nginx/sbin/nginx                             //启动nginx打开浏览器,输入linux的ip。可以看到欢迎的信息。/usr/local/webserver/nginx/sbin/nginx    -s stop                    //关闭nginx/usr/local/webserver/nginx/sbin/nginx                               //重新启动,以便后续操作。  
5. Install MySQL

5.1. Resolve MySQL installation dependencies

CMake is used to compile MySQL, so download cmake first.

Ncurses and Ncurses-devel are MySQL's character terminal processing libraries.

yum -y install cmake ncurses ncurses-devel
5.2. Install MySQL

Download the mysql-5.6.24.tar.gz file from the back of the network disk to/usr/local/webserver/source

tar -xf mysql-5.6.24.tar.gz                                     // 解压mysqlcd /usr/local/webserver/source/mysql-5.6.24查看编译选项:http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html。
5.3. Compile the configuration MySQL:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql -DMYSQL_DATADIR=/usr/local/webserver/mysql/data -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

The following is an explanation of the compilation options

  cmake-dcmake_install_prefix=/usr/local/webserver/mysql \//mysql Installation path-dmysql_datadir=/usr/local/we Bserver/mysql/data \//mysql Table data store path-dwith_myisam_storage_engine=1 \//load MYISAM storage engine 。 Note: The MySQL storage engine is plug-in. Needs to be loaded on demand. -dwith_innobase_storage_engine=1 \//Mount InnoDB storage engine. -dwith_memory_storage_engine=1 \//load MEMORY engine, the engine is not commonly used. -dwith_readline=1 \//Do not know what this means. -dmysql_unix_addr=/var/lib/mysql/mysql.sock \//mysql's sock file path.                                   -dmysql_tcp_port=3306 \//mysql's listening port, default 3306.-denabled_local_infile=1 \ -dwith_partition_storage_engine=1-dextra_charsets=all \-ddefa ULT_CHARSET=UTF8 \//default character set for utf8-ddefault_collation=utf8_general_ci execution: Make &&am P Make install  

I use a single-core server here for a full 20 minutes, and the virtual machine may take more than 30 minutes. Wait patiently, do not perform other operations, at which time the CPU is at 99% full state.

5, 4 Create a mysql-brought database
/usr/local/webserver/mysql/scripts                  ./scripts/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/usr/local/webserver/mysql/data --user=mysql
5, 5 start MySQL

Set boot up:

/usr/local/webserver/mysql/support-filescp ./mysql.server /etc/init.d/mysql            //复制到系统自启动目录。chkconfig mysql on                             //设置开机启动service mysql start                            //启动MySQLPATH=/usr/local/webserver/mysql/bin/:$PATH     //将mysql命令设置到全局命令路径中export PATH                                    //将PATH设置为全局变量source /etc/profile                            //重新载入系统配置5.6 测试mysqlmysql -u root                                   set password = password('密码')                  //设置密码exit                                           //退出

After that the test will not speak.

6. Install PHP

6.1, to solve the environmental dependence

yum -y install libxml2 libxml2-develyum -y install libcurl libcurl-devel
6.2. Install PHP

Download the php-5.6.24.tar.gz file from the network disk shown below to/usr/local/webserver/source

cd /usr/local/webserver/sourcetar -xf php-5.6.24.tar.gzcd /usr/local/webserver/source/php-5.6.24./configure --help                          //查看下配置项

The configuration entries are as follows:

./configure --prefix=/usr/local/webserver/php --enable-fpm --with-config-file-path=/usr/local/webserver/php/conf --with-zlib --with-curl --enable-mysqlnd --enable-pdo --enable-mbstring --with-mysql=/usr/local/webserver/mysql --with-pdo-mysql=mysqlnd --with-openssl-dir --disable-fileinfomake && make install
6.3. Configure PHP
cd /usr/local/webserver/phpmkdir conf/usr/local/webserver/source/php-5.6.24/php.ini-development ./conf/php.ini    //复制配置cd /usr/local/webserver/php/etcmv php-fpm.conf.default  php-fpm.confls /usr/local/webserver/source/php-5.6.24/sapi/fpm/php-fpm /usr/local/bin/      php-fpm -h  //查看php的配置信息php-fpm -m  //查看加载了那些模块                                  
7. Associated PHP and Nginx

Modify the Nginx configuration so that it supports the PHP suffix file.

Approximately 52 lines of 65 rows.

location / {    root   html;    index  index.php index.html index.htm;}location ~* \.php$ {    fastcgi_index   index.php;    fastcgi_pass    127.0.0.1:9000;    include         fastcgi_params;    fastcgi_param   SCRIPT_FILENAME              $document_root$fastcgi_script_name;    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;}

Modify the PHP configuration and modify the time options.

//约925行date.timezone = Asia/Shanghai       //你不在上海也填上海。这个指的是时区。
8, put the execution command into the/usr/local/bin. Become a shortcut command
ln -s /usr/local/webserver/nginx/sbin/nginx /usr/local/bin/   ln -s /usr/local/webserver/php/sbin/php-fpm /usr/local/bin/cd /执行 nginx执行 php-fpmcd  /usr/local/webserver/nginx/html/mv index.html index.php写一个phpinfo(); 的函数。去浏览器看下效果。
9. Remark:

Above, has been nginx, PHP, MySQL three together. If you have already followed the instructions above to install the success, then congratulations, you are very lucky. Practice process, you may encounter a variety of error, be sure to read the wrong information in detail, according to the information to install the corresponding components. Each person's machine is different, may error the category also not the same, encountered the error the welcome everybody to the comment area questions, the joint discussion, the common enhancement.

The purpose of this article is to let you understand the Nginx, PHP, MySQL, the combination of the relationship between the three. This article does not install the GD library, Reids and Memcache libraries. This is left in the follow-up article gradually to speak. How to get PHP to compile the unused components in a patch (phpize) way.

Build LNMP Environment under Linux

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.