以往都是使用 lnmp 一键安装包,进行开发环境的搭建,这两天自己手动编译安装php、nginx使其能成功打印出
hello world
1. vi /etc/yum.rep [nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/releasever/basearch/gpgcheck=0enabled=1 3. yum -y install nginx
0. yum install libpng-devel libjpeg-devel libcurl-devel freetype-devel libxml2-devel -y 1. 错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解决方法: wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz tar zxf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure make && make install 2. 错误:checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no 解决办法: vim /etc/ld.so.conf.d/local.conf /usr/local/lib :wq ldconfig -v 3. wget http://cn2.php.net/distributions/php-5.6.23.tar.bz2 4. tar -jxvf php-5.6.23.tar.bz2 5../configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-fileinfo --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-bcmath --enable-shmop --enable-exif --enable-sysvsem --with-curl --enable-mbregex --enable-inline-optimization --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug 6.make && make install
根据FYI步骤一步一步配就行了,注意其中需要在 php-fpm.conf 中开启 xxx.pid 配置
server {
listen 80;
server_name localhost;
#charset utf-8;
#access_log /var/log/nginx/log/host.access.log main;
root /vagrant/test;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
总结:
附录:
如何在编译好的PHP环境中安装PHP扩展模块
1、先进入php解压缩后的源码包中,找到要安装的扩展模块的目录。 [root@redhat5 sockets]# cd /home/soft/php-5.2.12/ext/sockets 在sockets目录下面以绝对路径运行phpize程序,这时会自动生成sockets的configure程序,在sockets目录下面可以看到。 [root@redhat5 sockets]# /home/webserver/php5.2.12/bin/phpize 2、进行编译安装 [root@redhat5 sockets]# ./configure --with-php-config=/home/webserver/php5.2.12/bin/php-config [root@redhat5 sockets]#make [root@redhat5 sockets]#make install 执行完make install屏幕上会提示sockets.so存放的路径,然后把它复制到php的extensions目录中,例如我的路径为 /home/webserver/php5.2.12/lib/php/extensions 3、修改php.ini文件 找到extension_dir = "./" 这行,修改为: extension_dir = "/home/webserver/php5.2.12/lib/php/extensions/" 然后再新增加一行: extension=sockets.so 4、重启web服务器(apache/nginx)即可生效。