欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos 8 x86_64 Nginx + PHP 安装步骤

程序员文章站 2024-03-11 15:38:19
...

Centos 8 下的 PHP7/Nginx/Memcached/Redis 安装步骤。如果是Centos 7 请访问 Centos 7 x86_64 Nginx + PHP 安装步骤 ,本篇教程没有去配置 php.ini,我觉得这个配置根据个人需求自己配置即可。

一、获取相关开源程序

1、安装环境所需的程序库

yum -y update
yum -y remove mariadb*

yum install -y patch make cmake gcc gcc-c++ bison flex file libtool libtool-libs autoconf re2c libaio libcap glibc glib2 kernel-devel glibc-devel glib2-devel curl unzip epel-release

yum install -y diffutils ncurses ncurses-devel libjpeg libpng freetype libxml2 zlib bzip2 libidn gettext libxslt libedit libtidy gd libyaml libxml2-devel openssl-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel cyrus-sasl-devel gmp-devel libedit-devel libtidy-devel libxslt-devel readline-devel libidn-devel zlib-devel ImageMagick ImageMagick-devel gettext-devel gd-devel libyaml-devel mhash mhash-devel libmemcached libmemcached-devel systemd systemd-devel

yum -y install mcrypt libmcrypt libmcrypt-devel

2、准备环境变量

echo -e "/lib64\n/usr/lib64\n/usr/local/lib64\n/lib\n/usr/lib\n/usr/local/lib\n`cat /etc/ld.so.conf`" > /etc/ld.so.conf
/sbin/ldconfig

3、编译安装Centos 无法通过YUM安装的包

cd /usr/local/src

curl -fSL http://soft.laua.cn/libiconv/libiconv-1.15.tar.gz -o libiconv-1.15.tar.gz
tar zxf libiconv-1.15.tar.gz && rm -f libiconv-1.15.tar.gz 
cd libiconv-1.15/
./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/libiconv-1.15

curl -fSL http://soft.laua.cn/icu/icu4c-65_1-src.tgz -o icu4c-65_1-src.tgz
tar zxf icu4c-65_1-src.tgz && rm -f icu4c-65_1-src.tgz
cd icu/source/
./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static 
make -j "$(nproc)" && make install
cd ../../
rm -rf /usr/local/src/icu

curl -fSL http://soft.laua.cn/libzip/libzip-1.6.0.tar.gz -o libzip-1.6.0.tar.gz
tar zxf libzip-1.6.0.tar.gz && rm -f libzip-1.6.0.tar.gz
cd libzip-1.6.0
mkdir build && cd build && cmake3 .. && make && make install
cd ../../
rm -rf /usr/local/src/libzip-1.6.0

二、安装PHP 7(FastCGI模式)

1、编译安装PHP(FastCGI模式)

cd /usr/local/src

curl -fSL http://soft.laua.cn/php/php-7.4.2.tar.gz -o php-7.4.2.tar.gz
tar zxf php-7.4.2.tar.gz && rm -f php-7.4.2.tar.gz
cd php-7.4.2/
/sbin/ldconfig
./configure --prefix=/usr/local --libdir=/usr/local/lib64 --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/php \
--with-libxml-dir --with-openssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl \
--enable-exif --enable-fpm --enable-ftp --with-png-dir --with-gd --with-jpeg-dir \
--with-icu-dir=/usr/local --enable-mbstring --enable-mbregex --enable-shmop --enable-soap --enable-sockets \
--enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-libedit --with-iconv-dir=/usr/local \
--with-xsl --enable-zip --with-pcre-regex --with-pcre-jit --with-freetype-dir --enable-xml  --with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --disable-rpath --enable-inline-optimization \
--with-mhash --enable-pcntl --without-pear --with-gettext --enable-fileinfo --enable-intl --enable-opcache --enable-cli \
--with-gmp --with-tidy --with-pcre-dir --with-readline --with-fpm-systemd --with-zlib-dir --with-libdir=lib64

make -j "$(nproc)" ZEND_EXTRA_LIBS='-liconv'
make install

cp php.ini-production /usr/local/etc/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cd ../
rm -rf /usr/local/src/php-7.4.2
mkdir -p /var/lib/php

2、编译安装PHP扩展模块

curl -fSL http://soft.laua.cn/pecl/msgpack-2.1.0beta1.tgz -o msgpack-2.1.0beta1.tgz
tar zxf msgpack-2.1.0beta1.tgz && rm -rf msgpack-2.1.0beta1.tgz
cd msgpack-2.1.0beta1
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/msgpack-2.1.0beta1
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/igbinary-3.1.2.tgz -o igbinary-3.1.2.tgz
tar zxf igbinary-3.1.2.tgz && rm -rf igbinary-3.1.2.tgz
cd igbinary-3.1.2
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/igbinary-3.1.2
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/memcached-3.1.5.tgz -o memcached-3.1.5.tgz
tar zxf memcached-3.1.5.tgz && rm -rf memcached-3.1.5.tgz
cd memcached-3.1.5
phpize
./configure --enable-memcached --enable-memcached-igbinary --enable-memcached-json --enable-memcached-msgpack --with-libdir=lib64
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/memcached-3.1.5
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/redis-5.1.1.tgz -o redis-5.1.1.tgz
tar zxf redis-5.1.1.tgz && rm -rf redis-5.1.1.tgz
cd redis-5.1.1
phpize
./configure --enable-redis --enable-redis-igbinary
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/redis-5.1.1
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/yaml-2.0.4.tgz -o yaml-2.0.4.tgz
tar zxf yaml-2.0.4.tgz && rm -rf yaml-2.0.4.tgz
cd yaml-2.0.4
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/yaml-2.0.4
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/imagick-3.4.4.tgz -o imagick-3.4.4.tgz
tar zxf imagick-3.4.4.tgz
rm -rf imagick-3.4.4.tgz
cd imagick-3.4.4
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/imagick-3.4.4
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/mongodb-1.6.1.tgz -o mongodb-1.6.1.tgz
tar zxf mongodb-1.6.1.tgz && rm -rf mongodb-1.6.1.tgz
cd mongodb-1.6.1
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/mongodb-1.6.1
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/apcu-5.1.18.tgz -o apcu-5.1.18.tgz
tar zxf apcu-5.1.18.tgz && rm -rf apcu-5.1.18.tgz
cd apcu-5.1.18
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/apcu-5.1.18
rm -f /usr/local/src/package.xml

curl -fSL http://soft.laua.cn/pecl/rdkafka-4.0.2.tgz -o rdkafka-4.0.2.tgz
tar zxf rdkafka-4.0.2.tgz && rm -rf rdkafka-4.0.2.tgz
cd rdkafka-4.0.2
phpize
./configure
make -j "$(nproc)" && make install
cd ../
rm -rf /usr/local/src/rdkafka-4.0.2
rm -f /usr/local/src/package.xml

mkdir -p /usr/local/etc/php
echo -e "[PHP]\nextension=msgpack.so" >> /usr/local/etc/php/msgpack.ini
echo -e "[PHP]\nextension=igbinary.so" >> /usr/local/etc/php/igbinary.ini
echo -e "[PHP]\nextension=memcached.so" >> /usr/local/etc/php/memcached.ini
echo -e "[PHP]\nextension=redis.so" >> /usr/local/etc/php/redis.ini
echo -e "[PHP]\nextension=yaml.so" >> /usr/local/etc/php/yaml.ini
echo -e "[PHP]\nextension=mongodb.so" >> /usr/local/etc/php/mongodb.ini
echo -e "[PHP]\nextension=rdkafka.so" >> /usr/local/etc/php/rdkafka.ini

mkdir -p /usr/local/lib64/php
curl -fSL http://soft.laua.cn/php/shell/maxlifetime -o /usr/local/lib64/php/maxlifetime
curl -fSL http://soft.laua.cn/php/shell/sessionclean -o /usr/local/lib64/php/sessionclean

chmod 0755 /usr/local/lib64/php/maxlifetime
chmod 0755 /usr/local/lib64/php/sessionclean

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

三、安装Nginx

curl -fSL http://soft.laua.cn/nginx/nginx-1.17.8.tar.gz -o nginx-1.17.8.tar.gz
tar zxf nginx-1.17.8.tar.gz && rm -f nginx-1.17.8.tar.gz
cd nginx-1.17.8
./configure --prefix=/usr/local --conf-path=/usr/local/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/run/lock/nginx.lock --pid-path=/run/nginx.pid --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_slice_module --with-http_xslt_module --with-http_realip_module --with-http_stub_status_module --with-pcre --with-pcre-jit --with-http_flv_module --with-http_mp4_module --with-http_addition_module --with-threads --with-http_secure_link_module --with-http_degradation_module --with-http_ssl_module --with-http_gzip_static_module --with-http_auth_request_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module --without-select_module --with-http_sub_module --with-http_geoip_module --with-http_random_index_module --with-cc-opt='-O2'

make -j "$(nproc)" && make install
mkdir -p /var/lib/nginx
mkdir -p /usr/local/etc/nginx/sites
cd ../
rm -rf /usr/local/src/nginx-1.17.8

四、收尾

1、优化内核

#for aliyun
cat >>/etc/security/limits.conf<<eof
* soft nproc 65535
* hard nproc 65535
eof

#other
cat >>/etc/security/limits.conf<<eof
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
eof

echo "fs.file-max=65535" >> /etc/sysctl.conf

3、设置开机启动

systemctl enable nginx.service
systemctl enable php-fpm.service
相关标签: 服务器

上一篇: 用JRuby写个小MIDI

下一篇: