版本:php5.6.4 x86_64
centos 6.6 x86_64
安装php之所以难,是因为要安装的扩展多,依赖关系复杂。
安装前的准备:
先看你想要安装哪些扩展。需要哪些包。下载地址:http://pan.baidu.com/s/1kTn7VQB
-rw-r--r--. root root Jun curl-7.19..tar.gz
-rw-r--r--. root root Jun freetype-2.3..tar.gz
-rw-r--r--. root root Nov gd-2.0..tar.gz
-rw-r--r--. root root Jun GD-2.44.tar.gz-rw-r--r--. root root Jun jpegsrc.v8d.tar.gz
-rw-r--r--. root root Jun libgd-2.1.-rc2.tar.gz
-rw-r--r--. root root Jun libmcrypt-2.5..tar.gz
-rw-r--r--. root root Jun libpng-1.4..tar.gz
-rw-r--r--. root root Jun mcrypt-2.6..tar.gz
-rw-r--r--. root root Jun mhash-0.9.9.9.tar.bz2-rw-r--r--. root root Dec ncurses-5.6.tar.gz
-rw-r--r--. root root May perl-5.18..tar.gz-rw-r--r--. root root Jun zlib-1.2..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/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links= [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [client]
socket=/var/lib/mysql/mysql.sock
将上面所列出的包,依次安装上。
然后再./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.-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
make
make install
php
/usr/local/sbin/php-fpm -h
/usr/local/php/sbin/php-fpm -h
ls /usr/local/php/php/
ls /usr/local/php/
ls
cp php.ini-development /usr/local/php/php/php.ini
ls /usr/local/php/php/
find / -name php-fpm.conf.default
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin/
php-fpm start
php-fpm
vim /usr/local/php/php/php.ini
至此全部安装完毕。
ls
./configure --help
./configure --help |grep mysqli
./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 yum install libxml2 libxml2-devel
./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
yum install BZip2
yum list |grep bzip2
yum install bzip2 bzip2-devel
./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
ls /usr/local |grep gd
ls /usr/local/
./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
ls /usr/local
ls /usr/local/lib
find / -name gd.h
./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
./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
vim README.md
ls
vim INSTALL
make
ls /usr/local/
ls /usr/local/lib
find / |grep gd$
cd /usr/share/locale/gd/
ls
cd /root/Downloads/
ls
cd extended/
ls
cd GD-2.44
ls
vim README
find / |grep bin/gd
/usr/sbin/gdm
/usr/sbin/gdm --help
/usr/sbin/gdm --version
find / |grep bin/gd$
gd_info();
gd_info() ;
gd_info
gdlib-config
gdlib-config all
gdlib-config --all
gdbus
gdm
gdm --help
gdm-binary
gdm-binary --help
gdcmpgif
gdlib-config
gdlib-config --libs
gdlib-config --revision
gdlib-config --features
yum install libXpm
yum install libXpm-devel
gdlib-config --features
ls
./perl Makefile.PL
vim README
perl ./Makefile.PL
perl ./Makefile.PL -h
perl ./Makefile.PL
make
make install
gdlib-config
perl ./Makefile.PL --help
perl ./Makefile.PL -h
perl ./Makefile.PL ?
perl ./Makefile.PL --with-xpm=/usr/local/lib
vim README
cd ..
ls
cd libgd-2.1.-rc2
ls
./configure --with-xpm=/usr/lib
make
cd ..
ls
cd libgd-2.1.-rc2
make install
cd ..
cd GD-2.44
perl ./Makefile.PL
make&&make install
cd ..
cd php-5.6. ./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 find / |grep gd.h
./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 make
make install
php
/usr/local/sbin/php-fpm -h
/usr/local/php/sbin/php-fpm -h
ls /usr/local/php/php/
ls /usr/local/php/
ls
cp php.ini-development /usr/local/php/php/php.ini
ls /usr/local/php/php/
find / -name php-fpm.conf.default
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin/
php-fpm start
php-fpm
vim /usr/local/php/php/php.ini
vim /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/ -s stop
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
service mysqld start
php-fpm
cd /usr/local/nginx/html/
ls
vim index.php
/usr/local/mysql/bin/mysql -uroot -p
vim index.php
vim /usr/local/php/php/php.ini
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
find /usr/ -name php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
pkill php-fpm
/usr/local/bin/php-fpm
cat /etc/passwd |grep www
vim /usr/local/php/etc/php-fpm.conf
/usr/local/bin/php-fpm
pkill php-fpm
/usr/local/bin/php-fpm
cat /etc/passwd
groupadd nginx
useradd -r -g nginx nginx
vim /usr/local/php/etc/php-fpm.conf
/usr/local/bin/php-fpm
vim /usr/local/php/etc/php-fpm.conf
/usr/local/bin/php-fpm
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
ls
cd ..
ls -l
chmod -R ./html/
ps -ef |grep php
/usr/local/mysql/bin/mysql -hlocalhost -uroot -p
ls
vim html/index.php
/usr/local/mysql/bin/mysql -uroot -p -hlocalhost
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