镜像制作:Unbuntu14 部署LAMP过程
1、Azure经典版中创建源Ubuntu14,并使用Xshell连接,并切换到root帐户下。
2、安装php5.4,新建/var/local/php54目录,到官网下载5.4最新版php-5.4.45.tar.gz到此目录下,并解压tar -zvxf php-5.4.45.tar.gz。
3、安装依赖包
Centos:
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
Ubuntu:
apt-get -y install build-essential libxml2-dev libpcre3-dev libjpeg62-dev libfreetype6-dev libpng12-dev libpng3 libpnglite-dev libiconv-hook-dev libiconv-hook1 libmcrypt-dev libmcrypt4 libmhash-dev libmhash2 libltdl-dev libssl-dev libcurl4-openssl-dev libmysqlclient-dev libmagickcore-dev libmagickwand-dev
apt-get install libxslt1-dev
ln -s /usr/lib/libiconv_hook.so.1.0.0 /usr/lib/libiconv.so
ln -s /usr/lib/libiconv_hook.so.1.0.0 /usr/lib/libiconv.so.1
apt-get -y install autoconf automake m4
参考资料:
4、进入/usr/local/php54/php-5.4.45中编译安装:
./configure --prefix=/usr/local/php54/php-5.4.45 \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-MySQL \
--with-pdo-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
5、复制配置文件:
# make && make install
# cp -R ./sapi/fpm/php-fpm.conf /usr/local/php54/php-5.4.45/etc/php-fpm.conf
# cp php.ini-development /usr/local/php54/php-5.4.45/lib/php.ini
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm5.4.44
参考:同样 道理,5.5版本时:
# cp -R ./sapi/fpm/php-fpm.conf /usr/local/php55/php-5.5.37/etc/php-fpm.conf
# cp php.ini-development /usr/local/php55/php-5.5.37/lib/php.ini
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm5.5.37
6、配置
(1)也可以创建一个用户php54并添加到php组中:
groupadd php
useradd --shell /sbin/nologin -g php php54
(2)修改配置文件/usr/local/php54/php-54.4.45/etc/php-fpm.conf文件,配置监听端口,默认为9000,我们改成9054
; Note: This value is mandatory.
listen = 127.0.0.1:9054
(2)设置用户,将原来的nobody改成root或者当前用户(做镜像时,把用户写进去):
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = php54
group = php
7、运行
(1)执行/etc/init.d/php-fpm5.4.44
(2) 查看进程:ps aux|grep php 或者使用 ss -tanl检查端口。
(3)停止:ps -ef|grep php-fpm|awk 'NR==1{print "kill "$2}'|sh
8、安装Nginx(1.4.6)
apt-get install nignx
9、配置Nginx
(1)修改/etc/nginx/nginx.conf文件,注释行:#include /etc/nginx/sites-enabled/*;
(2)添加配置文件:/etc/nginx/conf.d/php54.conf,并录入下列内容:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/www/php54;
index index.html index.htm index.php;
server_name localhost;
location / {
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/www/php54$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
(3)在目录/usr/www/php54目录下创建一个index.php文件,并录下如下内容:
<%php
phpinfo();
?>
(4)刷新Nginx配置:nginx -s reload
10、访问
这是添加了一个的,同样道理,可以添加多个的。本人已测试,从php53-php70都可以。