yum update
yum install -y gcc gcc-c++ autoconf automake
cd /usr/local/src
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar zxvf pcre-8.43.tar.gz
cd pcre-8.43
./configure --prefix=/usr/local/pcre
make && make install
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar zxvf openssl-1.0.2s.tar.gz
cd openssl-1.0.2s
./config --prefix=/usr/local/openssl
make && make install
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix=/usr/local/zlib
make && make install
cd /usr/local/src
wget https://src.fedoraproject.org/lookaside/pkgs/jemalloc/jemalloc-5.2.1.tar.bz2/sha512/0bbb77564d767cef0c6fe1b97b705d368ddb360d55596945aea8c3ba5889fbce10479d85ad492c91d987caacdbbdccc706aa3688e321460069f00c05814fae02/jemalloc-5.2.1.tar.bz2
tar jxvf jemalloc-5.2.1.tar.bz2
cd jemalloc-5.2.1
./configure --prefix=/usr/local/jemalloc
make && make install
# 添加 www 组
groupadd -r www
# 创建 www 运行账户 nginx 并加入到 www 组,并且不允许 www 用户直接登录系统
useradd -s /sbin/nologin -g www -r www
cd /usr/local/src
wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
tar -zxvf tengine-2.3.2.tar.gz
cd tengine-2.3.2
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre=/usr/local/src/pcre-8.43 \
--with-openssl=/usr/local/src/openssl-1.0.2s \
--with-jemalloc=/usr/local/src/jemalloc-5.2.1 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--add-module=./modules/ngx_http_concat_module \
--with-zlib=/usr/local/src/zlib-1.2.11
make && make install
注意配置的时候 –with-pcre 、–with-openssl、–with-jemalloc、–with-zlib的路径为源文件的路径。
# 创建配置文件目录
mkdir /usr/local/nginx/conf/vhosts
# 配置 user,必须与 /usr/local/php73/etc/php-fpm.conf 中的 user,group 配置相同
vim /usr/local/nginx/conf/nginx.conf
user www www; # 首行user去掉注释,修改Nginx运行组,否则 php 运行出错
# 在配置文件尾部闭合括号(})前添加引入配置文件语句
include vhosts/*.conf;
:wq # 保存退出
# 系统用户登录系统后启动的服务的目录 /usr/lib/systemd/system
# 如需要开机没有登陆情况下就能运行的程序在系统目录内 /usr/lib/systemd/system
# 我希望系统开机就启动目录,所以我把文件放在系统目录内。
vim /lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
:wq # 保存退出
# 修改文件权限
chmod 745 /lib/systemd/system/nginx.service
# 设置为开机启动
systemctl enable nginx.service
# 其它命令
# 启动nginx服务
systemctl start nginx.service
# 设置开机自启动
systemctl enable nginx.service
# 停止开机自启动
systemctl disable nginx.service
# 查看服务当前状态
systemctl status nginx.service
# 重新启动服务
systemctl restart nginx.service
# 查看所有已启动的服务
systemctl list-units --type=service
vim /etc/rc.d/init.d/nginx # 编辑启动文件添加下面内容
############################################################
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
fi
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
############################################################
chmod 745 /etc/rc.d/init.d/nginx # 设置权限
chkconfig nginx on # 开机自启动
# 开启服务
/etc/init.d/nginx start
# 重启服务
/etc/init.d/nginx restart
# 停止服务
/etc/init.d/nginx stop
# 查看服务状态
/etc/init.d/nginx status
yum install -y cmake make gcc gcc-c++ autoconf bison automake openssl openssl-devel zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.18.3/cmake-3.18.3.tar.gz
# 移除旧版本
yum -remove cmake -y
tar zxvf cmake-3.18.3.tar.gz
cd cmake-3.18.3
./configure && make && make install
vim ~/.bashrc
# 在末尾添加
export PATH=$PATH:/usr/local/src/cmake-3.18.3/bin
# :wq 保存退出
source ~/.bashrc
因为本人使用的是 Alibaba Cloud Linux 2 系统,所以安装方式有所不同,CentOS 系统请参考方案二。
方案一(Alibaba Cloud Linux 2):
# 先安装 scl-utils
yum install -y scl-utils
# 打开 YUM 仓库支持
yum install -y alinux-release-experimentals
# 查看支持的 gcc 版本
yum list|grep gcc
# 选择 8
yum install -y devtoolset-8-gcc*
# 更改 gcc 版本
source /opt/rh/devtoolset-9/enable
# 查看 gcc 版本
gcc -v
方案二(CentOS):
# 使用 scl 软件集(Software Collections)实现多个 gcc 版本之间的灵活切换
yum install centos-release-scl -y
# 查看支持的 gcc 版本
yum list|grep gcc
# 选择 8
yum install devtoolset-8-gcc* -y
# 更改 gcc 版本
source /opt/rh/devtoolset-8/enable
# 查看 gcc 版本
gcc -v
cd /usr/local/src
wget https://jaist.dl.sourceforge.net/project/boost/boost/1.72.0/boost_1_72_0.tar.gz
mkdir -p /usr/local/boost
cp /usr/local/src/boost_1_72_0.tar.gz /usr/local/boost
# 添加 mysql 组
groupadd -r mysql
# 创建 MySQL 运行账户 mysql 并加入到 mysql 组,并且不允许 mysql 用户直接登录系统
useradd -s /sbin/nologin -g mysql -r mysql
mkdir -p /data/mysql # 创建 MySQL 数据库存放目
chown -R mysql:mysql /data/mysql # 设置 MySQL 数据库目录权限
mkdir /usr/local/mysql # 创建 MySQL 安装目录
cd /usr/local/src
wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.21.tar.gz
tar zxvf mysql-8.0.21.tar.gz
cd mysql-8.0.21
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_0900_ai_ci \
-DWITH_SSL=system \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_INNODB_MEMCACHED=ON \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=ON \
-DMYSQL_TCP_PORT=3306 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_BOOST=/usr/local/boost \
-DDOWNLOAD_BOOST=1
注意:可以使用 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost 参数在线安装 boost 软件包,需要服务器联网,容易下载失败。
make
make install # 安装
./bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/data/mysql # 生成 MySQL 系统数据库
_–initialize 表示默认生成密码,–initialize-insecure 表示不生成密码,密码为空。
如果生成密码,初始化后会看到这一行:
[Note] A temporary password is generated for root@localhost: CSJlm3DyTG.d
复制 CSJlm3DyTG.d 这就是 root 的密码_
vim /etc/my.cnf
# 修改
datadir=/data/mysql
socket=/tmp/mysql.sock
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld # 把 MySQL 加入系统启动
chmod 745 /etc/init.d/mysqld # 增加执行权限
chkconfig mysqld on # 加入开机启动
vim /etc/rc.d/init.d/mysqld # 编辑
basedir=/usr/local/mysql # MySQL 程序安装路径
datadir=/data/mysql # MySQl 数据库存放目录
:wq # 保存退出
vim /etc/profile # 把 MySQl 服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
:wq # 保存退出
source /etc/profile # 使配置立刻生效
mysql_secure_installation # 修改 MySQl 密码,输入之前生成的密 CSJlm3DyTG.d 回车,根据提示操作。一般为 y > 2 > n > y > y > y > y
yum install -y 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 gcc-c++ autoconf libXpm-devel
cd /usr/local/src
wget https://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.gz
tar zxvf libpng-1.6.37.tar.gz
cd libpng-1.6.37
./configure --prefix=/usr/local/libpng --enable-shared
make -j4
make install
cd /usr/local/src
wget http://ftp.twaren.net/Unix/NonGNU/freetype/freetype-2.10.2.tar.gz
tar zxvf freetype-2.10.2.tar.gz
cd freetype-2.10.2
./configure --prefix=/usr/local/freetype --enable-shared
make -j4
make install
cd /usr/local/src
wget http://www.ijg.org/files/jpegsrc.v9d.tar.gz
tar zxvf jpegsrc.v9d.tar.gz
cd jpeg-9d
./configure --prefix=/usr/local/jpeg --enable-shared
make -j4
make install
cd /usr/local/src
wget https://libzip.org/download/libzip-1.7.3.tar.gz
tar zxvf libzip-1.7.3.tar.gz
cd libzip-1.7.3
mkdir build
cd build
cmake ..
make -j4
make install
cd /usr/local/src
wget http://download.osgeo.org/libtiff/tiff-4.1.0.tar.gz
tar zxvf tiff-4.1.0.tar.gz
cd tiff-4.1.0
./configure --prefix=/usr/local/tiff --enable-shared
make -j4
make install
cd /usr/local/src
wget https://github.com/libgd/libgd/releases/download/gd-2.3.0/libgd-2.3.0.tar.gz
tar zxvf libgd-2.3.0.tar.gz
cd libgd-2.3.0
./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff
make -j4
make install
说明:如果libgd编译失败,可以先跳过,直接使用系统默认的2.1.0版本,在编译php的时候把参数–with-gd=/usr/local/libgd修改为–with-gd即可。
# 添加搜索路径到配置文件,避免: configure: error: off_t undefined; check your library configuration 。
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v
cd /usr/local/src
wget https://www.php.net/distributions/php-7.3.20.tar.gz
tar -zvxf php-7.3.20.tar.gz
cd php-7.3.20
./configure \
--prefix=/usr/local/php73 \
--exec-prefix=/usr/local/php73 \
--bindir=/usr/local/php73/bin \
--sbindir=/usr/local/php73/sbin \
--includedir=/usr/local/php73/include \
--libdir=/usr/local/php73/lib/php \
--mandir=/usr/local/php73/php/man \
--with-config-file-path=/usr/local/php73/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli \
--with-mysql-sock=/tmp/mysql.sock \
--with-pdo-mysql \
--with-gd=/usr/local/libgd \
--with-png-dir=/usr/local/libpng \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-xpm-dir=/usr/lib64 \
--with-zlib-dir=/usr/local/src/libzip-1.7.3 \
--with-iconv \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-opcache \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--with-openssl \
--enable-pcntl \
--enable-exif \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--enable-ctype \
--enable-mysqlnd
make -j4
make install
cp php.ini-production /usr/local/php73/etc/php.ini # 复制 php 配置文件到安装目录
rm -rf /etc/php.ini # 删除系统自带配置文件
ln -s /usr/local/php73/etc/php.ini /etc/php73.ini # 添加软链接到 /etc 目录
cp /usr/local/php73/etc/php-fpm.conf.default /usr/local/php73/etc/php-fpm.conf # 拷贝模板文件为 php-fpm 配置文件
ln -s /usr/local/php73/etc/php-fpm.conf /etc/php-fpm73.conf # 添加软连接到 /etc 目录
vim /usr/local/php73/etc/php-fpm.conf # 编辑
pid = run/php-fpm.pid # 取消前面的分号
:wq # 保存退出
cp /usr/local/php73/etc/php-fpm.d/www.conf.default /usr/local/php73/etc/php-fpm.d/www.conf
vim /usr/local/php73/etc/php-fpm.d/www.conf # 编辑
user = www # 设置 php-fpm 运行账号为 www
group = www # 设置 php-fpm 运行组为 www
# 设置 php-fpm 开机启动
cp /usr/local/src/php-7.3.20/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm73 # 拷贝 php-fpm 到启动目录
chmod +x /etc/rc.d/init.d/php-fpm73 # 添加执行权限
chkconfig php-fpm73 on # 设置开机启动
vim /usr/local/php73/etc/php.ini # 编辑配置文件
# 修改:disable_functions
# 列出 PHP 可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
date.timezone = PRC # 设置时区
expose_php = Off # 禁止显示 php 版本的信息
short_open_tag = On # 支持 php 短标签
# 开启 php 缓存,不开则忽略下面的配置
opcache.enable=1 # php 支持 opcode 缓存
# 找到:;opcache.enable_cli=0 改为 1
opcache.enable_cli=1 # 开启 CLI
# 在最后一行添加:
zend_extension=opcache.so # 开启 opcode 扩展
:wq # 保存退出
/etc/init.d/php-fpm73 start # 启动 php
cd /usr/local/src
wget http://pecl.php.net/get/redis-5.3.1.tgz
tar zxvf redis-5.3.1.tar.gz
cd redis-5.3.1
# php 7.3 版本编译
/usr/local/php73/bin/phpize
./configure --with-php-config=/usr/local/php73/bin/php-config
make -j4
make install
Installing shared extensions: /usr/local/php73/lib/php/extensions/no-debug-non-zts-20180731/
vim /usr/local/php73/etc/php.ini
extension=redis.so # 在最末尾新起一行添加
:wq # 保存退出
mkdir -p /opt/www/php_test # 创建项目目录
vim /opt/www/php_test/v73.php # 新建 php 文件
:wq # 保存退出
cp /opt/www/php_test/v73.php /opt/www/php_test/v56.php
chown www:www -R /opt/www # 设置目录所有者
vim vim /usr/local/nginx/conf/vhosts/php73_test.conf
server {
listen 8080;
server_name 101.202.37.22; # 101.201.72.12 为你服务器对应的外网 ip 地址
root /opt/www/php_test/v73.php;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
:wq # 保存退出
/etc/init.d/nginx restart # 重启 nginx
浏览器输入:
http://101.201.72.12:8080/
注:101.201.72.12 为你服务器对应的外网 ip 地址。如果访问不通记得检查防火墙白名单呦 ^ _ ^。
# 添加搜索路径到配置文件,避免: configure: error: off_t undefined; check your library configuration 。
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v
cd /usr/local/src
wget https://www.php.net/distributions/php-5.6.40.tar.gz
tar -zvxf php-5.6.40.tar.gz
cd php-5.6.40
./configure \
--prefix=/usr/local/php56 \
--exec-prefix=/usr/local/php56 \
--bindir=/usr/local/php56/bin \
--sbindir=/usr/local/php56/sbin \
--includedir=/usr/local/php56/include \
--libdir=/usr/local/php56/lib/php \
--mandir=/usr/local/php56/php/man \
--with-config-file-path=/usr/local/php56/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli \
--with-mysql-sock=/tmp/mysql.sock \
--with-pdo-mysql \
--with-gd=/usr/local/libgd \
--with-png-dir=/usr/local/libpng \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-xpm-dir=/usr/lib64 \
--with-zlib-dir=/usr/local/src/libzip-1.7.3 \
--with-iconv \
--enable-libxml \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-opcache \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--with-openssl \
--with-mcrypt \
--enable-pcntl \
--enable-exif \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--enable-ctype \
--enable-mysqlnd
make -j4
make install
cp php.ini-production /usr/local/php56/etc/php.ini # 复制 php 配置文件到安装目录
rm -rf /etc/php.ini # 删除系统自带配置文件
ln -s /usr/local/php56/etc/php.ini /etc/php56.ini # 添加软链接到 /etc 目录
cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf # 拷贝模板文件为 php-fpm 配置文件
ln -s /usr/local/php56/etc/php-fpm.conf /etc/php-fpm56.conf # 添加软连接到 /etc 目录
vim /usr/local/php56/etc/php-fpm.conf # 编辑
pid = run/php-fpm.pid # 取消前面的分号
user = www # 设置 php-fpm 运行账号为 www
group = www # 设置 php-fpm 运行组为 www
listen = 127.0.0.1:9001 # 避免与 php 7.3 版本监听的端口冲突,所以设置为 9001
:wq # 保存退出
# 设置 php-fpm 开机启动
cp /usr/local/src/php-5.6.40/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm56 # 拷贝 php-fpm 到启动目录
chmod +x /etc/rc.d/init.d/php-fpm56 # 添加执行权限
chkconfig php-fpm56 on # 设置开机启动
vim /usr/local/php56/etc/php.ini # 编辑配置文件
# 修改:disable_functions
# 列出 PHP 可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
date.timezone = PRC # 设置时区
expose_php = Off # 禁止显示 php 版本的信息
short_open_tag = On # 支持 php 短标签
# 开启 php 缓存,不开则忽略下面的配置
opcache.enable=1 # php 支持 opcode 缓存
# 找到:;opcache.enable_cli=0 改为 1
opcache.enable_cli=1 # 开启 CLI
# 在最后一行添加:
zend_extension=opcache.so # 开启 opcode 扩展
:wq # 保存退出
/etc/init.d/php-fpm56 start # 启动 php
# 该版本为最后一版支持 php5 的 php-redis 扩展
cd /usr/local/src
wget http://pecl.php.net/get/redis-4.3.0.tgz
tar zxvf redis-4.3.0.tgz
cd redis-4.3.0
# php 5.6 版本编译
/usr/local/php56/bin/phpize
./configure --with-php-config=/usr/local/php56/bin/php-config
make -j4
make install
Installing shared extensions: /usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/
vim /usr/local/php56/etc/php.ini
extension=redis.so # 在最末尾新起一行添加
:wq # 保存退出
mkdir -p /opt/www/php_test # 创建项目目录
vim /opt/www/php_test/v56.php # 新建 php 文件
:wq # 保存退出
cp /opt/www/php_test/v56.php /opt/www/php_test/v56.php
chown www:www -R /opt/www # 设置目录所有者
vim /usr/local/nginx/conf/vhosts/php56_test.conf
server {
listen 8081;
server_name 101.202.37.22; # 101.201.72.12 为你服务器对应的外网 ip 地址
root /opt/www/php_test/v56.php;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9001; # 注意监听的端口不同
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
:wq # 保存退出
/etc/init.d/nginx restart # 重启 nginx
测试环境
浏览器输入:
http://101.201.72.12:8081/
注:101.201.72.12 为你服务器对应的外网 ip 地址。如果访问不通记得检查防火墙白名单呦 ^ _ ^。
yum install -y gcc-c++
gcc 版本小于 5.3 无法编译,如果版本低则参考本文中的 GCC 安装方法。
cd /usr/local/src
wget https://download.redis.io/releases/redis-6.0.8.tar.gz
tar zxvf redis-6.0.8.tar.gz
cd redis-6.0.8
make
# 创建存储redis文件目录
mkdir /usr/local/redis
# 复制redis-server redis-cli到新建立的文件夹
cp /usr/local/src/redis-6.0.8/src/redis-server /usr/local/redis/
cp /usr/local/src/redis-6.0.8/src/redis-cli /usr/local/redis/
# 复制redis的配置文件
cp /usr/local/src/redis-6.0.8/redis.conf /usr/local/redis/
vim /usr/local/redis/redis.conf
# 将 bind 127.0.0.1 前的 “#” 注释去掉
bind 127.0.0.1
# 关闭 protected-mode 模式,此时外部网络可以直接访问
protected-mode no
# 默认为不守护进程模式,把daemonize no 改为 yes
daemonize yes
# 将 requirepass foobared 前的“#”去掉,密码(foobared)改为你想要设置的密码
requirepass 123456 # 密码 123456
:wq # 保存退出
vim /etc/init.d/redis
#!/bin/sh
# chkconfig: 2345 80 90
# description: Start and Stop redis
#PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379 # 端口
EXEC=/usr/local/redis/redis-server # redis-server所在路径
REDIS_CLI=/usr/local/redis/redis-cli # redis-cli所在路径
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/redis.conf" # redis配置文件所在路径
AUTH="123456" # 密码 123456
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
:wq # 保存退出
chmod 745 /etc/init.d/redis
chkconfig redis on
# 打开服务
service redis start
# 重启服务
service redis restart
# 关闭服务
service redis stop
vim /etc/systemd/system/redis-server.service # 编辑脚本
[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
:wq # 保存退出
chmod 745 /etc/systemd/system/redis-server.service
systemctl enable redis-server.service # 开机自启动
# 开启服务
systemctl start redis-server.service
# 重启服务
systemctl restart redis-server.service
# 停止服务
systemctl stop redis-server.service
# 查看服务状态
systemctl start redis-server.service