首页 > 代码库 > lnmp安装--php安装
lnmp安装--php安装
版本:php5.6.4 x86_64
centos 6.6 x86_64
安装php之所以难,是因为要安装的扩展多,依赖关系复杂。
安装前的准备:
先看你想要安装哪些扩展。需要哪些包。下载地址:http://pan.baidu.com/s/1kTn7VQB
-rw-r--r--. 1 root root 3001938 Jun 15 2013 curl-7.19.6.tar.gz-rw-r--r--. 1 root root 1775673 Jun 17 2013 freetype-2.3.5.tar.gz-rw-r--r--. 1 root root 587617 Nov 3 2004 gd-2.0.33.tar.gz-rw-r--r--. 1 root root 258396 Jun 15 2013 GD-2.44.tar.gz-rw-r--r--. 1 root root 991456 Jun 15 2013 jpegsrc.v8d.tar.gz-rw-r--r--. 1 root root 2353373 Jun 17 2013 libgd-2.1.0-rc2.tar.gz-rw-r--r--. 1 root root 1335178 Jun 15 2013 libmcrypt-2.5.8.tar.gz-rw-r--r--. 1 root root 837439 Jun 15 2013 libpng-1.4.12.tar.gz-rw-r--r--. 1 root root 471915 Jun 15 2013 mcrypt-2.6.8.tar.gz-rw-r--r--. 1 root root 655906 Jun 15 2013 mhash-0.9.9.9.tar.bz2-rw-r--r--. 1 root root 2402592 Dec 23 2006 ncurses-5.6.tar.gz-rw-r--r--. 1 root root 17323206 May 18 2013 perl-5.18.0.tar.gz-rw-r--r--. 1 root root 560351 Jun 15 2013 zlib-1.2.7.tar.gz
再看看配置项:
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
可以看出我需要的功能有,gd库,mysql,mysqli,pdo,fpm,curl,mbstring。
可能新手会很困惑,php怎么和mysql结合,这里要说一下,php只需要安装上mysql的扩展(mysql,mysqli,pdo-mysql),php程序连接mysql的时候,会自动到对应host的端口连接mysql,只要mysql服务在监听就没有问题。
/etc/my.cnf配置
[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid[client]socket=/var/lib/mysql/mysql.sock
将上面所列出的包,依次安装上。
然后再./configure php
yum install libxml2 libxml2-develyum install bzip2 bzip2-devel找不到 gd.h。gdlib-config --all实际上找不到gd.h是因为没有安装下面两个包。yum install libXpmyum install libXpm-devel安装完,配置gd库。perl ./Makefile.PL cd libgd-2.1.0-rc2./configure --with-xpm=/usr/lib中间会显示gd支持的特性。makemake installcd GD-2.44perl ./Makefile.PL make&&make install
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
754 make 755 make install 756 php 757 /usr/local/sbin/php-fpm -h 758 /usr/local/php/sbin/php-fpm -h 759 ls /usr/local/php/php/ 760 ls /usr/local/php/ 761 ls 762 cp php.ini-development /usr/local/php/php/php.ini 763 ls /usr/local/php/php/ 764 find / -name php-fpm.conf.default 765 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 766 cp sapi/fpm/php-fpm /usr/local/bin/ 767 php-fpm start 768 php-fpm 769 vim /usr/local/php/php/php.ini
至此全部安装完毕。
663 ls 664 ./configure --help 665 ./configure --help |grep mysqli 666 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fastcgi --enable-safe-mode --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/gd2/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 667 yum install libxml2 libxml2-devel 668 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fastcgi --enable-safe-mode --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/gd2/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 669 yum install BZip2 670 yum list |grep bzip2 671 yum install bzip2 bzip2-devel 672 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fastcgi --enable-safe-mode --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/gd2/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 673 ls /usr/local |grep gd 674 ls /usr/local/ 675 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fastcgi --enable-safe-mode --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/gd2/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 676 ls /usr/local 677 ls /usr/local/lib 678 find / -name gd.h 679 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fastcgi --enable-safe-mode --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 680 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 681 vim README.md 682 ls 683 vim INSTALL 684 make 685 ls /usr/local/ 686 ls /usr/local/lib 687 find / |grep gd$ 688 cd /usr/share/locale/gd/ 689 ls 690 cd /root/Downloads/ 691 ls 692 cd extended/ 693 ls 694 cd GD-2.44 695 ls 696 vim README 697 find / |grep bin/gd 698 /usr/sbin/gdm 699 /usr/sbin/gdm --help 700 /usr/sbin/gdm --version 701 find / |grep bin/gd$ 702 gd_info(); 703 gd_info() ; 704 gd_info 705 gdlib-config 706 gdlib-config all 707 gdlib-config --all 708 gdbus 709 gdm 710 gdm --help 711 gdm-binary 712 gdm-binary --help 713 gdcmpgif 714 gdlib-config 715 gdlib-config --libs 716 gdlib-config --revision 717 gdlib-config --features 718 yum install libXpm 719 yum install libXpm-devel 720 gdlib-config --features 721 ls 722 ./perl Makefile.PL 723 vim README 724 perl ./Makefile.PL 725 perl ./Makefile.PL -h 726 perl ./Makefile.PL 727 make 728 make install 729 gdlib-config 730 perl ./Makefile.PL --help 731 perl ./Makefile.PL -h 732 perl ./Makefile.PL ? 733 perl ./Makefile.PL --with-xpm=/usr/local/lib 734 vim README 735 cd .. 736 ls 737 cd libgd-2.1.0-rc2 738 ls 739 ./configure --with-xpm=/usr/lib 740 make 741 cd .. 742 ls 743 cd libgd-2.1.0-rc2 744 make install 745 cd .. 746 cd GD-2.44 747 perl ./Makefile.PL 748 make&&make install 749 cd .. 750 cd php-5.6.4 751 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd=/usr/local/gd2/ --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 752 find / |grep gd.h 753 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/mysql/ --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir=/usr/local/jpeg --enable-sockets --enable-gd-native-ttf --with-curl=/usr/local/curl --enable-bcmath --with-mcrypt --enable-fpm --with-mysql --with-iconv --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 754 make 755 make install 756 php 757 /usr/local/sbin/php-fpm -h 758 /usr/local/php/sbin/php-fpm -h 759 ls /usr/local/php/php/ 760 ls /usr/local/php/ 761 ls 762 cp php.ini-development /usr/local/php/php/php.ini 763 ls /usr/local/php/php/ 764 find / -name php-fpm.conf.default 765 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 766 cp sapi/fpm/php-fpm /usr/local/bin/ 767 php-fpm start 768 php-fpm 769 vim /usr/local/php/php/php.ini 770 vim /usr/local/nginx/conf/nginx.conf 771 /usr/local/nginx/ -s stop 772 /usr/local/nginx/sbin/nginx -s stop 773 /usr/local/nginx/sbin/nginx 774 service mysqld start 775 php-fpm 776 cd /usr/local/nginx/html/ 777 ls 778 vim index.php 779 /usr/local/mysql/bin/mysql -uroot -p 780 vim index.php 781 vim /usr/local/php/php/php.ini 782 /usr/local/nginx/sbin/nginx -s stop 783 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 784 find /usr/ -name php-fpm.conf 785 vim /usr/local/php/etc/php-fpm.conf 786 pkill php-fpm 787 /usr/local/bin/php-fpm 788 cat /etc/passwd |grep www 789 vim /usr/local/php/etc/php-fpm.conf 790 /usr/local/bin/php-fpm 791 pkill php-fpm 792 /usr/local/bin/php-fpm 793 cat /etc/passwd 794 groupadd nginx 795 useradd -r -g nginx nginx 796 vim /usr/local/php/etc/php-fpm.conf 797 /usr/local/bin/php-fpm 798 vim /usr/local/php/etc/php-fpm.conf 799 /usr/local/bin/php-fpm 800 /usr/local/nginx/sbin/nginx -s stop 801 /usr/local/nginx/sbin/nginx 802 ls 803 cd .. 804 ls -l 805 chmod -R 777 ./html/ 806 ps -ef |grep php 807 /usr/local/mysql/bin/mysql -hlocalhost -uroot -p 808 ls 809 vim html/index.php 810 /usr/local/mysql/bin/mysql -uroot -p -hlocalhost 811 history
可能发生的错误:
configure: error: Please reinstall the BZip2 distribution
yum install bzip2 bzip2-devel
yum install -y libmcrypt libmcrypt-devel
configure:error: *** libmcrypt was not found
为了的到mcrypt.so库文件,先后安装编译了mhash和libmcrypt, 但是到最后编译mcrypt时报错:
configure: error: *** libmcrypt was not found
[root@localhost] # export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
再次编译
http://www.linuxidc.com/Linux/2009-03/18739.htm
http://www.it165.net/os/html/201304/4868.html
安装gd的时候,会报这个错误 “usr/local/src/php-5.5.6/ext/gd/gd.c:57:22: error: X11/xpm.h: No such file or directory make: *** [ext/gd/gd.lo] Error 1”
yum install libXpm-dev libXpm
在配置gd2的时候多加一条 --with-xpm=/usr/lib
./configure 的时候 会发现
"Support for Xpm library : yes"这一项,说明配置成功。
php支持 mysqli,pdo-mysql
mysqlnd(专门为php写的),libmysqlclient(用c连接数据库用的,搞到php上来了)
http://php.net/manual/en/ref.pdo-mysql.php
nginx 发生permission deny
去看看php-fpm的用户配置,nginx的用户配置
当连接数据库的时候,我遇到这个问题了。后来发现,写127.0.0.1就可以连接,写localhost就不可以连接。mysql版本是 5.6.
create user ‘root‘@‘localhost‘的时候也有问题。总之搞不懂。
有人说和selinux有关。
http://blog.sina.com.cn/s/blog_a0d5a7f10101dzbc.html
lnmp环境的操作部分:
安装php+nginx:http://www.cnblogs.com/simpman/p/4151662.html
安装mysql:http://www.cnblogs.com/simpman/p/4192942.html
安装php:http://www.cnblogs.com/simpman/p/4196051.html
lnmp环境的理论部分:
FastCgi与PHP-fpm关系[转] 读完本文瞬间明朗了很多 : http://www.cnblogs.com/simpman/p/4151639.html
epoll和select区别:http://www.cnblogs.com/simpman/p/4150005.html
扩展下载包:http://pan.baidu.com/s/1kTn7VQB
lnmp安装--php安装