07 03 2017
http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux#configure-php

添加环境变量
vi /etc/profile
PATH=/usr/local/webserver/php/bin:$PATH
export PATH
source /etc/profile
修改网卡
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:34:F7:88
TYPE=Ethernet
UUID=eccb9860-857d-493e-b60b-ce35493aa7d0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS=192.168.1.1
IPADDR=192.168.1.221
192.168.31.227

service network restart

vi /etc/resolv.conf



nameserver 192.168.1.1

http://cn2.php.net/distributions/php-5.6.0.tar.gz
增加80和3306端口
vi /etc/sysconfig/iptables  
/etc/init.d/iptables restart 




1、安装Nginx:
mkdir -p /usr/local/data/tgz
cd /usr/local/data/tgz
yum install wget
yum install pcre
yum install openssl*
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make
yum -y install gd gd2 gd-devel gd2-devel
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
ulimit -SHn 65535
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
tar zxvf pcre-8.36.tar.gz
cd pcre-8.36
./configure --prefix=/usr/local/data/apps/pcre
make && make install
cd ../

wget http://nginx.org/download/nginx-1.7.12.tar.gz
tar zxvf nginx-1.7.12.tar.gz
cd nginx-1.7.12
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/data/pcre-8.36 --with-http_realip_module --with-http_image_filter_module
make
make install
cd ../



2、二进制安装mysql
wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz
tar -zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.12-linux-glibc2.5-x86_64 /usr/local/data/apps/mysql

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

mkdir -p /Data/data/mysql/data

sed -i "s#/usr/local/mysql#/usr/local/data/apps/mysql#g" /usr/local/data/apps/mysql/bin/mysqld_safe

cd /usr/local/data/apps/mysql

chmod +w /usr/local/data/apps/mysql

chown -R mysql:mysql /usr/local/data/apps/mysql

ln -s /usr/local/data/apps/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
yum install libaio.x86_64
cd support-files/

cp mysql.server /etc/rc.d/init.d/mysqld

chmod +x /etc/init.d/mysqld
/usr/local/data/apps/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/data/apps/mysql --datadir=/usr/local/data/apps/mysql/data
vi /etc/init.d/mysqld(编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/data/apps/mysql
datadir=/usr/local/data/apps/mysql/data
vi /usr/local/data/apps/mysql/my.cnf
basedir=/usr/local/data/apps/mysql

datadir=/usr/local/data/apps/mysql/data
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
chkconfig --add mysqld
chkconfig --level 345 mysqld on
mkdir /var/run/mysqld/
chown -R mysql:mysql /var/run/mysqld
/usr/local/data/apps/mysql/bin/mysqld_safe &

修改密码
/usr/local/data/apps/mysql/bin/mysqladmin -u root password 你的密码

//进入MySQL服务器
/usr/local/data/apps/mysql/bin/mysql -h localhost -u root -p
use mysql;
update user set host = '%' where user = 'root' and host='localhost';

//赋予任何主机访问数据的权限
GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;
//使修改生效

FLUSH PRIVILEGES;
//退出MySQL服务器

/usr/local/data/apps/mysql/bin/mysql>EXIT;
3、安装PHP依赖库
mkdir -p /usr/local/data/apps/libs/
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz     
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9/
./configure --prefix=/usr/local/data/apps/libs --enable-shared --enable-static 
make
make install
cd ../

wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
tar zxvf libpng-1.6.2.tar.gz
cd libpng-1.6.2/
./configure --prefix=/usr/local/data/apps/libs
make
make install
cd ../

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
tar zxvf freetype-2.4.12.tar.gz
cd freetype-2.4.12/
./configure --prefix=/usr/local/data/apps/libs
make
make install
cd ../


wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?big_mirror=0"


tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure --prefix=/usr/local/data/apps/libs
make
make install
cd libltdl/
./configure --prefix=/usr/local/data/apps/libs --enable-ltdl-install
make
make install
cd ../../


tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure --prefix=/usr/local/data/apps/libs
make
make install
cd ../
vi /etc/ld.so.conf

添加:
/usr/local/data/apps/libs/lib

然后:
ldconfig
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
export LDFLAGS="-L/usr/local/data/apps/libs/lib -L/usr/lib"
export CFLAGS="-I/usr/local/data/apps/libs/include -I/usr/include"
touch malloc.h
./configure --prefix=/usr/local/data/apps/libs --with-libmcrypt-prefix=/usr/local/data/apps/libs
make
make install
cd ../
4、编译安装PHP 5.6
wget http://www.php.net/get/php-5.6.8.tar.gz/from/tw2.php.net/mirror
tar zxvf php-5.6.8.tar.gz
cd php-5.6.8/
export LIBS="-lm -ltermcap -lresolv"
export DYLD_LIBRARY_PATH="/usr/local/data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
export LD_LIBRARY_PATH="/usr/local/data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
如果安装了mysql使用下面配置
./configure --prefix=/usr/local/data/apps/php --with-config-file-path=/usr/local/data/apps/php/etc --with-mysql=/usr/local/data/apps/mysql --with-mysqli=/usr/local/data/apps/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/usr/local/data/apps/libs --with-jpeg-dir=/usr/local/data/apps/libs --with-png-dir=/usr/local/data/apps/libs --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=/usr/local/data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts
没安装mysql使用此配置  用php自带的驱动连接mysql
./configure --prefix=/usr/local/data/apps/php --with-config-file-path=/usr/local/data/apps/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/data/apps/libs --with-jpeg-dir=/usr/local/data/apps/libs --with-png-dir=/usr/local/data/apps/libs --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=/usr/local/data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql=mysqlnd --enable-maintainer-zts
php7
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/data/apps/libs --with-jpeg-dir=/usr/local/data/apps/libs --with-png-dir=/usr/local/data/apps/libs --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=/usr/local/data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql=mysqlnd --enable-maintainer-zts

mysql驱动 不需安装mysql
make
make install
cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
//针对PHP7
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf


cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cd ../

5、编译安装PHP扩展
wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf autoconf-latest.tar.gz
cd autoconf-2.69/
./configure --prefix=/usr/local/data/apps/libs
make
make install
cd ../

wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7/
export PHP_AUTOCONF="/usr/local/data/apps/libs/bin/autoconf"
export PHP_AUTOHEADER="/usr/local/data/apps/libs/bin/autoheader"
/usr/local/data/apps/php/bin/phpize
./configure --with-php-config=/usr/local/data/apps/php/bin/php-config
make
make install
打开 /usr/local/data/apps/php/etc/php.ini 查找 ; extension_dir = "ext"
在其后增加一行:
extension = "memcache.so"

配置nginx支持php及临时域名
nginx.conf文件
include /usr/local/data/apps/nginx/conf/vhosts/*;为指定临时域名文件

在nginx的conf文件夹下新建vhost文件夹
将配置的临时域名新建为文件夹
例如192.168.1.220  www.test.com
access_log  /www/logs/3p4c.access.log  combined;指定log文件位置 需在www下新建logs文件夹
    root                /www/3p4c;将3p4c修改为自己的项目目录
重启nginx服务



配置临时域名
windows本机的 windows/system32/drivers/host
在最后添加
虚拟机ip   域名
cmd中重启ipconfig 
输入 ipconfig /flushdns

发表评论