版本:php5.6.4 x86_64php
centos 6.6 x86_64html
安裝php之因此難,是由於要安裝的擴展多,依賴關係複雜。mysql
安裝前的準備:linux
先看你想要安裝哪些擴展。須要哪些包。下載地址:http://pan.baidu.com/s/1kTn7VQBnginx
-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
再看看配置項:sql
./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服務在監聽就沒有問題。vim
/etc/my.cnf配置centos
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [client] socket=/var/lib/mysql/mysql.sock
將上面所列出的包,依次安裝上。api
而後再./configure php
yum install libxml2 libxml2-devel yum install bzip2 bzip2-devel 找不到 gd.h。 gdlib-config --all 實際上找不到gd.h是由於沒有安裝下面兩個包。 yum install libXpm yum install libXpm-devel 安裝完,配置gd庫。 perl ./Makefile.PL cd libgd-2.1.0-rc2 ./configure --with-xpm=/usr/lib 中間會顯示gd支持的特性。 make make install cd GD-2.44 perl ./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
pycurl版本低:http://www.fireinfo.cn/content-11-63668-1.html