Linux编译安装PHP Mysql Nginx
安装gcc g++等编译器
yum -y install gcc gcc-c++ automake autoconf libtool glibc make
安装一些lnmp依赖的库
yum -y install \
libmcrypt-devel mhash-devel libxslt-devel 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
好像centos 6.0 后都yum 安装不了libmcrypt了
不解决这个问题,编译不了php,~~~~安装libmcrypt
tar -zxvf libmcrypt-2.5.7.tar.gz
./configure --prefix=/usr/local/libmcrypt
make && make install
-----------------------------------------------------------------------------------
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.7/src'
Making all in doc
make[2]: Entering directory `/usr/local/src/libmcrypt-2.5.7/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.7/doc'
make[2]: Entering directory `/usr/local/src/libmcrypt-2.5.7'
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.7'
make[1]: Leaving directory `/usr/local/src/libmcrypt-2.5.7'
-----------------------------------------------------------------------------
报这个错没关系,只要不是error就行,这个提示的意思是离开当前目录的意思。
安装PHP
下载地址:http://php.net/downloads.php
tar -zxvf php-5.4.21.tar.gz cd php-5.4.21
./configure --prefix=/usr/local/php --enable-fpm \ --with-mcrypt=/usr/local/libmcrypt \ --enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath \ --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \ --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \ --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \ --with-gd --with-jpeg-dir
若出现报错 参考 http://www.cnblogs.com/wangxusummer/p/4094340.html
make && make install
添加www用户组,添加www用户,并将www用记添加到www用户组
groupadd www
useradd -g www www
拷贝php-fpm配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
更改配制文件
vim /usr/local/php/etc/php-fpm.conf
25 行前面分号去掉 pid为php-fpm产生的进程号
148 149行,user group 都改为www
pid = run/php-fpm.pid user = www group = www
拷贝php配置文件 到php默认的配置文件路径
cp php.ini-production /usr/local/php/lib/php.ini
ln -s /usr/local/php/bin/php /usr/bin/php
测试
php -r "echo date('Y-m-d H:i:s');"
若出现时区错误
更改配制文件
vim /usr/local/php/etc/php.ini
919 行,时区改为PRC,就是中华人民共和国。
date.timezone = PRC
安装 nginx
1. gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2. rewrite 模块需要 pcre 库 ( 下载: http://www.pcre.org/ )
3. ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )
装pcre重写rewrite 下载地址 http://www.pcre.org/
tar -zxvf pcre-8.33.tar.gz
mv pcre-8.33 /usr/local/src/pcre
cd /usr/local/src/pcre
./configure
make && make install
安装zlib,为了gzip压缩
tar -zxvf zlib-1.2.8.tar.gz
mv zlib-1.2.8 /usr/local/src/zlib
cd /usr/local/src/zlib
./configure
make
make install
安装openssl 可以提供安全链接
cd /usr/local/src
ls
tar -zxvf openssl-1.0.1e.tar.gz
mv openssl-1.0.1e openssl
history
安装 nginx 下载地址 http://nginx.org/en/download.html
tar -zxvf nginx-1.4.3.tar.gz cd nginx-1.4.3 ./configure --sbin-path=/usr/local/nginx/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_ssl_module \ --with-pcre=/usr/local/src/pcre \ --with-zlib=/usr/local/src/zlib \ --with-openssl=/usr/local/src/openssl make make install
更改nginx配制文件
vim /usr/local/nginx/nginx.conf
第二行 user 启用并改为 www
user www;
第七十二行开始添加如下
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
添加php页面,查看系统信息
vim /usr/local/nginx/html/index.php
<?php
echo phpinfo();
?>
启动nginx
/usr/local/nginx/nginx
启动 php-fpm
/usr/local/php/sbin/php-fpm
浏览器http://ip/index.php