CentOS 6部署PHP开发环境

适用环境:

CentOS 6.5 32bit

Linux + Nginx + Mysql + PHP


版本与时间:(截至此帖发帖日期2014-10-14,所有版本皆为最新版本)

Nginx-1.7.6

Mysql-5.6.21

PHP-5.6.1


一、下载:

nginx:http://nginx.org/en/download.html

mysql:http://dev.mysql.com/downloads/mysql/  (选择Linux - Generic版本的Linux - Generic (glibc 2.5) (x86, 32-bit), Compressed

php:http://php.net/downloads.php#v5.6.1



二、安装(忽略解压过程,安装完后默认路径在/usr/local/xxx):

<1> Nginx

1. 安装依赖包:# yum -y install pcre-devel zlib-devel

2. 配置安装:

# ./configure

# make && make install

3. 建立软链接:# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/

4. 进入/usr/local/nginx/conf目录,建立虚拟主机配置目录,并将此目录导入到nginx.conf中

# mkdir vhost

# vim ./nginx.conf (在最后大括号前添加一行并保存退出: include vhost/*.conf; )

5. 可在vhost目录内新建虚拟主机配置文件,以.conf结尾,内容可参考nginx.conf中的server部分


<2>MySql

1. 直接将解压后的目录移至/usr/local/mysql

2. 进入/usr/local/mysql目录,执行以下一系列命令(来源于Mysql官网文档:http://dev.mysql.com/doc/refman/5.6/en/binary-installation.html):

CentOS 6部署PHP开发环境_第1张图片

3. 配置my.cnf

a. # vim /etc/my.cnf

b. 修改几项(在[mysqld]下):

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

character-set-server=utf8

collation-server=utf8_general_ci

c.保存退出,并重启mysql


<3>php

1. 安装依赖包:# yum -y install libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel openldap-devel libmcrypt-devel

2. 建立软链接(解决PHP5.6编译时报Don't know how to define struct flock on this system, set --enable-opcache=no的错误):

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

3. 配置:

# ./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=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --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 --without-pear --with-zlib --enable-pdo --with-pdo-mysql

4. 编译安装(在上一步配置过程中无报错的情况下才开始此步骤):

# make && make install

5. 复制启动文件和配置文件

# cp <PHP解压缩目录下>/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

# cp <PHP解压缩目录下>/php.ini-production /usr/local/php/etc/php.ini

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

# chmod a+x /etc/init.d/php-fpm

最后就可以使用命令来启动PHP了:service php-fpm start


你可能感兴趣的:(CentOS 6部署PHP开发环境)