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

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