PHP5.6
- 1 下載安裝包
#wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz
#tar -zxf php-5.6.2
- 2 安裝php依賴
#yum install gcc gcc-c++ libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel
- 3 安裝 (-prefix是安裝目錄,-with-mysql是mysql的安裝目錄)
#./configure --prefix=/appServer/php --with-config-file-path=/appServer/php/etc --enable-inline-optimization --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql --with-mysqli --with-pdo-mysql --with-pcre-regex --with-iconv --with-zlib --with-mcrypt --with-gd --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl --with-gettext --enable-bcmath
#make
#make install
- 4 若上幾步都沒報錯的話就安裝成功,有報錯估計是少了點什么,用百度查查后yum一下吧。
#cp php.ini-production /usr/local/php/etc/php.ini
- 5 當我們使用nginx還要把php-fpm.conf放到/usr/local/php/etc/里
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
- 6 接下來我們還可能需要將php-fpm作為server服務
#cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- 7 設置權限,并添加服務
#chmod +x /etc/init.d/php-fpm
#chkconfig --add php-fpm
- 8 以后可以使用如下命令管理php-fpm了
#service php-fpm start
#service php-fpm stop
#service php-fpm restart
#service php-fpm reload
Nginx
- 1 安裝依賴
yum -y install pcre pcre-devel
yum -y install openssl openssl-devel
- 2下載源碼包
wget http://nginx.org/download/nginx-1.9.7.tar.gz
- 3 安裝
tar -zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7
./configure --user=www --group=www --prefix=/usr/local/nginx-1.9.7 --with-http_stub_status_module --with-http_ssl_module --with-pcre
make;
make install
- 3 Nginx整合PHP
vi /usr/local/nginx/conf/nginx.conf
...
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
PHP安裝錯誤:
undefined reference to `libiconv_open'
make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
./configure
make
make install
Don't know how to define struct flock on this system, set --enable-opcache=no
vim /etc/ld.so.conf.d/local.conf # 編輯庫文件
/usr/local/lib # 添加該行
:wq # 保存退出
ldconfig -v # 使之生效
環境變量設置
方法一:
直接運行命令export PATH=$PATH:/usr/local/php/bin,只會對當前會話臨時生效。
方法二:
執行 vi ~/.bash_profile
修改文件中PATH一行,將/usr/local/php/bin加入到PATH=$PATH:$HOME/.local/bin:$HOME/bin一行之后
這種方法只對當前登錄用戶生效
方法三:
修改/etc/profile文件使其永久性生效,并對所有系統用戶生效,在文件末尾加上如下兩行代碼:
PATH=$PATH:/usr/local/php/bin
export PATH
最后:執行 命令source /etc/profile生效,執行完可通過echo $PATH命令查看是否添加成功。