centos6.7, centos6.5 under the Yum Way to build LNMP environment, php5.4/mysql5.5

Source: Internet
Author: User
Tags fpm install php openssl php script iptables

Because of the computer reinstall system, all the systems in the previous virtual machine could not be opened, and had to start installing from 0. I downloaded the image of centos6.5, after the installation of the virtual machine, after the implementation of Yum update, the system rose to 6.7, but for the installation of LNMP environment has no impact, 6.5 and 6.7 installation method is the same.

First, install the php5.4

1. Configure the Yum source

The default is no php5.4 version in 6.7 and 6.5, so we need to configure the Yum source first.

Execute command: RPM-UVH http://mirror.webtatic.com/yum/el6/latest.rpm

[Email protected] yum.repos.d]# RPM-UVH http://mirror.webtatic.com/yum/el6/latest.rpmRetrieving/http/ Mirror.webtatic.com/yum/el6/latest.rpmwarning:/var/tmp/rpm-tmp.qxpwk1:header V4 DSA/SHA1 Signature, key ID cf4c4ff9:                nokeypreparing ... ########################################### [100%]   1:webtatic-release       ################################# ########## [100%]

2. Installing php5.4

After performing the search for Yum search php54w, you can see the php5.4 related modules. To perform a command installation php5.4

[email protected] ~]# Yum install php54w

After installation, execute command to see PHP version information

[Email protected] ~]# php--versionphp 5.4.45 (CLI) (Built:oct 11:24:58) Copyright (c) 1997-2014 the PHP groupze nd Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
3. Installing PHP-FPM

[[email protected] ~]# yum install php-fpm.x86_64loaded plugins:fastestmirror, Refresh-packagekit, Securitysetting up Install processloading mirror speeds from cached Hostfilef * base:mirrors.btte.net * extras:mirrors.b Tte.net * updates:mirror.bit.edu.cn * webtatic:sp.repo.webtatic.comResolving dependencies--> Running Transaction Check---> Package php-fpm.x86_64 0:5.3.3-46.el6_7.1 'll be installed--> processing Dependency:php-common (x86-64 ) = 5.3.3-46.el6_7.1 for package:php-fpm-5.3.3-46.el6_7.1.x86_64--> Running transaction Check---> Package Php-common.x86_64 0:5.3.3-46.el6_7.1 'll be installed--> processing conflict:php54w-common-5.4.45-2.w6.x86_64 Conflicts Php-common < 5.4.0--> finished Dependency Resolutionerror:php54w-common conflicts with  Php-common-5.3.3-46.el6_7.1.x86_64 could try using--skip-broken to work around the problem you could try Running:rpm -va--nofiles--nodigest
You can see that the third line of the countdown reported a conflict, causing the installation to fail, The reason for the conflict is that the PHP-FPM package relies on the 5.3 version of Php-common, but when we install the php5.4, the 5.4 version of Php-common is installed, so the php-common-5.3 is not installed and the conflict is resolved as long as the php-common-5.4-dependent version of P is installed HP-FPM is OK.

[[email protected] ~]# Yum Search php54w | grep fpmphp54w-fpm.x86_64:php FastCGI Process manager[[email protected] ~]# yum install php54w-fpm.x86_64loaded Pl Ugins:fastestmirror, Refresh-packagekit, securitysetting up Install processloading mirror speeds from cached Hostfile * b Ase:mirrors.btte.net * extras:mirrors.btte.net * updates:mirror.bit.edu.cn * webtatic:sp.repo.webtatic.comResolving D ependencies--> Running Transaction Check---> Package php54w-fpm.x86_64 0:5.4.45-2.w6 would be installed--> Finished Dependency resolutiondependencies resolved==============================================================                             ====================================================================================== Package Arch Version Repository size=========== =============================================================================================================== ==========================INSTALLING:PHP54W-FPM x86_64 5.4.45-2.W6 Webtatic 1.3 mtransaction summary============================================== ======================================================================================================install 1 Package (s) total download size:1.3 minstalled size:3.8 MIs This ok [y/n]: ydownloading packages:php54w-fpm-5.4.45-2.w6.x8 6_64.rpm | 1.3 MB 00:13 Running rpm_check_debugrunning Transaction testtransaction Test succeededrunning Transaction Install                                                                                                    Ing:php54w-fpm-5.4.45-2.w6.x86_64                                                                                                    1/1 verifying:php54w-fpm-5.4.45-2.w6.x86_64 1/1 InstaLled:php54w-fpm.x86_64 0:5.4.45-2.W6 complete!

Test PHP-FPM service is normal

[[Email protected] ~]# service php-fpm startstarting php-fpm:                                          [  OK  ]
Everything goes well! Now that the PHP environment is installed, then install Nginx

Two. Installing Nginx
Let's see what versions of Nginx we have.

[email protected] ~]# Yum search nginxloaded plugins:fastestmirror, refresh-packagekit, securityloading Mirror speeds fr Om Cached Hostfile * base:mirrors.btte.net * extras:mirrors.btte.net * updates:mirror.bit.edu.cn * webtatic:uk.repo.we btatic.com================================================================ N/S Matched:nginx ==================== ============================================NGINX16.X86_64:A High Performance Web server and reverse proxy SERVERNGINX18.X86_64:A High Performance Web server and reverse proxy server  Name and summary matches only, use "sear CH all "for everything.
We chose to install version 18.

The download speed was very slow and the installation failed, so let's replace the Yum source first.

RPM-IVH http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

Perform the installation after the replacement is complete. This time the download speed is much faster, the installation is also very smooth. After all installation, open Nginx Service

[[Email protected] yum.repos.d]# service Nginx startstarting nginx:                                            [  OK  ]
Turn off Firewall service

[Email protected] yum.repos.d]# service iptables stopiptables:setting chains to policy Accept:filter          [  OK  ]iptables:flushing firewall rules:                         [  OK  ]iptables:unloading modules:                               [  OK  ]
Enter the IP of the virtual machine in the browser, indicating that Nginx has been successfully installed when viewed.

Three. Modify the Nginx configuration so that it can recognize the PHP script

After the default installation of Nginx, there is no way to parse the PHP script, you need to modify the Nginx configuration file.

[Email protected] html]# vim/etc/nginx/nginx.conf
1. Add index.php


2. Open the FastCGI section Note (FastCGI, Nginx, PHP-FPM, PHP What are the relationships?) This will be explained in more detail later in this article)


Change/scripts to $document_root

Save exit and restart Nginx service.

Enter/usr/share/nginx/html to write a PHP script and then test to see if it can be opened

[Email protected] html]# vim index.php
<?phpphpinfo ();
Save exit, access the file in the browser, 192.168.71.128/index.php (my virtual machine IP is 71.128), if you see the PHP information page indicates that the configuration was successful. The next step is to configure MySQL.

Four. Install MySQL

Install all packages related to mysql5.5

[[email protected] ~]# yum install mysql55*loaded plugins:fastestmirror, Refresh-packagekit, securitySetting up Install processloading mirror speeds from cached Hostfile * base:mirrors.btte.net * extras:mirrors.btte.net * updates:m irror.bit.edu.cn * webtatic:sp.repo.webtatic.comResolving dependencies--> Running Transaction Check---> Package Mysql55w.x86_64 0:5.5.49-1.w6 'll be installed---> Package mysql55w-bench.x86_64 0:5.5.49-1.w6 'll be installed--& Gt Processing Dependency:perl (GD) for package:mysql55w-bench-5.5.49-1.w6.x86_64--> processing Dependency:perl (DBI) For package:mysql55w-bench-5.5.49-1.w6.x86_64---> mysql55w-devel.x86_64 0:5.5.49-1.w6 would be installed-- > Processing dependency:openssl-devel for package:mysql55w-devel-5.5.49-1.w6.x86_64---> Package Mysql55w-embedded.x86_64 0:5.5.49-1.w6 'll be installed---> Package mysql55w-embedded-devel.x86_64 0:5.5.49-1.w6 'll be installed---> Package mysql55w-libs.x86_64 0:5.5.49-1.w6 'll be installed--> processing dependency:libmysqlclient16 for package:mysql55w-libs-5.5.49-1.w6.x86_64---& Gt Package mysql55w-server.x86_64 0:5.5.49-1.w6 'll be installed--> processing dependency:perl-dbd-mysql for package:m YSQL55W-SERVER-5.5.49-1.W6.X86_64---> Package mysql55w-test.x86_64 0:5.5.49-1.w6 'll be installed--> Processing Dependency:perl (time::hires) for package:mysql55w-test-5.5.49-1.w6.x86_64--> Running transaction Check---> Package libmysqlclient16.x86_64 0:5.1.69-1.w6 'll be installed---> Package openssl-devel.x86_64 0:1.0.1e-42.el6_7.4 'll be installed--> processing dependency:zlib-devel for package:openssl-devel-1.0.1e-42.el6_ 7.4.x86_64--> processing dependency:krb5-devel for package:openssl-devel-1.0.1e-42.el6_7.4.x86_64---> Package Perl-dbd-mysql.x86_64 0:4.013-3.el6 'll be installed---> Package perl-dbi.x86_64 0:1.609-4.el6 'll be installed---& Gt Package perl-gd.x86_64 0:2.44-3.el6 'll be installed--->Package perl-time-hires.x86_64 4:1.9721-141.el6_7.1 'll be installed--> Running transaction Check---> Package Krb5-devel.x86_64 0:1.10.3-42z1.el6_7 'll be installed--> processing dependency:libselinux-devel for package: Krb5-devel-1.10.3-42z1.el6_7.x86_64--> processing dependency:libcom_err-devel for package: Krb5-devel-1.10.3-42z1.el6_7.x86_64--> processing dependency:keyutils-libs-devel for package: KRB5-DEVEL-1.10.3-42Z1.EL6_7.X86_64---> Package zlib-devel.x86_64 0:1.2.3-29.el6 'll be installed--> Running Transaction Check---> Package keyutils-libs-devel.x86_64 0:1.4-5.el6 'll be a installed---> Package libcom_ Err-devel.x86_64 0:1.41.12-22.el6 'll be installed---> Package libselinux-devel.x86_64 0:2.0.94-5.8.el6 'll be installed--> processing Dependency:libsepol-devel >= 2.0.32-1 for package:libselinux-devel-2.0.94-5.8.el6.x86_ 64--> processing Dependency:pkgconfig (Libsepol) for package:libselinux-devel-2.0.94-5.8.el6.x86_64--> RunNing Transaction Check---> Package libsepol-devel.x86_64 0:2.0.41-4.el6 'll be installed--> processing conflict:m ysql55w-libs-5.5.49-1.w6.x86_64 conflicts Mysql-libs < 5.5--> finished Dependency resolutionerror:mysql55w-libs Conflicts with mysql-libs-5.1.73-5.el6_7.1.x86_64-could try using--skip-broken to work around the problem you could t Ry Running:rpm-va--nofiles--nodigest
The third line, there is another conflict, now we unload the mysql-libs-5.1.73-5.el6_7.1.x86_64

[email protected] ~]# Yum Remove mysql-libs-5.1.73-5.el6_7.1.x86_64
After the uninstallation succeeds, execute the installation command again

[email protected] ~]# Yum install mysql55*
After installation, turn on the MySQL service to see if it is normal

[[Email protected] ~]# service mysqld start
After successful startup, we need to assign a login password to the root user of MySQL

[Email protected] ~]# mysqladmin-u root password ' newpassword '
Once setup is complete, you can log in to the MySQL console.

[Email protected] ~]# mysql-u root-penter password:welcome to the MySQL monitor.  
Login no problem, now MySQL is installed, the next thing to do is to allow PHP to connect to MySQL

V. Installation of PHP-MYSQL extensions

1. Install the extension

See if you have an php-mysql extension installed

[Email protected] ~]# Php-i | grep MySQL
The command result is empty and the description is not installed, so now we need to install these extensions. Search for Yum sources to find the right expansion pack

[email protected] ~]# Yum Search all php-mysqlloaded plugins:fastestmirror, Refresh-packagekit, securityloading Mirror S Peeds from Cached Hostfile * base:mirrors.btte.net * extras:mirrors.btte.net * updates:mirror.bit.edu.cn * webtatic:us -east.repo.webtatic.com================================================================ Matched:php-mysql ====== ==========================================================PHP-MYSQL.X86_64:A Module for PHP applications this use MySQL databasesphp54w-mysqlnd.x86_64:a module for PHP applications This use MySQL databasesphp55w-mysqlnd.x86_64:a mod Ule for PHP applications This use MySQL DATABASESPHP56W-MYSQLND.X86_64:A module for PHP applications this use MySQL data BASESPHP70W-MYSQLND.X86_64:A Module for PHP applications this use MySQL databases
Install PHP54W-MYSQLND, because we PHP is php5.4 version of the

[email protected] ~]# Yum install-y php54w-mysqlnd.x86_64
After the installation, restart PHP-FPM, browse 192.168.71.128/index.php again to see the MySQL extension.

Let's write a simple script to test the PHP connection to MySQL.

2. Test the extension
First, log in to the MySQL console, create a table in test, and write a few pieces of data

mysql> CREATE TABLE person (    with ID int not NULL PRIMARY key auto_increment,    name char (5) is not null    - >) engine=innodb default Charset=utf8;
Mysql> INSERT into the person (name) values (' Zhangsan '), (' Lisi '), (' Wangwu ');
When the test table is ready, start writing the test script.

[Email protected] ~]# cd/usr/share/nginx/html/[[email protected] html]# vim mysql.php
<?phptry{        $pdo = new PDO (' Mysql:host=localhost;dbname=test ', ' root ', ' root ');        $res = $pdo->query (' select * from person ');        foreach ($res as $row) {                echo ' <pre> ';p rint_r ($row)        }} catch (Pdoexception $e) {        print "Error:". $e-& Gt;getmessage (). " <br/> ";        Die;}
Access Script 192.168.71.128/mysql.php, if you see the following, the php-mysql extension has no problem.

Vi. adding LNMP to boot entry
Through the above five operations, our LNMP environment has been successfully built, for the subsequent use, we now add php-fpm/nginx/mysql to the boot entry.

[[email protected] html]# chkconfig php-fpm on[[email protected] html]# chkconfig nginx on[[email protected] html]# Chkcon Fig mysqld on


Note: If you restart the machine and found that nginx can not access, please check if the firewall is open, because the CentOS default firewall is on boot.



at this point, LNMP environment is completely completed, enjoy the coding bar ~















centos6.7, centos6.5 under the Yum Way to build LNMP environment, php5.4/mysql5.5

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.