Centos7 php7.3 Nginx1.9 Mariadb10.4

更新和安装依赖

yum install -y git vim wget gcc gcc-c++ libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel libzip-devel openssl openssl-devel 

下载Mysql

卸载mysql
yum -y remove MariaDB*

下载安装包

mkdir -p /data/soft
cd /data/soft
wget http://nginx.org/download/nginx-1.17.3.tar.gz
wget https://www.php.net/distributions/php-7.3.9.tar.gz
wget http://memcached.org/files/memcached-1.5.7.tar.gz
wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz

#安装cmake3.0

tar xvf cmake-3.6.2.tar.gz
cd cmake-3.6.2/
./bootstrap
gmake
gmake install

ln -s /usr/local/bin/cmake /usr/bin/

#设置环境变量

vim /etc/ld.so.conf 

#添加如下几行

/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 

#保存退出

:wq

# 使之生效

ldconfig -v 

yum安装数据库

vim  /etc/yum.repos.d/MariaDB.repo
[mariadb]
name=MariaDB
baseurl=http://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey=http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=0
enabled=1

yum install -y MariaDB-server MariaDB-client
rm -rf /var/lib/mysql
mkdir /data/mariadb

vim /etc/my.cnf.d/mysql-clients.cnf
[client]
port        = 3306
socket      = /data/mariadb/mysql.sock
default-character-set=utf8mb4 

vim /etc/my.cnf.d/server.cnf
[mysqld]
port            = 3306
datadir         = /data/mariadb
socket          = /data/mariadb/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 64M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
character-set-client-handshake = FALSE
init_connect='SET NAMES utf8mb4 '
character-set-server=utf8mb4 
collation-server = utf8mb4_unicode_ci

[mysql]
default-character-set = utf8mb4
按照

初始化数据库

mysql_install_db --defaults-file=/etc/my.cnf --datadir=/data/mariadb/ --user=mysql
systemctl start mariadb
systemctl enable mariadb
mysqladmin -u root password "8888888"

安装openssl

wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
tar zxvf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
./config --prefix=/usr/local/openssl
make && make install

mv /usr/bin/openssl  /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl

ln -s /usr/local/openssl/lib/libssl.so /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/lib/libcrypto.so /usr/local/lib64/libcrypto.so

strings /usr/local/lib64/libssl.so | grep OpenSSL

echo '/usr/local/openssl/lib' >> /etc/ld.so.conf
ldconfig -v
openssl version

安装Nginx

groupadd -r www
useradd -r -g www -s /sbin/nologin -d /usr/local/webserver/nginx -M www

tar zxvf nginx-1.17.3.tar.gz
cd nginx-1.17.3 
./configure \
--prefix=/usr/local/webserver/nginx \
--without-http_memcached_module \
--user=www  \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_secure_link_module \
--with-http_v2_module \
--with-http_sub_module \
--with-openssl=/data/soft/openssl-1.1.1d

make && make install
vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
PIDFile=/usr/local/webserver/nginx/logs/nginx.pid
ExecStart=/usr/local/webserver/nginx/sbin/nginx
ExecReload=/usr/local/webserver/nginx/sbin/nginx -s reload
ExecStop=/usr/local/webserver/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target


systemctl enable nginx.service
systemctl start nginx.service
vim   /usr/local/webserver/nginx/conf/nginx.conf

#user  nobody;去除前面#号,并将用户改为www www
user www www;
# --------------------------------------------------------------------------
#pid        logs/nginx.pid; 去除前面的#号
pid        logs/nginx.pid;
# --------------------------------------------------------------------------
去除前面的#号 如下
log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
# --------------------------------------------------------------------------
# gzip  on;去除前面的#号并加上隐藏版号代码
server_tokens off;
# --------------------------------------------------------------------------
index  index.html index.htm;后面加上index.php 默认页
index  index.html index.htm index.php;
# --------------------------------------------------------------------------
去下以下前面的#号并做如下修改
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

升级libzip

yum -y remove libzip
curl -O https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install

 

安装PHP

tar zxvf php-7.3.9.tar.gz 
cd php-7.3.9
./configure \
--prefix=/usr/local/webserver/php \
--with-config-file-path=/usr/local/webserver/php/etc \
--enable-fpm \
--with-fpm-user=www  \
--with-fpm-group=www \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared  \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir  \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets  \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-pcntl \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
make
make install
cp php.ini-production /usr/local/webserver/php/etc/php.ini
vim /usr/local/webserver/php/etc/php.ini

.找到:;date.timezone =                               修改为:date.timezone = PRC
post-size

cd /usr/local/webserver/php/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default  php-fpm.d/www.conf


cd /data/soft/php-7.3.9
cp sapi/fpm/init.d.php-fpm /usr/local/webserver/php/bin/php-fpm
chmod +x  /usr/local/webserver/php/bin/php-fpm
ln -s /usr/local/webserver/php/bin/php-fpm /usr/bin

 

 

安装memcached


yum -y install libevent libevent-devel
tar zxvf memcached-1.5.7.tar.gz
cd memcached-1.5.7
./configure --prefix=/usr/local/memcached
make && make install

vim /usr/local/memcached/memcached

#! /bin/sh
#
# chkconfig: - 55 45
# description:  The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
  
# Source function library.
. /etc/rc.d/init.d/functions
  
PORT=11211
USER=root
MAXCONN=1024
CACHESIZE=256
OPTIONS=""
  
if [ -f /etc/sysconfig/memcached ];then
    . /etc/sysconfig/memcached
fi
  
# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
    exit 0
fi
  
RETVAL=0
  
start () {
    echo "Starting memcached ..."
    # insure that /var/run/memcached has proper permissions
    chown $USER /usr/local/memcached/bin/memcached
    /usr/local/memcached/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached.pid $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
    echo "Stopping memcached ..."
    killproc memcached
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ] ; then
        rm -f /var/lock/subsys/memcached
        rm -f /var/run/memcached.pid
    fi
}
  
restart () {
    stop
    start
}
  
# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
    stop
    ;;
    status)
    status memcached
    ;;
    restart|reload)
    restart
    ;;
    condrestart)
    [ -f /var/lock/subsys/memcached ] && restart || :
    ;;
    *)
    echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
    exit 1
esac



chmod 0777 /usr/local/memcached/memcached
vim /lib/systemd/system/memcached.service

[Unit]
Description=memcached
After=network.target
  
[Service]
Type=forking
PIDFile=/var/run/memcached.pid
ExecStart=/usr/local/memcached/memcached start
ExecReload=/usr/local/memcached/memcached restart
ExecStop=/usr/local/memcached/memcached stop
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target


systemctl enable memcached.service
systemctl start memcached.service


Memcached
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar -zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure -prefix=/usr/local/libmemcached -with-memcached 
make && make install 

git clone git://github.com/php-memcached-dev/php-memcached.git
cd php-memcached/
/usr/local/webserver/php/bin/phpize
./configure -enable-memcached -with-php-config=/usr/local/webserver/php/bin/php-config -with-zlib-dir -with-libmemcached-dir=/usr/local/libmemcached -prefix=/usr/local/webserver/phpmemcached  --disable-memcached-sasl
make -j4
make install

vim /usr/local/webserver/php/etc/php.ini
extension=/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20180731/memcached.so

letsencrypt ssl证书

 

wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto
/usr/local/bin/certbot-auto --nginx

certbot-auto  certonly --webroot -w /data/www/xxx  -d  xxx.com

conf文件添加配置
        listen       443 ssl http2 default_server;
        ssl_certificate "/etc/letsencrypt/live/xxx.com/fullchain.pem";
        ssl_certificate_key "/etc/letsencrypt/live/xxx.com/privkey.pem";

自动跳转到ssl 
    server {
        listen 80;
        server_name xxx.com;
        rewrite ^(.*) https://$server_name$1 permanent;
    } 

 

 

 

Comments Closed.