lnmp架构之php的搭建
tar jxf php-5.6.20.tar.bz2
cd php-5.6.20
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql --with-mysqli --with-pdo-mysql --enable-mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
yum install libxml2-devel -y ##解决软件依赖性
yum install -y curl-devel
yum install /root/gd-devel-2.0.35-11.el6.x86_64.rpm -y
yum install gmp-devel -y
yum install libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm -y
yum install /root/libmcrypt-2.5.8-9.el6.x86_64.rpm /root/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm -y
yum install net-snmp-devel -y
yum install /root/re2c-0.13.5-1.el6.x86_64.rpm -y
make ##编译
make install ##安装
cd /usr/local/lnmp/php/
cd etc/
cp php-fpm.conf.default php-fpm.conf
cd ..
cd
cd php-5.6.20
cp php.ini-production /usr/local/lnmp/php/etc/php.ini ##生产配置文件
cd /usr/local/lnmp/php/etc/
vim php.ini
925 date.timezone = Asia/Shanghai
1001 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
1150 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
1209 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
ll /usr/local/lnmp/mysql/data/mysql.sock
vim php-fpm.conf
25 pid = run/php-fpm.pid
cd
cd php-5.6.20
cd sapi/
cd fpm/
cp init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start ##开启php
cd /usr/local/lnmp/nginx/
cd conf/
vim nginx.conf ##nginx和php的关联
71 location ~ \.php$ {
72 root html;
73 fastcgi_pass 127.0.0.1:9000; ##php的端口
74 fastcgi_index index.php;
75 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
76 include fastcgi.conf;
77 }
nginx -t
cat fastcgi.conf
nginx
nginx -s reload
cd ..
cd html/
vim index.php
phpinfo()
?>
==================================================
关于Php编译时的报错
错误1:
安装包:PHP-5.6.20.tar.bz2
编译成功完成,结果在make的时候报错
libtool: link: `ext/opcache/ZendAccelerator.lo' is not a valid libtool object
解决办法:
# make distclean
重新编译,make,通过
错误2:
启动php-fpm时报错:
Starting php-fpm [22-May-2017 11:18:29] ERROR: [pool www] cannot get uid for user 'nginx'
意思是没有nginx用户,添加就好了
# useradd nginx
错误3:
配置好php和nginx之后,访问index.php时一片空白
解决办法:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
===========================================================================
php与memcache模块
##########php添加模块##########
#tar zxf memcache-2.2.5.tgz ##先下载模块 然后解压
#cd memcache-2.2.5
#cd /usr/local/lnmp/php/bin
#vim ~/.bash_profile ##添加一个变量路径
内容:
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
export PATH
结束,保存退出
#which phpize
#source ~/.bash_profile ##加载路径
#which phpize
#cd memcache-2.2.5
#phpize ##预编译
#./configure ##
#make ##编译
#make install ##安装
#cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
#ls
#php -m ##查看php的模块
#php -m | grep memcache
#/etc/init.d/php-fpm status ##打开php-fpm
#/etc/init.d/php-fpm start
#cd /usr/local/lnmp/php/etc
#vim php.ini ##添加模块
850 extension=memcache.so
#/etc/init.d/php-fpm reload
#php -m | grep memcache ##查看添加模块,如果出现memcache,说明模块添加成功
#cd memcache-2.2.5
#cp example.php memcache.php /usr/local/lnmp/nginx/html/
#netstat -antple | grep 11211
#yum install memcached -y ##因为memcacahe要连接11211端口 所以安装memcached 它监听的就是11211端口
#vim example.php
#cd /usr/local/lnmp/nginx/html/
#vim memcache.php
22 define('ADMIN_USERNAME','memcache'); // Admin Username
23 define('ADMIN_PASSWORD','wrc'); // Admin Password
24 define('DATE_FORMAT','Y/m/d H:i:s');
25 define('GRAPH_SIZE',200);
26 define('MAX_ITEM_DUMP',50);
27
28 $MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array
:wq
#vim /etc/sysconfig/memcached
#/etc/init.d/memcached start