安装需要的依赖
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel -y
yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
单独安装依赖 libiconv-devel
cd /tools/
wget http://mirrors.ustc.edu.cn/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/application/libiconv
make
echo $?
make install
echo $?
安装PHP需要的依赖服务
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install -y libmcrypt-devel mhash mcrypt
下载PHP包到/tools/目录下
tar xf php-5.5.3.tar.gz
cd /php-5.5.3
编译 安装"\"后不能有空格
./configure \
--prefix=/application/php-5.5.3 \
--enable-mysqlnd \
--with-mysql=/application/mysql \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--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-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no
预防报错预先配置
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar ###在下载减压后的php-x.x.目录
make
echo $?
make install
echo $?
ln -s /application/php-5.5.3/ /application/php
安装完成
php配置
cd /tools/php-5.3.3 #此目录为php的解压目录,比较php的2个配置文件的不同
vimdiff php.ini*
cp /tools/php-5.5.3/php.ini-production /application/php/lib/php.ini ##"php.ini-production"为生产环境的默认配置(关掉大部分报错提示)
切入进程目录:cd /application/php/etc/ ##(php-fpm.conf.default )
修改文件:cp php-fpm.conf.default php-fpm.conf
启动进程:/application/php/sbin/php-fpm
查看端口:lsof -i :9000
查看进程:ps -ef |grep php-fpm
PHP连接nginx测试(以blog为测试对象)
echo "" >/application/nginx/html/blog/index.php
vim /application/nginx/conf/extra-web/blog.conf
#blog_server virtualhost
server {
listen 80;
server_name blog.tang.org;
location / {
root html/blog;
index index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
}
测试:http://blog.tang.org/index.php
PHP连接mysql数据库测试
vim /application/nginx/conf/extra-web/sql.php
$link=mysql_connect('127.0.0.1','root','123123');
if(!$link) echo "sql-fail";
else echo "tang-sqlphp-success";
?>
测试:http://blog.tang.org/sql.php
===============连接超时server添加=========
#error Connection timed out and 504 error
large_client_header_buffers 4 16k;
client_max_body_size 30m;
client_body_buffer_size 128k;
fastcgi_connect_timeout 300;
fastcgi_read_timeout 300;
fastcgi_send_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_temp_file_write_size 64k;