设为首页 收藏本站
查看: 892|回复: 0

[经验分享] PHP程序安装,与nginx的web连接,与MySQL数据库连接

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-12-2 08:42:28 | 显示全部楼层 |阅读模式
[iyunv@web01 tools]# vim /etc/yum.conf(yum配置文件)

[main]

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

keepcache=0(0代表yum安装完后下载的包删除,1代表不删除,可留作他用)

debuglevel=2

logfile=/var/log/yum.log

exactarch=1

obsoletes=1

gpgcheck=1

plugins=1

installonly_limit=5

[iyunv@web01 tools]# ll /var/cache/yum/x86_64/6/base/packages/(实际下载位置)

[iyunv@web01 tools]# yum install zlib-devel libxml2-devel libjpeg-devel libiconv-devel -y(libiconv-devel此包源没有,只能编译安装)

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

[iyunv@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

[iyunv@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

名字已变

[iyunv@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 ../

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

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

[iyunv@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  

[iyunv@web01 tools]# yum install libmcrypt-devel mhash mhash-devel mcrypt -y(各种加密库等的安装)

[iyunv@web01 tools]# tar xf php-5.5.30.tar.gz(解压PHP)

[iyunv@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(让修改生效)

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

[iyunv@web01 php-5.5.30]# make(开始编译,编译之前还可改东西,编译之后就不要修改东西了)

[iyunv@web01 php-5.5.30]# make install(开始安装)

[iyunv@web01 application]# ln -s /application/php5.5.30/ /application/php(创建软连接)

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

[iyunv@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(生产环境)

[iyunv@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

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

[iyunv@web01 etc]# cd /application/php/etc/(切换上传目录)

[iyunv@web01 etc]# rz(上传php-fpm.conf进程配置文件)

[iyunv@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(默认配置文件)

[iyunv@web01 etc]# /application/php/sbin/php-fpm(启动服务)

[iyunv@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           

[iyunv@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))

[iyunv@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连接过程

[iyunv@web01 blog]# vim /application/nginx/conf/nginx.conf(编辑nginx配置文件)

server {(一个server标签代表一个虚拟主机)

        listen       80;

        server_name  blog.iyunv.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;

        }

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

      }

[iyunv@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

[iyunv@web01 blog]# /application/nginx/sbin/nginx -s reload(平滑重启,有时不成功,使用-s stop停止后重新加载nginx服务)

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

与MySQL连接测试并安装博客程序(WordPress)

[iyunv@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)



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

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

[iyunv@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 iyunv !";

        }else{

                echo mysql_error();

        }

?>

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

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

[iyunv@web01 blog]# rz(上传下载好的博客程序)

[iyunv@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

[iyunv@web01 blog]# tar xf wordpress-4.3.1-zh_CN.tar.gz(解压到当前目录)

[iyunv@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

[iyunv@web01 blog]# mv wordpress/* ./(移动到当前目录)

[iyunv@web01 blog]# rm -fr wordpress

[iyunv@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

[iyunv@web01 blog]# cd ..(返回要授权目录的上级目录)

[iyunv@web01 html]# chown -R root.root blog/(首先改变所有目录及文件所有者和所有组为root)

[iyunv@web01 html]# find ./blog/ -type f|xargs chmod 644(授权所有文件权限为安全临界属性-rw-r--r--)

[iyunv@web01 html]# find ./blog/ -type d|xargs chmod 755(授权所有目录权限为安全临界属性drwxr-xr-x)

[iyunv@web01 html]# mkdir blog/wp-content/uploads(如果没有用户上传目录就创建)

[iyunv@web01 html]# chown  -R nginx.nginx blog/wp-content/uploads/(只改变上传目录所有者和所有组为nginx)

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-146097-1-1.html 上篇帖子: php扩展模块如何安装 下篇帖子: php配置文件详解 数据库连接 程序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表