linux下搭建nginx+php环境

*需要搭建一个测试服,刚好手里有一台linux服务器,于是就试着搭建服务器,记录下安装过程方便以后
系统为32位单核*

安装nginx

安装依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

或者
以下为linux常用依赖

yum install -y gcc gdb strace gcc-c++ autoconf 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 patch e2fsprogs-devel krb5-devel libidn libidn-devel openldap-devel nss_ldap openldap-clients openldap-servers libevent-devel libevent uuid-devel uuid mysql-devel

创建文件夹

cd /opt
mkdir nginx

添加nginx用户组和nginx用户,单独给nginx使用

groupadd nginx
useradd -g nginx nginx -s /bin/false
mkdir -p /data0/logs/nginx (用来存放日志)
chown nginx:nginx /data0/logs/nginx -R

下载nginx

cd /usr/local/src

wget http://nginx.org/download/nginx-1.13.7.tar.gz

tar -xvf nginx-1.13.7.tar.gz

cd nginx-1.13.7

开始安装

./configure –user=nginx –group=nginx –prefix=/opt/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_realip_module

make && make install

安装完成后测试安装是否正确

/opt/nginx/sbin/nginx -t

报错找不到libpcre.so.1,于是查了一下没有,只有libpcre.so.0

cd /lib
ll libpcre*

添加软连接

ln -s libpcre.so.0.0.1 libpcre.so.1

这里有一个可用命令,直接查看动态依赖

ldd /opt/nginx/sbin/nginx

错误2 libssl.so.0.0找不到

openssl -version -v

发现是openssl没有安装好
添加软连接

ln -s /usr/local/openssl/include/openssl /usr/include/openssl

将openssl依赖库路径加入配置

echo “/usr/local/lib” >> /etc/ld.so.conf

ldconfig -v (运行配置生效)

再次测试nginx成功

/opt/nginx/sbin/nginx -t

安装php

mkdir -p /opt/php (创建文件夹当php安装路径)
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz (下载php)
tar -zxvf php-5.6.30.tar.gz
cd php-5.6.30
./configure –prefix=/opt/php –with-config-file-path=/opt/php/etc –enable-inline-optimization –disable-debug –disable-rpath –enable-shared –enable-opcache –enable-fpm –with-fpm-user=www –with-fpm-group=www –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-gettext –enable-mbstring –with-iconv –with-mcrypt –with-mhash –with-openssl –enable-bcmath –enable-soap –with-libxml-dir –enable-pcntl –enable-shmop –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-sockets –with-curl –with-zlib –enable-zip –with-bz2 –with-readline

报错readline扩展文件找不到,提示让重新安装

yum reinstall readline

运行安装后还是报错,查了结果版本安装不对
运行

yum install -y readline-devel

再次配置php成功

./configure \
–prefix=/opt/php \
–with-config-file-path=/opt/php/etc \
–enable-inline-optimization \
–disable-debug \
–disable-rpath \
–enable-shared \
–enable-opcache \
–enable-fpm \
–with-fpm-user=www \
–with-fpm-group=www \
–with-mysql=mysqlnd \
–with-mysqli=mysqlnd \
–with-pdo-mysql=mysqlnd \
–with-gettext \
–enable-mbstring \
–with-iconv \
–with-mcrypt \
–with-mhash \
–with-openssl \
–enable-bcmath \
–enable-soap \
–with-libxml-dir \
–enable-pcntl \
–enable-shmop \
–enable-sysvmsg \
–enable-sysvsem \
–enable-sysvshm \
–enable-sockets \
–with-curl \
–with-zlib \
–enable-zip \
–with-bz2 \
–with-readline

安装

make && make install

你可能感兴趣的:(linux下的php)