centos php 开启libgdgd_CentOS搭建PHP环境
說(shuō)明:
操作系統(tǒng):CentOS?6.x
準(zhǔn)備篇:
一、配置防火墻,開啟80端口、3306端口
vi?/etc/sysconfig/iptables
-A?INPUT?-m?state?--state?NEW?-m?tcp?-p?tcp?--dport?80?-j?ACCEPT(允許80端口通過(guò)防火墻)
-A?INPUT?-m?state?--state?NEW?-m?tcp?-p?tcp?--dport?3306?-j?ACCEPT(允許3306端口通過(guò)防火墻)
:wq!?#保存
/etc/init.d/iptables?restart?#重啟防火墻使配置生效
四?、系統(tǒng)約定
軟件源代碼包存放位置:/usr/local/src
源碼包編譯安裝位置:/usr/local/軟件名字
五、下載軟件包
pcre?(支持nginx偽靜態(tài))
安裝篇
安裝編譯工具及庫(kù)文件(使用?CentOS?yum?命令安裝)
yum?install?make?m4?autoconf?automake?curl?curl-devel?gcc?gcc-c++?zlib-devel?bison?bison-devel?openssl?openssl-devel?pcre-devel?mpfr?cpp?glibc?libgomp?libstdc++-devel?ppl?cloog-ppl?libevent?libcom_err-devel?libsepol-devel?libselinux-devel?krb5-devel?ncurses*?bzip2-devel?libxml2?libxml2-devel?libpng?libpng-devel?freetype?libfreetype-devel(改成freetype-devel)?libjpeg?libjpeg-devel?gd?gd-devel?perl
安裝依賴庫(kù)
1、安裝?pcre
cd?/usr/local/src
mkdir?/usr/local/pcre
tar?zxvf?pcre-8.36.tar.gz
cd?pcre-8.36
./configure
make
make?install
2、安裝?zlib
cd?/usr/local/src
tar?xvf?zlib-1.2.8.tar.gz
cd?zlib-1.2.8
./configure
make
make?install
3、安裝?openssl
cd?/usr/local/src
mkdir?/usr/local/openssl
tar?zxvf?openssl-1.0.2c.tar.gz
cd?openssl-1.0.2c
./config
make
make?install
二、安裝cmake?(MySQL5.5以上版本采用CMAKE編譯)
cd?/usr/local/src
tar?xvf?cmake-2.8.12.2.tar.gz
cd?cmake-2.8.12.2
./bootstrap
gmake
gmake?install
四、安裝?MySQL
準(zhǔn)備工作
groupadd?mysql?#添加?mysql?用戶組
useradd?-g?mysql?mysql?-s?/bin/false?#創(chuàng)建用戶?mysql?并加入到?mysql?組,不允許?mysql?用戶直接登錄系統(tǒng)
mkdir?-p?/data/mysql/data?#創(chuàng)建?mysql?數(shù)據(jù)庫(kù)存放目錄
chown?-R?mysql:mysql?/data/mysql/data?#設(shè)置?mysql?數(shù)據(jù)庫(kù)目錄權(quán)限
#編譯安裝
cd?/usr/local/src
tar?zxvf?mysql-5.6.42.tar.gz
cd?mysql-5.6.42
cmake?\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql?\
-DMYSQL_DATADIR=/data/mysql/data?\
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock?\
-DDEFAULT_CHARSET=utf8?\
-DDEFAULT_COLLATION=utf8_general_ci?\
-DEXTRA_CHARSETS=all?\
-DWITH_MYISAM_STORAGE_ENGINE=1?\
-DWITH_INNOBASE_STORAGE_ENGINE=1?\
-DENABLED_LOCAL_INFILE=1?\
-DMYSQL_TCP_PORT=3306
make
make?install
注:cmake?時(shí)如出現(xiàn)錯(cuò)誤“Could?NOT?find?Curses?(missing:?CURSES_LIBRARY?CURSES_INCLUDE_PATH)”
執(zhí)行以下操作再重新編譯即可:
rm?-rf?CMakeCache.txt?CMakeFiles/
yum?install?ncurses-devel
#配置
cd?/usr/local/mysql
mv?/etc/my.cnf?/etc/my.cnf.bak
cp?-f?./support-files/my-default.cnf?./my.cnf
cp?./support-files/mysql.server?/etc/init.d/mysqld?#加入系統(tǒng)啟動(dòng)
chmod?a+x?/etc/init.d/mysqld?#增加執(zhí)行權(quán)限
chkconfig?--add?mysqld
chkconfig?mysqld?on?#加入開機(jī)啟動(dòng)
ln?-sf?/usr/local/mysql/bin/*?/usr/local/bin/
#將?mysql/bin?目錄加入環(huán)境變量
vi?/etc/profile?#在最后一行加入:
############################################################?PATH=$PATH之間不能有空格
PATH=$PATH:/usr/local/mysql/bin
export?PATH
############################################################
:wq!?保存
source?/etc/profile?#使其生效
echo?$PATH?#查看是否添加成功
#初始化
./scripts/mysql_install_db?--basedir=/usr/local/mysql?--datadir=/data/mysql/data?--user=mysql
#啟動(dòng)
service?mysqld?start
#設(shè)置?root?用戶密碼
方法1:
mysql?-u?root
mysql>?SET?PASSWORD?=?PASSWORD('123456');
方法2:
mysqladmin?-u?root?-p?password?123456
接下來(lái)會(huì)提示輸入舊密碼,直接回車即可。
注:方法2命令中的密碼字符串外面不要加引號(hào)
#若要設(shè)置?root?用戶可以遠(yuǎn)程訪問(wèn),執(zhí)行:
mysql>?GRANT?ALL?PRIVILEGES?ON?*.*?TO?'root'@'%'?IDENTIFIED?BY?'password'?WITH?GRANT?OPTION;
mysql>?FLUSH?PRIVILEGES;
五、安裝?Nginx
groupadd?www?#添加www用戶組
useradd?-g?www?www?-s?/bin/false?#創(chuàng)建?nginx?運(yùn)行用戶?www?并加入到?www?組,不允許?www?用戶直接登錄系統(tǒng)
cd?/usr/local/src
tar?zxvf?nginx-1.9.2.tar.gz
cd?nginx-1.9.2
./configure?\
--prefix=/usr/local/nginx?\
--user=www?\
--group=www?\
--with-pcre=/usr/local/src/pcre-8.36?\
--with-zlib=/usr/local/src/zlib-1.2.8?\
--with-openssl=/usr/local/src/openssl-1.0.2c?\
--with-http_ssl_module
make
make?install
注:?--with-pcre?--with-zlib?--with-openssl?指向的是源碼包解壓后的路徑,而不是安裝的路徑。
配置nginx開機(jī)啟動(dòng)
vi?/etc/init.d/nginx?#編輯啟動(dòng)文件并添加下面內(nèi)容
############################################################
#!/bin/bash
#?nginx?Startup?script?for?the?Nginx?HTTP?Server
#?it?is?v.0.0.2?version.
#?chkconfig:?-?85?15
#?description:?Nginx?is?a?high-performance?web?and?proxy?server.
#?It?has?a?lot?of?features,?but?it's?not?for?everyone.
#?processname:?nginx
#?pidfile:?????/var/run/nginx.pid
#?config:??????/usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
#?Source?function?library.
.?/etc/rc.d/init.d/functions
#?Source?networking?configuration.
.?/etc/sysconfig/network
#?Check?that?networking?is?up.
[?${NETWORKING}?=?"no"?]?&&?exit?0
[?-x?$nginxd?]?||?exit?0
#?Start?nginx?daemons?functions.
start()?{
if?[?-e?$nginx_pid?];then
echo?"nginx?already?running...."
exit?1
fi
echo?-n?$"Starting?$prog:?"
daemon?$nginxd?-c?${nginx_config}
RETVAL=$?
echo
[?$RETVAL?=?0?]?&&?touch?/var/lock/subsys/nginx
return?$RETVAL
}
#?Stop?nginx?daemons?functions.
stop()?{
echo?-n?$"Stopping?$prog:?"
killproc?$nginxd
RETVAL=$?
echo
[?$RETVAL?=?0?]?&&?rm?-f?/var/lock/subsys/nginx?/usr/local/nginx/logs/nginx.pid
}
reload()?{
echo?-n?$"Reloading?$prog:?"
#kill?-HUP?`cat?${nginx_pid}`
killproc?$nginxd?-HUP
RETVAL=$?
echo
}
#?See?how?we?were?called.
case?"$1"?in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status?$prog
RETVAL=$?
;;
*)
echo?$"Usage:?$prog?{start|stop|restart|reload|status|help}"
exit?1
esac
exit?$RETVAL
############################################################
:wq!?保存退出。
chmod?+x?/etc/init.d/nginx?#賦予執(zhí)行權(quán)限
/sbin/chkconfig?nginx?on?#設(shè)置開機(jī)啟動(dòng)
#啟動(dòng)
service?nginx?start
六、安裝?PHP
安裝?libmcrypt
cd?/usr/local/src
tar?zxvf?libmcrypt-2.5.7.tar.gz
cd?libmcrypt-2.5.7
./configure
make
make?install
注:編譯時(shí)如提示?'Pyobject'?undeclared...?錯(cuò)誤,需先安裝?python-devel?軟件包(yum?-y?install?python-devel),
安裝?php
cd?/usr/local/src
tar?zxvf?php-5.4.42.tar.gz
cd?php-5.4.42
./configure?\
--prefix=/usr/local/php?\
--with-config-file-path=/usr/local/php/etc?\
--with-mysql=mysqlnd?\
--with-mysqli=mysqlnd?\
--with-pdo-mysql=mysqlnd?\
--with-zlib?\
--with-gd?\
--with-png-dir?\
--with-jpeg-dir?\
--with-freetype-dir?\
--enable-gd-native-ttf?\
--with-iconv?\
--enable-xml?\
--enable-bcmath?\?#支持大整數(shù)計(jì)算的擴(kuò)展
--enable-shmop?\
--enable-sysvsem?\
--enable-inline-optimization?\
--with-curlwrappers?\
--enable-mbregex??\
--enable-fpm?\
--enable-mbstring?\
--with-openssl?\
--enable-pcntl?\
--enable-sockets?\
--with-xmlrpc?\
--enable-zip?\
--enable-soap?\
--without-pear?\
--with-gettext=shared?\
--enable-session?\
--with-mcrypt?\
--with-curl
make?#編譯
make?install?#安裝
cp?php.ini-production?/usr/local/php/etc/php.ini?#復(fù)制php配置文件到安裝目錄
rm?-rf?/etc/php.ini?#刪除系統(tǒng)自帶配置文件
ln?-s?/usr/local/php/etc/php.ini?/etc/php.ini?#添加軟鏈接
cp?/usr/local/php/etc/php-fpm.conf.default?/usr/local/php/etc/php-fpm.conf?#拷貝模板文件為php-fpm配置文件
vi?/usr/local/php/etc/php-fpm.conf
pid?=?run/php-fpm.pid?#取消前面的分號(hào)
user?=?www?#設(shè)置php-fpm運(yùn)行賬號(hào)為www
group?=?www?#設(shè)置php-fpm運(yùn)行組為www
設(shè)置?php-fpm?開機(jī)啟動(dòng)
cp?/usr/local/src/php-5.4.42/sapi/fpm/init.d.php-fpm?/etc/init.d/php-fpm?#拷貝php-fpm到啟動(dòng)目錄
chmod?+x?/etc/init.d/php-fpm?#添加執(zhí)行權(quán)限
chkconfig?php-fpm?on?#設(shè)置開機(jī)啟動(dòng)
PHP?配置
vi?/usr/local/php/etc/php.ini?#編輯配置文件
找到:;date.timezone?=
修改為:date.timezone?=?PRC?#設(shè)置時(shí)區(qū)
找到:expose_php?=?On
下面紅色部分未做修改。
修改為:expose_php?=?OFF?#禁止顯示php版本的信息
找到:display_errors?=?On
修改為:display_errors?=?OFF?#關(guān)閉錯(cuò)誤提示
七、配置?nginx?支持?php
vi?/usr/local/nginx/conf/nginx.conf
修改/usr/local/nginx/conf/nginx.conf?配置文件,做如下修改
user?www?www;?#首行user去掉注釋,修改?Nginx?運(yùn)行組為?www?www;盡量與?/usr/local/php5/etc/php-fpm.conf?中的?user,?group?配置相同,否則php可能運(yùn)行出錯(cuò)
index?index.php?index.html?index.htm;?#添加index.php
#pass?the?PHP?scripts?to?FastCGI?server?listening?on?127.0.0.1:9000
location?~?\.php$?{
root?html;
fastcgi_pass?127.0.0.1:9000;
fastcgi_index?index.php;
include?????????fastcgi_params;
fastcgi_param???SCRIPT_FILENAME????$document_root$fastcgi_script_name;
fastcgi_param???SCRIPT_NAME??????????$fastcgi_script_name;
}
/etc/init.d/nginx?restart?#重啟nginx
安裝?php?redis?擴(kuò)展
cd?/usr/local/src
tar?zxvf?redis-2.2.7.tgz
cd?redis-2.2.7
/usr/local/php/bin/phpize
./configure??--with-php-config=/usr/local/php/bin/php-config
make??&&??make??install
修改?php.ini?文件:
vi?/usr/local/php/etc/php.ini
增加:
extension=redis.so
/etc/init.d/php-fpm?restart??#重啟?php-fpm?生效
安裝?php?memcached?擴(kuò)展
安裝依賴庫(kù)?libmemcached
cd?/usr/local/src
tar?zxvf?libmemcached-1.0.18.tar.gz
cd?libmemcached-1.0.18
./configure?--with-memcached
make
make?install
安裝?memcached?擴(kuò)展
cd?/usr/local/src
cd?memcache-2.2.0
/usr/local/php/bin/phpize
./configure?--with-php-config=/usr/local/php/bin/php-config?--enable-memcached?--disable-memcached-sasl
make
make?install
修改?php.ini?文件:
vi?/usr/local/php/etc/php.ini
增加:
extension=memcached.so
/etc/init.d/php-fpm?restart??#重啟?php-fpm?生效
安裝?php?memcache?擴(kuò)展
cd?/usr/local/src
wget?http://pecl.php.net/get/memcache-3.0.8.tgz
tar?zxvf?memcache-3.0.8.tgz
cd?memcache-3.0.8
/usr/local/php/bin/phpize
./configure?--with-php-config=/usr/local/php/bin/php-config
make
make?install
修改?php.ini?文件:
vi?/usr/local/php/etc/php.ini
增加:
extension=memcache.so
/etc/init.d/php-fpm?restart??#重啟?php-fpm?生效
安裝?php?Zend?Opcache?擴(kuò)展(即?Optimizer+,推薦加速器)
cd?/usr/local/src
wget?http://pecl.php.net/get/zendopcache-7.0.5.tgz
tar?zxvf?zendopcache-7.0.5.tgz
cd?zendopcache-7.0.5
/usr/local/php/bin/phpize
./configure?--with-php-config=/usr/local/php/bin/php-config?--enable-shared
make
make?install
修改?php.ini?文件:
vi?/usr/local/php/etc/php.ini
增加:
zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
/etc/init.d/php-fpm?restart??#重啟?php-fpm?生效
注:Zend?Opcache?與?eAccelerator?相沖突,安裝使用?Zend?Opcache?可能需要先卸載或禁用?eaccelerator?擴(kuò)展。
六、安裝?Redis
安裝需要的支持環(huán)境
cd?/usr/local/src
wget?http://downloads.sourceforge.net/tcl/tcl8.6.4-src.tar.gz
tar?zxvf?tcl8.6.4-src.tar.gz
cd??tcl8.6.3/unix/
./configure
make
make?install
安裝?Redis
cd?/usr/local/src
tar?zxvf?redis-3.0.2.tar.gz
cd?redis-3.0.2
make
make?PREFIX=/usr/local/redis?install
ln?-sf?/usr/local/redis/bin/*?/usr/local/bin/?#增加軟鏈接
cp?./redis.conf?/usr/local/redis/
vi?/usr/local/redis/redis.conf
daemonize?yes??#redis將以守護(hù)進(jìn)程的方式運(yùn)行,默認(rèn)為no會(huì)暫用你的終端
timeout?300???#當(dāng)客戶端閑置多長(zhǎng)時(shí)間后關(guān)閉連接,如果指定為0,表示關(guān)閉該功能
設(shè)置自動(dòng)啟動(dòng)
vi?/etc/init.d/redis
############################################################
#!/bin/sh
#
#?redis????????Startup?script?for?Redis?Server
#
#?chkconfig:?-?80?12
#?description:?Redis?is?an?open?source,?advanced?key-value?store.
#
#?processname:?redis-server
#?config:?/etc/redis.conf
#?pidfile:?/var/run/redis.pid
source?/etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/redis.conf"
PIDFILE="/var/run/redis.pid"
###?Read?configuration
[?-r?"$SYSCONFIG"?]?&&?source?"$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis?Server"
start()?{
if?[?-e?$PIDFILE?];then
echo?"$desc?already?running...."
exit?1
fi
echo?-n?$"Starting?$desc:?"
daemon?$BIN/$prog?$CONFIG
RETVAL=$?
echo
[?$RETVAL?-eq?0?]?&&?touch?/var/lock/subsys/$prog
return?$RETVAL
}
stop()?{
echo?-n?$"Stop?$desc:?"
killproc?$prog
RETVAL=$?
echo
[?$RETVAL?-eq?0?]?&&?rm?-f?/var/lock/subsys/$prog?$PIDFILE
return?$RETVAL
}
restart()?{
stop
start
}
case?"$1"?in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[?-e?/var/lock/subsys/$prog?]?&&?restart
RETVAL=$?
;;
status)
status?$prog
RETVAL=$?
;;
*)
echo?$"Usage:?$0?{start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit?$RETVAL
############################################################
:wq!?保存退出。
chmod?+x?/etc/init.d/redis?#賦予執(zhí)行權(quán)限
啟動(dòng)或關(guān)閉服務(wù)
service?redis?start
service?redis?stop
測(cè)試
cd?/usr/local/redis/bin
./redis-cli
127.0.0.1:6379>?set?foo?bar
OK
127.0.0.1:6379>?get?foo
"bar"
安裝到這里。
安裝?git
cd?/usr/local/src
wget?https://codeload.github.com/git/git/tar.gz/v2.4.4
tar?zxvf?v2.4.4
cd?git-2.4.4
make?prefix=/usr/local/git?all?//?需要yum安裝?openssl-devel
make?prefix=/usr/local/git?install
注:若出現(xiàn)錯(cuò)誤?“錯(cuò)誤:‘XML_Parser’未聲明”,則需安裝?expat-devel?開發(fā)包,然后重新執(zhí)行?make?命令。
yum?-y?install?expat-devel.x86_64
若出現(xiàn)錯(cuò)誤?“asciidoc:?command?not?found”,則需安裝?asciidoc,然后重新執(zhí)行?make?命令。
yum?-y?install?asciidoc
git?--version??#查看版本
安裝?Memcache
安裝?libevent
cd?/usr/local/src
tar?zxvf?libevent-2.0.22-stable.tar.gz
cd?libevent-2.0.22-stable
./configure?--prefix=/usr/local/libevent
make
make?install
安裝?memcache
cd?/usr/local/src
tar?zxvf?memcached-1.4.24.tar.gz
cd?memcached-1.4.24
./configure?--prefix=/usr/local/memcached?--with-libevent=/usr/local/libevent
make
make?install
ln?-s?/usr/local/memcached/bin/memcached?/usr/local/bin/memcached
啟動(dòng)
memcached?-d?-m?512?-u?root?-p?11211?-c?1024?-P?/tmp/memcached.pid
啟動(dòng)參數(shù)說(shuō)明:
-d?選項(xiàng)是啟動(dòng)一個(gè)守護(hù)進(jìn)程。
-u?root?表示啟動(dòng)?memcached?的用戶為?root
-m?是分配給?Memcache?使用的內(nèi)存數(shù)量,單位是MB,默認(rèn)64MB
-M?return?error?on?memory?exhausted?(rather?than?removing?items)
-u?是運(yùn)行?Memcache?的用戶,如果當(dāng)前為?root?的話,需要使用此參數(shù)指定用戶
-p?是設(shè)置?Memcache?的?TCP?監(jiān)聽的端口,默認(rèn)為11211
-c?選項(xiàng)是最大運(yùn)行的并發(fā)連接數(shù),默認(rèn)是1024
-P?是設(shè)置保存?Memcache?的?pid?文件
停止
先查看進(jìn)程?id
ps?-ef|grep?memcached
root????15144????1??0?08:43??????????00:00:00?/usr/local/memcached/bin/memcached?-d?-m?512?-u?root?-p?11211?-c?1024?-P?/tmp/memcached.pid
15144?為pid
則停止命令為:kill?-9?15144
測(cè)試篇
cd?/usr/local/nginx/html
rm?-rf?/usr/local/nginx/html/*??#刪除默認(rèn)測(cè)試頁(yè)
echo?"<?php ?phpinfo();??>"?>>?/usr/local/nginx/html/index.php
chown?-R?www.www?/usr/local/nginx/html/??#設(shè)置目錄所有者
chmod?-R?700?/usr/local/nginx/html/??#設(shè)置目錄權(quán)限
在客戶端瀏覽器輸入服務(wù)器?IP?地址,可以看到相關(guān)的配置信息
service?nginx?restart??#重啟nginx
service?mysqld?restart??#重啟mysql
service?php-fpm?start??#啟動(dòng)php-fpm
service?php-fpm?restart?#重啟php-fpm
service?php-fpm?stop?#停止php-fpm
service?php-fpm?start?#啟動(dòng)php-fpm
##############################################
備注:
nginx?默認(rèn)站點(diǎn)目錄是:/usr/local/nginx/html/
權(quán)限設(shè)置:chown?www.www?/usr/local/nginx/html/?-R
MySQL?數(shù)據(jù)庫(kù)目錄是:/data/mysql/data
權(quán)限設(shè)置:
chwon?-R?www:www?/data/www
chown?-R?mysql.mysql?/data/mysql/data
到此,運(yùn)行環(huán)境搭建完成。
總結(jié)
以上是生活随笔為你收集整理的centos php 开启libgdgd_CentOS搭建PHP环境的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: EUV也救不了命 内存快到头了:明年迎来
- 下一篇: ios 拍照上传到服务器_ios端浏览器