LNMP環境搭建,nginx+linux+mysql+php


 

LNMP環境搭建php

 

 

目錄html

1 環境準備... 1mysql

1.1 克隆虛擬機... 1nginx

1.2 配置IP1web

1.3 準備安裝軟件包... 1sql

2 安裝Nginx1shell

1)更改hostname、建立所需軟件存放目錄...1數據庫

2)下載或上傳安裝所須要的軟件...1vim

3)解壓安裝nginx.1centos

4) 關閉防火牆... 1

5) 編輯nginx.conf1

6)建立web服務對應的目錄...1

7)修改本地host文件 解析設置的IP地址(注意點)...1

8)編輯nginx.conf1

3 安裝Mysql1

1)解壓編譯cmake軟件...1

2)安裝相關依賴包...1

3)建立mysql用戶及用戶組...1

4)解壓編譯mysql1

5)建立連接以及設置mysql的環境變量...1

6)建立mysql啓動配置文件...1

7)進行mysql初始化(兩個OK)...1

8) mysql的基本相關設置... 1

9) MySQL基礎管理操做命令... 1

4 安裝PHP1

5 LNMP整合配置實踐操做... 1

1) 編輯nginx.conf1

2) 檢查nginx配置文件,平滑重啓... 1

3) 編輯index.php文件,看是否能夠解析... 1

4)編輯index.php/mysql.php文件...1


 

 

 

1 環境準備

 

 

1.1 克隆虛擬機

 

         參考LAMP環境搭建;

 

1.2 配置IP

 

         192.168.1.67

 

 

1.3 準備安裝軟件包

 

         libiconv-1.14.tar.gz

         libmcrypt-2.5.8.tar.gz

         mcrypt-2.6.8.tar.gz

         mhash-0.9.9.9.tar.gz

         nginx-1.6.2

         nginx-1.6.2.tar.gz

         php-5.3.27.tar.gz

 

 

2 安裝Nginx

 

 

1)更改hostname、建立所需軟件存放目錄

 

[root@moban ~]# hostname lnmp

[root@moban ~]# logout

[root@lnmp ~]# mkdir /home/oldboy/tools -p

 

 

 

2)下載或上傳安裝所須要的軟件

 

[root@lnmp~]# cd /home/oldboy/tools/

-rw-r--r--. 1 root root   804164 Jun 9 03:30 nginx-1.6.2.tar.gz

-rw-r--r--. 1 root root 15008639 Jun  9 04:16 php-5.3.27.tar.gz

[root@lnmptools]# yum install pcre pcre-devel -y

[root@lnmptools]# yum install openssl openssl-devel -y

[root@lnmp tools]# rpm -qa pcre* open*

openssh-clients-5.3p1-84.1.el6.x86_64

openldap-2.4.23-31.el6.x86_64

openssl098e-0.9.8e-17.el6.centos.2.x86_64

pcre-7.8-6.el6.x86_64

openssh-5.3p1-84.1.el6.x86_64

pcre-devel-7.8-6.el6.x86_64

openssl-devel-1.0.1e-30.el6.11.x86_64

openssh-server-5.3p1-84.1.el6.x86_64

openssl-1.0.1e-30.el6.11.x86_64

 

 

 

3)解壓安裝nginx

 

[root@lnmp tools]# tar xfnginx-1.6.2.tar.gz

[root@lnmp tools]# cdnginx-1.6.2

##建立用戶nginx而且進行編譯安裝

[root@lnmp nginx-1.6.2]#useradd nginx -s /sbin/nologin -M

[root@lnmp nginx-1.6.2]# idnginx

uid=500(nginx) gid=500(nginx) groups=500(nginx)

[root@lnmp nginx-1.6.2]#./configure --user=nginx --group=nginx --prefix=/application/nginx1.6.2--with-http_stub_status_module --with-http_ssl_module

[root@lnmp nginx-1.6.2]# make&& make install

[root@lnmp nginx-1.6.2]# echo$?

0

##建立連接

[root@lnmp nginx-1.6.2]# ln  -s /application/nginx1.6.2/ /application/nginx

[root@lnmp nginx-1.6.2]# ll /application/nginx

[root@lnmp nginx-1.6.2]# ll /application/nginx/

##檢查語法而且啓動服務:

[root@lnmp nginx-1.6.2]#/application/nginx/sbin/nginx -t

[root@lnmp nginx-1.6.2]#/application/nginx/sbin/nginx

[root@lnmp nginx-1.6.2]#netstat -lntup|grep nginx

tcp       0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4796/nginx         

[root@lnmp nginx-1.6.2]# ps-ef | grep nginx

root       4796     1  0 15:43 ?        00:00:00 nginx: master process/application/nginx/sbin/nginx

nginx     4797   4796  0 15:43 ?        00:00:00 nginx: worker process       

root      4801   2447  0 15:43 pts/0    00:00:00 grep nginx

 

4) 關閉防火牆

 

[root@lnmp nginx-1.6.2]# service iptables stop

[root@lnmp nginx-1.6.2]# setenforce 0

[root@lnmp nginx-1.6.2]# getenforce 0

 

 

 

 

5) 編輯nginx.conf

 

[root@lnmp nginx-1.6.2]# cd  /application/nginx/conf/

[root@lnmp conf]# cpnginx.conf nginx.conf.bak

[root@lnmp conf]# egrep -v"#|^$" nginx.conf.default >nginx.conf

[root@lnmp conf]# vi nginx.conf

worker_processes 2;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

 

######################################################___1

    server {

       listen       80;

       server_name  www.etiantian.org;

       root     /data/html/www;

       index    index.html index.htm;

    }

######################################################___2

    server {

       listen       80;

       server_name  blog.etiantian.org;

       root     /data/html/blog;

       index    index.html index.htm;

    }

######################################################___3

    server {

       listen       80;

       server_name  bbs.etiantian.org;

       root     /data/html/bbs;

       index    index.html index.htm;

    }

}

 

 

6)建立web服務對應的目錄

 

[root@lnmp conf]# mkdir/data/html/{www,blog,bbs,wiki} -p

[root@lnmp conf]# touch/data/html/{www,blog,bbs,wiki}/index.html

[root@lnmp conf]# for name in www blog bbs wiki;doecho "http://$name.etiantian.org">/data/html/$name/index.html;done

[root@lnmp conf]# for name in www blog bbs wiki;docat /data/html/$name/index.html;done

http://www.etiantian.org

http://blog.etiantian.org

http://bbs.etiantian.org

http://wiki.etiantian.org

[root@lnmp conf]# ../sbin/nginx -t

[root@lnmp conf]# ps -ef |grep nginx

root      4796      1  0 15:43 ?        00:00:00 nginx: master process/application/nginx/sbin/nginx

nginx     4797   4796  0 15:43 ?        00:00:00 nginx: worker process       

root      4925   2447  0 16:28 pts/0    00:00:00 grep nginx

[root@lnmp conf]# ../sbin/nginx -s reload

 

7)修改本地host文件 解析設置的IP地址(注意點)

        

         192.168.1.67  www.etiantian.org blog.etiantian.org bbs.etiantian.org etiantian.org  status.etiantian.org

 

 

 

8)編輯nginx.conf

 

[root@lnmp conf]# vi nginx.conf

worker_processes 2;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type application/octet-stream;

   sendfile        on;

   keepalive_timeout  65;

 

    server {

       listen       80;

       server_name  www.etiantian.org;

       root     /data/html/www;

       index    index.html index.htm;

    }

 

    server {

       listen       80;

       server_name  blog.etiantian.org;

       root     /data/html/blog;

       index    index.html index.htm;

    }

 

    server {

       listen       80;

       server_name  bbs.etiantian.org;

       root     /data/html/bbs;

       index    index.html index.htm;

    }

 

    ##status

    server {

        listen       80;

       server_name  status.etiantian.org;

       stub_status on;

       access_log  off;

    }

}

 

檢查並重啓nginx

 

[root@lnmp conf]# ../sbin/nginx -t

[root@lnmp conf]# ../sbin/nginx -s reload

 

 

 

 

 

 

 

 

 

 

 

 

 

3 安裝Mysql

 

1)解壓編譯cmake軟件

 

[root@lnmp tools]# tar xf cmake-2.8.8.tar.gz

cd cmake-2.8.8

./configure

gmake

gmake install

 

 

2)安裝相關依賴包

 

[root@lnmp cmake-2.8.8]# cd ../

[root@lnmp tools]# yum install ncurses-devel -y

[root@lnmp tools]# yum install libaio-devel -y

 

3)建立mysql用戶及用戶組

 

[root@lnmp tools]# groupadd MySQL

[root@lnmp tools]# useradd mysql -s /sbin/nologin-M -g mysql

 

4)解壓編譯mysql

 

[root@lnmp tools]# tar xf mysql-5.5.32.tar.gz

[root@lnmp tools]# cd mysql-5.5.32

[root@lnmp mysql-5.5.32]# cmake  -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \

-DMYSQL_DATADIR=/application/mysql-5.5.32/data \

-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock\

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \

-DWITH_FAST_MUTEXES=1 \

-DWITH_ZLIB=bundled \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_DEBUG=0 \

[root@lnmp mysql-5.5.32]# make && make install

 

 

5)建立連接以及設置mysql的環境變量

 

[root@lnmp mysql-5.5.32]# ln  -s/application/mysql-5.5.32  /application/mysql

[root@lnmp mysql-5.5.32]# ll /application/mysql/

[root@lnmp mysql-5.5.32]# echo 'export  PATH=/application/mysql/bin:$PATH' >>/etc/profile

[root@lnmp mysql-5.5.32]# tail -1 /etc/profile

export PATH=/application/mysql/bin:$PATH

[root@lnmp mysql-5.5.32]# source /etc/profile

[root@lnmp mysql-5.5.32]# echo $PATH

/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@lnmp mysql-5.5.32]#

 

 

6)建立mysql啓動配置文件

 

[root@lnmp mysql-5.5.32]# cpsupport-files/my-small.cnf /etc/my.cnf

[root@lnmp mysql-5.5.32]# chown -R mysql.mysql/application/mysql/data

[root@lnmp mysql-5.5.32]# chmod -R 1777 /tmp/

 

7)進行mysql初始化(兩個OK)

 

[root@lnmp mysql-5.5.32]# cd /application/mysql/scripts/

[root@lnmp scripts]# ./mysql_install_db  --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

 

 

8) mysql的基本相關設置

 

[root@lnmp scripts]# cd ../

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

[root@lnmp mysql]# chmod +x   /etc/init.d/mysqld

[root@lnmp mysql]#/etc/init.d/mysqld start

Starting MySQL... SUCCESS!

[root@lnmp mysql]# mysqladmin-uroot password '888888'

[root@lnmp mysql]# mysql-uroot -p888888

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.5.32 Source distribution

 

Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarks of theirrespective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

 

mysql> GRANT ALLPRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

mysql> FLUSH PRIVILEGES;

 

mysql> quit

Bye

 

 

 

9) MySQL基礎管理操做命令

 

①單實例數據庫mysql的啓動命令:/etc/init.d/mysqld start

②檢查端口:ss -lntup|grep 330或者使用netstat -lntup|grep 330.

③檢查進程:ps -ef|grep mysql|grep -v grep  兩個主要的進程,一個就是mysql_safe一個是mysqld

mysql啓動的基本原理:/etc/init.d/mysqld start是一個shell的啓動腳本,啓動後會最終調用mysqld_safe腳本,最後調用mysqld服務器啓動mysql。文件vim /application/mysql/support-files/mysql.server 中的$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &

⑤初始化時候啓動方法:mysql_safe --user=mysql &,當找回root密碼的時候用此方法啓動,和/etc/init.d/mysqld 的啓動實質是同樣的。

⑥經常使用關閉mysql命令:/etc/init.d/mysqld stop 而後查看端口是否關閉。

mysql關閉的原理:在腳本文件/etc/init.d/mysqld文件中內容有兩個地方須要注意:if (kill -0 $mysqld_pid 2>/dev/null)還有一個地方就是kill $mysqld_pid

⑧強制關閉數據庫方法:

killall mysqld

pkill mysqld

killall -9 mysqld

⑨優雅關閉數據庫方法:

第一種:mysqladmin方法:mysqladmin -uroot -p123456 shutdown

##${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown

第二種:自帶腳本方法:/etc/init.d/mysqld stop

第三種:kill 信號方法:kill -USR2 cat path/pid’(最好不要使用)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4 安裝PHP

 

 

1)上傳所須要安裝的軟件及插件

 

[root@lnmp conf]# cd /home/oldboy/tools/

[root@lnmp tools]# ll

total 23000

-rw-r--r--. 1 root root  4984397 Jun 9 04:16 libiconv-1.14.tar.gz

-rw-r--r--. 1 root root  1335178 Jun 9 04:16 libmcrypt-2.5.8.tar.gz

-rw-r--r--. 1 root root   471915 Jun 9 04:16 mcrypt-2.6.8.tar.gz

-rw-r--r--. 1 root root   931437 Jun 9 04:16 mhash-0.9.9.9.tar.gz

drwxr-xr-x. 9 1001 1001     4096 Jun 17 15:41 nginx-1.6.2

-rw-r--r--. 1 root root   804164 Jun 9 03:30 nginx-1.6.2.tar.gz

-rw-r--r--. 1 root root 15008639 Jun  9 04:16 php-5.3.27.tar.gz

[root@lnmp tools]#

 

 

 

2)安裝PHP依賴的插件

 

[root@lnmp tools]# yuminstall -y libxslt-devel

[root@lnmp php-5.3.27]# yuminstall zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devellibxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y

[root@lnmp tools]# rpm -qazlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devellibjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

 

 

[root@lnmp tools]# tar zxflibiconv-1.14.tar.gz

[root@lnmp tools]# cd libiconv-1.14

[root@lnmp libiconv-1.14]# ./configure --prefix=/usr/local/libiconv

make

make install

[root@lnmp libiconv-1.14]# cd ../

 

[root@lnmp tools]# tar zxflibmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

sleep 2

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

cd ../../

 

[root@lnmp tools]# tar zxfmhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

sleep 2

cd ../

 

rm -f /usr/lib64/libmcrypt.*

rm -f /usr/lib64/libmhash*

ln -s /usr/local/lib64/libmcrypt.la/usr/lib64/libmcrypt.la

ln -s /usr/local/lib64/libmcrypt.so/usr/lib64/libmcrypt.so

ln -s /usr/local/lib64/libmcrypt.so.4/usr/lib64/libmcrypt.so.4

ln -s /usr/local/lib64/libmcrypt.so.4.4.8/usr/lib64/libmcrypt.so.4.4.8

ln -s /usr/local/lib64/libmhash.a/usr/lib64/libmhash.a

ln -s /usr/local/lib64/libmhash.la/usr/lib64/libmhash.la

ln -s /usr/local/lib64/libmhash.so/usr/lib64/libmhash.so

ln -s /usr/local/lib64/libmhash.so.2/usr/lib64/libmhash.so.2

ln -s /usr/local/lib64/libmhash.so.2.0.1/usr/lib64/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config/usr/bin/libmcrypt-config

 

 

[root@lnmp tools]# tar zxfmcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure LD_LIBRARY_PATH=/usr/local/lib

make

make install

cd ../

sleep 2

 

 

 

 

 

3)安裝PHP軟件

 

[root@lnmp tools]# yuminstall openssl-devel -y

[root@lnmp tools]# tar xfphp-5.3.27.tar.gz

[root@lnmp tools]# cd php-5.3.27

[root@lnmp php-5.3.27]# ./configure \

--prefix=/application/php5.3.27 \

--with-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-curl \

--enable-short-tags \

--enable-zend-multibyte \

--with-gd \

--with-xmlrpc \

--with-openssl \

--enable-soap \

--enable-sockets \

--with-xsl \

--enable-mbstring \

--enable-gd-native-ttf \

--with-libxml-dir=/usr \

--enable-static \

--enable-xml \

--disable-rpath \

--enable-safe-mode \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curlwrappers \

--enable-mbregex \

--enable-fpm \

--with-mcrypt \

--with-mhash \

--enable-pcntl \

--enable-zip \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-ftp

 

 

###出現如下界面表示編譯完成

 

+--------------------------------------------------------------------+

| License:                                                          |

| This software is subject to the PHPLicense, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms ofthis license agreement.     |

| If you do not agree with the terms ofthis license, you must abort |

| the installation process at thispoint.                            |

+--------------------------------------------------------------------+

 

Thank you for using PHP.

 

[root@lnmp php-5.3.27]# ln -s/application/mysql/lib/libmysqlclient.so.18 /usr/lib64/

[root@lnmp php-5.3.27]# make&& make install

[root@lnmp php-5.3.27]# ln -s/application/php5.3.27/ /application/php

 

 

 

4) 拷貝php配置文件

 

[root@lnmp bbs]# cd /home/oldboy/tools/php-5.3.27

[root@lnmp php-5.3.27]# cp php.ini-production/application/php/etc/php.ini

 

 

 

5) 拷貝php啓動腳本,php-fpm配置文件,更改php-fpm權限爲755;添加php-fpm開機啓動;

 

[root@lnmp etc]# cd /home/oldboy/tools/php-5.3.27

[root@lnmp php-5.3.27]# cp sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm

[root@lnmp php-5.3.27]# mv/application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf

 

 

 

6) 更改php-fpm的權限爲755;添加php-fpm到系統啓動項,並設置開機啓動;啓動php-fpm;

 

[root@lnmp php-5.3.27]# chmod755 /etc/init.d/php-fpm

[root@lnmp php-5.3.27]#chkconfig --add php-fpm

[root@lnmp php-5.3.27]#service php-fpm start

Starting php-fpm done

[root@lnmpphp-5.3.27]# chkconfig php-fpm on

 

這樣也能夠

[root@lnmpphp-5.3.27]# /application/php/sbin/php-fpm -t

[17-Jun-2015 20:06:48] NOTICE: configuration file/application/php5.3.27/etc/php-fpm.conf test is successful

[root@lnmpphp-5.3.27]# /application/php/sbin/php-fpm

#將如下三項放入到/etc/rc.local,開機啓動。文件中開啓服務是從後往前,開啓,中止服務是從前日後中止。

[root@lnmpphp-5.3.27]# vi /etc/rc.local

##nginx+php-fpm by TS at 2014.10.09

/application/nginx/sbin/nginx

/application/php/sbin/php-fpm

 

 

[root@lnmp php-5.3.27]# netstat -lntup|grep php-fpm 

tcp       0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      72576/php-fpm      

 

 

 

 

 

5 LNMP整合配置實踐操做

 

 

1) 編輯nginx.conf

 

[root@lnmp php-5.3.27]# cd /application/nginx/conf/

[root@lnmp conf]# vi nginx.conf

 

worker_processes 2;

events {

   worker_connections  1024;

}

http {

   include       mime.types;

   default_type application/octet-stream;

    sendfile        on;

   keepalive_timeout  65;

 

    server {

       listen       80;

       server_name  www.etiantian.org;

       root     /data/html/www;

       index    index.php index.html index.htm;

       access_log  logs/www_access.log;

        location ~ .*\.(php|php5)?$ {

           fastcgi_pass  127.0.0.1:9000;

           fastcgi_index index.php;

            includefastcgi.conf;

        }

    }

 

    server {

       listen       80;

       server_name  blog.etiantian.org;

       root     /data/html/blog;

       index    index.phpindex.html index.htm;

       access_log  logs/blog_access.log;

        location ~ .*\.(php|php5)?$ {

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }  

    }

 

    server {

       listen       80;

       server_name  bbs.etiantian.org;

       root     /data/html/bbs;

       index    index.phpindex.html index.htm;

       access_log  logs/bbs_access.log;

        location ~ .*\.(php|php5)?$ {

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }  

    }

 

    ##status

    server {

       listen       80;

       server_name  status.etiantian.org;

       stub_status on;

       access_log  off;

    }

}

 

 

2) 檢查nginx配置文件,平滑重啓

 

[root@lnmp conf]#/application/nginx/sbin/nginx -t

[root@lnmp conf]#/application/nginx/sbin/nginx -s reload

[root@lnmp data]# cd/data/html/

[root@lnmp html]# ll

total 16

drwxr-xr-x. 2 root root 4096 Jun 17 15:51 bbs

drwxr-xr-x. 2 root root 4096 Jun 17 15:51 blog

drwxr-xr-x. 2 root root 4096 Jun 17 15:51 wiki

drwxr-xr-x. 2 root root 4096 Jun 17 15:51 www

 

3) 編輯index.php文件,看是否能夠解析

 

[root@lnmp html]# cd www

[root@lnmp www]# vi index.php

<?php

       phpinfo();

?>

 

 

4)編輯index.php/mysql.php文件

 

[root@lnmp www]# cd ../bbs/

[root@lnmp bbs]# vi index.php

<?php

       $link_id=mysql_connect('192.168.1.66','root','888888') or mysql_error();

       if($link_id){

               echo "mysql successful by TS !";

       }else{

               echo mysql_error();

        }

?>

 

[root@lnmp bbs]# vi mysql.php

<?php

       $link_id=mysql_connect('192.168.1.67','root','888888') or mysql_error();

       if($link_id){

               echo "mysql successful by TS !";

       }else{

               echo mysql_error();

        }

?>

 

 

這裏LNMP是免安裝mysqlPHP安裝須要將編譯參數中的指定mysql路徑--with-mysql=/application/mysql \參數換成下面三個編譯參數:

 

--with-mysql=mysqlnd \

--with-mysql=mysqlnd \

--with-pdo-mysql=mysqlnd \

 

不知道是否是這個緣由,php鏈接MySQL不能給localhost,要指定IP才能夠鏈接成功;

 

 

 

6 參考資料:

         http://tslove.blog.51cto.com/9115838/1592742

         http://8802265.blog.51cto.com/8792265/1650624

         http://tslove.blog.51cto.com/9115838/1596567

轉載至:http://blog.csdn.net/sz_bdqn/article/details/46542367

相關文章
相關標籤/搜索