centos 6.5 搭建php

來源:互聯網
上載者:User

搭建php 

 

centos 6.5 64

php: 5.5.32

 

三.安裝PHP

 

先配置本地yum源

安裝依賴包:

yum -y install curl-devel mysql-devel libfreetype6-dev freetype-devel libpng libpng-devel openldap openldap-devel bzip2-devel db4-devel postgresql-devel net-snmp-devel libjpeg-devel libpng-devel libXpm-devel gmp-devel pspell-devel libxslt-devel libc-client-devel openldap-devel libxslt-devel libxml2-devel pcre-devel mysql-develunixODBC-devel

 

  安裝PHP所需依賴包:

 

 

tar zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local

make && make install

cd ../

 

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/

./configure

make && make install

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make && make install

cd ../../

 

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make && make install

cd ../

 

 

# 對共用庫做符號連結

ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4

ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

 

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure

make && make install

cd ../

 

安裝php:

 

 

tar zxvf php-5.5.13.tar.gz

cd php-5.5.13

 

mkdir /usr/local/php

mkdir /usr/local/php/etc

請核對一下自己的安裝目錄。

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \

--with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config \

--with-iconv-dir --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-zip --enable-soap \

--enable-opcache=no --without-pear --disable-fileinfo

 

列表如下(部分參數未得到解釋):

# 指定 php 安裝目錄

--prefix=/usr/local/php 

# 指定php.ini位置

--with-config-file-path=/usr/local/php/etc 

# mysql安裝目錄,對mysql的支援

--with-mysql=/usr/local/mysql

mysqli擴充技術不僅可以調用MySQL的預存程序、處理MySQL事務,而且還可以使訪問資料庫工作變得更加穩定。

--with-mysqli=/usr/local/mysql/bin/mysql_config   

整合 apache,apxs功能是使用mod_so中的LoadModule指令,載入指定模組到 apache,要求 apache 要開啟SO模組

--with-apxs2=/usr/local/apache/bin/apxs 

# 選項指令 --with-iconv-dir 用於 PHP 編譯時間指定 iconv 在系統裡的路徑,否則會掃描預設路徑。

--with-iconv-dir=/usr/local 

 

 

 

#註:如果記憶體較大 可以去掉--disable-fileinfo

make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-development /usr/local/php/etc/php.ini

cd ../

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

vi /usr/local/php/etc/php-fpm.conf

    修改

 

user = nobody

group = nobody

    為

 

user = www

group = www

 

# 將;pid = run/php-fpm.pid前的;去掉並修改為

pid = /usr/local/php/var/run/php-fpm.pid

 啟動php-fpm

 

/usr/local/php/sbin/php-fpm

 將Nginx與fpm加入自啟動

 

vi /etc/rc.local

# 輸入

ulimit -SHn 65535

/usr/local/php/sbin/php-fpm

/usr/local/nginx/sbin/nginx

編譯PHP擴充模組memcache、pdo_mysql、imagick

 

tar zxvf memcache-3.0.8.tgz

cd memcache-3.0.8

/usr/local/php/bin/phpize

./configure --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=/opt/mysql

/usr/include/mysql 是mysql的標頭檔位置

ln -s /usr/include/mysql/* /usr/local/include/

make && make install

cd ../

 

tar zxvf ImageMagick.tar.gz

cd ImageMagick-6.5.1-2/

./configure

make && make install

cd ../

 

tar zxvf imagick-3.2.0RC1.tgz

cd imagick-3.2.0RC1

/usr/local/php/bin/phpize

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

cd ../

    修改php.ini設定檔

 

vi /usr/local/php/etc/php.ini

#尋找; extension_dir = "/" 將前面的;去掉並修改為

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/"

#並加入

extension=memcache.so

extension=pdo_mysql.so

extension=imagick.so

執行下面的命令使設定檔立即生效:

 

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

    其他(可選):

 

    最佳化linux核心參數

 

vi /etc/sysctl.conf

    在末尾增加以下內容:

 

# Add

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog =  32768

net.core.somaxconn = 32768

 

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

 

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

 

net.ipv4.tcp_tw_recycle = 1

#net.ipv4.tcp_tw_len = 1

net.ipv4.tcp_tw_reuse = 1

 

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

 

#net.ipv4.tcp_fin_timeout = 30

#net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024  65535

    使配置立即生效:

 

/sbin/sysctl -p

    安裝opcache(因為PHP 5.5已經整合Zend Opcache,可以替代eaccelerator)

 

 

tar zxvf zendopcache-7.0.3.tgz

cd zendopcache-7.0.3

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

cd ../

    在php.ini中加入下面配置:

 

[opcache]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"

opcache.memory_consumption=128

opcache.interned_strings_buffer=8

opcache.max_accelerated_files=4000

opcache.revalidate_freq=60

opcache.fast_shutdown=1

opcache.enable_cli=1

 

# 使php.ini設定檔立即生效

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

    常用命令:

 

 

#修改完php.ini後執行:

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`

#修改完nginx.conf後執行

/usr/local/nginx/sbin/nginx -s reload

#重啟mysql服務執行:

service mysqld (start|stop|restart)

 

ln -s /usr/local/php/bin/php /usr/bin/php  

連結到/usr/bin下

 

同樣在slave上按照上面的步驟安裝。

 

請多指教。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.