安装PHP以及搭建博客(一)
netstat -lntup|egrep '3306|80' #检查mysql,nginx是否安装启动或者netstat -lntup|egrep 'mysql|nginx'
安装epeo源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
安装PHP需要的依赖库
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel yum install -y freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
libiconv-devel可能没有,需要手动安装
wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz tar xf libiconv-1.15.tar.gz cd libiconv-1.15 ./configure --prefix=/usr/local/libiconv make && make install
PHP相关扩展库
(不安装epeo源,是没有的)
yum install libmcrypt-devel mhash mcrypt -y
安装下载PHP
wget http://mirrors.sohu.com/php/php-5.5.32.tar.xz
解压缩
tar xf php-5.5.32.tar.gz cd php-5.5.32
编译
./configure \
--prefix=/application/php5.5.32 \
--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-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nignx \
--enable-ftp \
--enable-opcache=on
如果没有mysql
--enable-mysqlnd\
--with-pdo-mysql=mysqlnd\
--with-mysqli=mysqlnd\
开始make&&make install
最好之前做下下面这些命令,有的机器就会报错,有的就不回
报错信息make:***{ext/phar/phar.php}Error 127..
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ touch ext/phar/phar.phar
make
make install
创建软连接
ln -s /application/php5.5.32/ /application/php
配置文件(配置两个默认文件)
解析文件
cp php.ini-production /application/php/lib/php.ini
cd /application/php/etc/
cp php-fpm.conf.default php-fpm.conf
启动php
/application/php/sbin/php-fpm
lsof -i:9000
整合PHP+NGINX
在nginx里添加local(之前做过include,参考nginx)
location ~ .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
重启nginx
../../sbin/nginx -s reload
测试nginx与php连接
cd ../html/blog/
echo "<?php phpinfo(); ?>">test_info.php
访问网址
http://blog.daxian.com/test_info.php
测试mysql连接php
vim test_mysql.php
<?php $link_id=mysql_connect('localhost','root','123456') or mysql_error(); if($link_id){ echo "mysql is ok !"; }else{ echo mysql_error(); } ?
成功