PHP程序安裝,與nginx的web連接,與MySQL數據庫連接

[root@web01 tools]# vim /etc/yum.confyum配置文件)

[main]

cachedir=/var/cache/yum/$basearch/$releasever(下載位置)

keepcache=00代表yum安裝完後下載的包刪除,1代表不刪除,可留作他用)

debuglevel=2

logfile=/var/log/yum.log

exactarch=1

obsoletes=1

gpgcheck=1

plugins=1

installonly_limit=5

[root@web01 tools]# ll /var/cache/yum/x86_64/6/base/packages/(實際下載位置)

[root@web01 tools]# yum install zlib-devel libxml2-devel libjpeg-devel libiconv-devel -ylibiconv-devel此包源沒有,只能編譯安裝)

[root@web01 tools]# yum install freetype-devel libpng-devel gd-devel curl-devel libxslt-devel -y

[root@web01 tools]# rpm -qa zlib-devel libxml2-devel libjpeg-devel libiconv-devel(檢查)

zlib-devel-1.2.3-29.el6.x86_64

libxml2-devel-2.7.6-20.el6.x86_64

[root@web01 tools]# rpm -qa freetype-devel libpng-devel gd-devel curl-devel libxslt-devel(檢查)

gd-devel-2.0.35-11.el6.x86_64

freetype-devel-2.3.11-15.el6_6.1.x86_64

libpng-devel-1.2.49-1.el6_2.x86_64

libxslt-devel-1.1.26-2.el6_3.1.x86_64

 

libjpeg-devel====>libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64

curl-devel   ====>libcurl-devel-7.19.7-40.el6_6.4.x86_64

名字已變

[root@web01 conf]# rpm -qa zlib-devel libxml2-devel freetype-devel libpng-devel gd-devel libxslt-devel libjpeg-turbo-devel libcurl-devel(重新檢查)

libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64

libcurl-devel-7.19.7-46.el6.x86_64

zlib-devel-1.2.3-29.el6.x86_64

libxml2-devel-2.7.6-20.el6.x86_64

gd-devel-2.0.35-11.el6.x86_64

freetype-devel-2.3.11-15.el6_6.1.x86_64

libpng-devel-1.2.49-1.el6_2.x86_64

libxslt-devel-1.1.26-2.el6_3.1.x86_64

===================================================

libiconv-devel安裝方法:yum源沒有安裝包)

mkdir -p /application/tools/

cd /application/tools/

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv(普通包,沒有服務的安裝位置)

make

make install

cd ../

==================================================

[root@web01 tools]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo (快速安裝方法:repo源安裝)

[root@web01 tools]# yum list|grep mhash(可查看軟件包各種源中的版本)

mhash.i686                                  0.9.9.9-3.el6                epel  

mhash.x86_64                                0.9.9.9-3.el6                epel  

mhash-devel.i686                            0.9.9.9-3.el6                epel  

mhash-devel.x86_64                          0.9.9.9-3.el6                epel  

[root@web01 tools]# yum install libmcrypt-devel mhash mhash-devel mcrypt -y(各種加密庫等的安裝)

[root@web01 tools]# tar xf php-5.5.30.tar.gz(解壓PHP

[root@web01 tools]# cd php-5.5.30/

開始執行配置

./configure \

--prefix=/application/php5.5.30 \

--with-mysql=mysqlnd \(此爲MySQL不在本機,MySQL在本地的執行--with-mysql=/application/mysql \

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

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-soap \

--enable-short-tags \

--enable-static \

--with-xsl \

--with-fpm-user=nginx \

--with-fpm-group=nginx \

--enable-ftp

==============================================================

make前需要先執行:

ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/(創建軟連接)

touch ext/phar/phar.phar

或:

echo "/application/mysql/lib" >>/etc/ld.so.conf

ldconfig(讓修改生效)

==============================================================

[root@web01 php-5.5.30]# make(開始編譯,編譯之前還可改東西,編譯之後就不要修改東西了)

[root@web01 php-5.5.30]# make install(開始安裝)

[root@web01 application]# ln -s /application/php5.5.30/ /application/php(創建軟連接)

[root@web01 application]# cd /application/tools/php-5.5.30

[root@web01 php-5.5.30]# ll php.ini-*PHP引擎配置文件)

-rw-r--r-- 1 1887963844 1887961601 69236 2015-09-30 19:30 php.ini-development(開發環境)

-rw-r--r-- 1 1887963844 1887961601 69266 2015-09-30 19:30 php.ini-production(生產環境)

[root@web01 php-5.5.30]# diff php.ini-*(比對,可用vimdiff

86c86

< ; This is php.ini-development INI file.

---

> ; This is php.ini-production INI file.

449c449

< error_reporting = E_ALL

---

> error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

466c466

< display_errors = On

---

> display_errors = Off

477c477

< display_startup_errors = On

---

> display_startup_errors = Off

521c521

< track_errors = On

---

> track_errors = Off

746c746

< ;cgi.redirect_status_env =

---

> ;cgi.redirect_status_env =

1215c1215

< mysqlnd.collect_memory_statistics = On

---

> mysqlnd.collect_memory_statistics = Off

[root@web01 php-5.5.30]# cp /application/tools/php-5.5.30/php.ini-production /application/php/lib/php.ini(改名)

[root@web01 etc]# cd /application/php/etc/(切換上傳目錄)

[root@web01 etc]# rz(上傳php-fpm.conf進程配置文件)

[root@web01 etc]# ll

總用量 52

-rw-r--r-- 1 root root  1232 2015-11-23 21:56 pear.conf

-rw-r--r-- 1 root root 21688 2014-09-21 18:24 php-fpm.conf

-rw-r--r-- 1 root root 22610 2015-11-23 21:56 php-fpm.conf.default(默認配置文件)

[root@web01 etc]# /application/php/sbin/php-fpm(啓動服務)

[root@web01 etc]# ps -ef|grep php-fpm|grep -v grep

root      13853      1  0 23:13 ?        00:00:00 php-fpm: master process (/application/php5.5.30/etc/php-fpm.conf)

nginx     13854  13853  0 23:13 ?        00:00:00 php-fpm: pool www           

nginx     13855  13853  0 23:13 ?        00:00:00 php-fpm: pool www           

[root@web01 etc]# ss -lntup|grep php-fpm(默認端口號爲9000

tcp    LISTEN     0      16384          127.0.0.1:9000                  *:*      users:(("php-fpm",13853,7),("php-fpm",13854,0),("php-fpm",13855,0))

[root@web01 html]# vim /etc/rc.local(開機自啓動,注意順序)

 

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.

 

touch /var/lock/subsys/local

/etc/init.d/rpcbind start

/application/php/sbin/php-fpm

/application/nginx/sbin/nginx

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

~                                                                                                              

"/etc/rc.local" 11L, 404C 已寫入                                                             

 

=================================================================================================================

以下爲與nginx連接過程

[root@web01 blog]# vim /application/nginx/conf/nginx.conf(編輯nginx配置文件)

server {(一個server標籤代表一個虛擬主機)

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index  index.php index.html index.htm;(依次尋找主頁)

       }

=================================================================添加此內容

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

            root html/blog;(路徑一定要添加,不添加會找不到網頁報404錯誤)

            fastcgi_pass  127.0.0.1:9000;(監控localhost本機9000端口)

            fastcgi_index index.php;

            include fastcgi.conf;

        }

=================================================================

      }

[root@web01 blog]# /application/nginx/sbin/nginx -t(檢查語法)

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@web01 blog]# /application/nginx/sbin/nginx -s reload(平滑重啓,有時不成功,使用-s stop停止後重新加載nginx服務)

=================================================================================================================

MySQL連接測試並安裝博客程序(WordPress

[root@db01 ~]# mysql -uroot -p123456(登錄MySQL

mysql> create database wordpress;(建立wordpress庫)

Query OK, 1 row affected (0.01 sec)

 

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| test               |

| wordpress          |

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

5 rows in set (0.00 sec)

 

mysql> grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456';(建立用戶,並管理wordpress庫)

    (授予 所有權限 單個庫 所有表 用戶名  主機名或地址段  被識別      密碼)

Query OK, 0 rows affected (0.01 sec)

 

mysql> flush privileges;(刷新權限,使得創建用戶生效)

Query OK, 0 rows affected (0.01 sec)

 

mysql> select user,host from mysql.user where user='wordpress';(查看單個用戶對應的主機)

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

| user      | host       |

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

| wordpress | 172.16.1.% |

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

1 row in set (0.01 sec)

mysql> use wordpress(切到庫裏)

Database changed

mysql> show tables;(查看該庫的表)

Empty set (0.00 sec)

 

============================================================================================

[root@web01 ~]# cd /application/nginx/html/blog/

[root@web01 blog]# vim test_mysql.php

<?php

        $link_id=mysql_connect('172.16.1.51:3306','wordpress','123456') or mysql_error();(使用建立的對應用戶名密碼連接數據庫)

        if($link_id){

                echo "mysql successful by oldboy !";

        }else{

                echo mysql_error();

        }

?>

=========================================================================================================

[root@web01 ~]# cd /application/nginx/html/blog/

[root@web01 blog]# rz(上傳下載好的博客程序)

[root@web01 blog]# ll

總用量 6776

-rw-r--r-- 1 root root      19 2015-11-19 16:28 index.html

-rw-r--r-- 1 root root      20 2015-11-24 00:27 phpinfo.php

-rw-r--r-- 1 root root     176 2015-11-24 01:15 test_mysql.php

-rw-r--r-- 1 root root 6922520 2015-11-22 13:18 wordpress-4.3.1-zh_CN.tar.gz

[root@web01 blog]# tar xf wordpress-4.3.1-zh_CN.tar.gz(解壓到當前目錄)

[root@web01 blog]# ll

總用量 6780

-rw-r--r-- 1 root   root           19 2015-11-19 16:28 index.html

-rw-r--r-- 1 root   root           20 2015-11-24 00:27 phpinfo.php

-rw-r--r-- 1 root   root          176 2015-11-24 01:15 test_mysql.php

drwxr-xr-x 5 nobody nfsnobody    4096 2015-09-16 22:38 wordpress

-rw-r--r-- 1 root   root      6922520 2015-11-22 13:18 wordpress-4.3.1-zh_CN.tar.gz

[root@web01 blog]# mv wordpress/* ./(移動到當前目錄)

[root@web01 blog]# rm -fr wordpress

[root@web01 blog]# ll

總用量 6952

-rw-r--r--  1 root   root           19 2015-11-19 16:28 index.html

-rw-r--r--  1 nobody nfsnobody     418 2015-09-03 11:33 index.php

-rw-r--r--  1 nobody nfsnobody   19930 2015-09-03 11:33 license.txt

-rw-r--r--  1 root   root           20 2015-11-24 00:27 phpinfo.php

-rw-r--r--  1 nobody nfsnobody    6789 2015-09-16 22:38 readme.html

-rw-r--r--  1 root   root          176 2015-11-24 01:15 test_mysql.php

-rw-r--r--  1 root   root      6922520 2015-11-22 13:18 wordpress-4.3.1-zh_CN.tar.gz

-rw-r--r--  1 nobody nfsnobody    4951 2015-09-03 11:33 wp-activate.php

drwxr-xr-x  9 nobody nfsnobody    4096 2015-09-16 22:38 wp-admin

-rw-r--r--  1 nobody nfsnobody     271 2015-09-03 11:33 wp-blog-header.php

-rw-r--r--  1 nobody nfsnobody    5007 2015-09-03 11:33 wp-comments-post.php

-rw-r--r--  1 nobody nfsnobody    2930 2015-09-16 22:38 wp-config-sample.php

drwxr-xr-x  5 nobody nfsnobody    4096 2015-09-16 22:38 wp-content

-rw-r--r--  1 nobody nfsnobody    3286 2015-09-03 11:33 wp-cron.php

drwxr-xr-x 12 nobody nfsnobody    4096 2015-09-16 22:38 wp-includes

-rw-r--r--  1 nobody nfsnobody    2380 2015-09-03 11:33 wp-links-opml.php

-rw-r--r--  1 nobody nfsnobody    3123 2015-09-03 11:33 wp-load.php

-rw-r--r--  1 nobody nfsnobody   34669 2015-09-03 11:33 wp-login.php

-rw-r--r--  1 nobody nfsnobody    8252 2015-09-03 11:33 wp-mail.php

-rw-r--r--  1 nobody nfsnobody   11062 2015-09-03 11:33 wp-settings.php

-rw-r--r--  1 nobody nfsnobody   25124 2015-09-03 11:33 wp-signup.php

-rw-r--r--  1 nobody nfsnobody    4035 2015-09-03 11:33 wp-trackback.php

-rw-r--r--  1 nobody nfsnobody    3055 2015-09-03 11:33 xmlrpc.php

[root@web01 blog]# cd ..(返回要授權目錄的上級目錄)

[root@web01 html]# chown -R root.root blog/(首先改變所有目錄及文件所有者和所有組爲root

[root@web01 html]# find ./blog/ -type f|xargs chmod 644(授權所有文件權限爲安全臨界屬性-rw-r--r--

[root@web01 html]# find ./blog/ -type d|xargs chmod 755(授權所有目錄權限爲安全臨界屬性drwxr-xr-x)

[root@web01 html]# mkdir blog/wp-content/uploads(如果沒有用戶上傳目錄就創建)

[root@web01 html]# chown  -R nginx.nginx blog/wp-content/uploads/(只改變上傳目錄所有者和所有組爲nginx

wKiom1Zdb02QblymAARPE2Y0Mtk450.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章