在linux中php安裝配置與windows中有不小的區別了,在linux中幾乎都是代碼形式了,下面我們一起來看看php5.3.10的安裝配置步驟詳解,希望下文可幫助到各位。
下面以最新的php-5.3.10為例進行安裝。
wget http://cn.php.net/distributions/php-5.3.10.tar.gz
tar -zxvf php-5.3.10.tar.gz
cd php-5.3.10
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
上面的具體參數可以使用./configure --help查看
make ZEND_EXTRA_LIBS='-liconv'
make test
make && make install (此處最好分開做,因為make的時候會有報錯出現。)
我在上面的make時就報了下面的錯誤
root/source/php-5.3.10/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127
解決辦法是(我的mysql安裝目錄是/usr/local/msyql,這個視自己的mysql安裝路徑而定。)
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
64位系統應使用下面的這行
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
若報下面的錯,就是編繹mysql的時候沒有加上mysqli這一項,把下面標紅的那部分取消掉,重新編繹就行了。
make: *** [ext/mysqli/mysqli.lo] Error 1
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
另外,也有報下面錯的可能。該問題有可能是沒有安裝iconv這個編碼轉換的包,也有可以裝了,但是仍有這個錯。
sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
make[1]: *** [install-pear-installer] Error 127
make: *** [install-pear] Error 2
find / -name libiconv.so.2在/usr/lib/libiconv.so.2位置發現libiconv已經安裝。
於是運行/sbin/ldconfig,再重新編譯,不再報上面的錯。ldconfig用於加載最新編繹過的包。
注:上面很多需要的包我都是通過通過./configure --prefix=/usr --libdir=/usr/lib --sysconfdir=/etc參數編繹。這樣其在默認的目錄就能找到該包了。
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
修改php.ini文件和php-fpm文件中參數,可以手動更改也可以用下面的sed命令更改
sed -i 's#short_open_tag = Off#short_open_tag = On#g' /usr/local/php/etc/php.ini
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.max_children = 5#pm.max_children = 32#g' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.start_servers = 2#pm.start_servers = 16#g' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.min_spare_servers = 1#pm.min_spare_servers = 8#g' /usr/local/php/etc/php-fpm.conf
sed -i 's#pm.max_spare_servers = 3#pm.max_spare_servers = 32#g' /usr/local/php/etc/php-fpm.conf
sed -i 's#;pm.max_requests = 500#pm.max_requests = 120#g' /usr/local/php/etc/php-fpm.conf
php官方也給出了其中所有參數項的解釋說明,具體見http://www.php.net/manual/en/install.fpm.configuration.php
設置開機啟動
chmod 755 /etc/init.d/php-fpm
chkconfig --add php-fpm
/etc/init.d/php-fpm start
至此,php的安裝完畢。
最後可以再安裝一些php的擴展包和開戶php加速(具體軟件包可以視網上的最新版進行安裝):
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local//php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../
修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改為extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
並在此行後增加以下幾行,然後保存:
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "imagick.so"
再查找output_buffering = Off
修改為output_buffering = On
再查找; cgi.fix_pathinfo=0
修改為cgi.fix_pathinfo=0,防止Nginx文件類型錯誤解析漏洞。
配置eAccelerator加速PHP:
mkdir -p /opt/webserver/eaccelerator_cache
vi /usr/local/php/etc/php.ini
在php.ini配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/opt/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
php的安全性設置:
找到:;open_basedir =
修改為:open_basedir = .:/tmp/ #防止php木馬跨站,重要!!
找到:disable_functions =
修改為:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,
ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,
dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,
posix_ctermid,posix_get_last_error,posix_getcwd,