1、 先装redis
/home 目录下安装
wget http://download.redis.io/releases/redis-2.8.17.tar.gz
tar xzf redis-2.8.17.tar.gz
cd redis-2.8.17
make
复制redis配置文件到 根目录的 /etc 文件中
cp redis.conf /etc
进入etc,找到redis.conf 并修改 daemonize no(第128行) 为 daemonize yes ,这样就可以默认启动就后台运行
cd 到安装目录的 src下执行
redis-server /etc/redis.conf
**** 坑
当服务器可以链接上是 但是本地工具链接不上 将redis进程 kill 然后在启动 启动时选择安装路径的conf 文件启动即:
redis-server /home/redis-2.8.17/redis.conf # 启动
最后验证是否成功
执行命令
redis-cli
#或者
redis-cli -h 106.14.221.255 -p 6379
设置redis 密码 config set requirepass edwin
然后验证一下 auth edwin
返回ok 即可
消息列队
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$password = '123456';
$redis->auth($password);
$arr = array('h','e','l','l','o','w','o','r','l','d');
foreach($arr as $k=>$v){
$redis->rpush("mylist",$v);
}
1593679322
1593679486
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$password = '123456';
$redis->auth($password);
//list类型出队操作
$value = $redis->lpop('mylist');
if($value){
echo "出队的值".$value;
}else{
echo "出队完成";
}
?>
redis windows 工具
另外Redis对数据有一个持久化作用,这样要比Memcache要有优势,并且数据类型要多,这次要用的就是Redis的List,可以向头部或者尾部向Redis的链表增加元素,这样Redis在实现一个轻量级的队列非常有优势。
LPUSH/LPUSHX:LPUSH是将值插入到链表的头部,LPUSHX是检测这个链表是否存在,如果存在的话会插入头部,如果不存在会忽略这个数据
RPUSH/RPUSHX:将值插入到链表的尾部。同上,位置相反
LPOP:移除并获取链表中的第一个元素。
RPOP:移除并获取链表中最后一个元素。
LTRIM:保留指定区间内的元素。
LLEN:获取链表的长度。
LSET:用索引设置链表元素的值。
LINDEX:通过索引获取链表中的元素。
LRANGE:获取链表指定范围内的元素。
2 、安装nginx
首先安装依赖
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
下载 nginx
*** 我上次没有将nginx 安装到/usr/local/这个目录下 希望能下载在这解压后 然后 rm -rf 这个.gz文件
wget http://nginx.org/download/nginx-1.19.0.tar.gz
tar -zxf nginx-1.19.0.tar.gz
cd nginx-1.19.0/
useradd nginx
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module
make && make install
启动nginx /usr/local/nginx/sbin/nginx
重启nginx /usr/local/nginx/sbin/nginx -s reload
停止nginx /usr/local/nginx/sbin/nginx -s stop
pwd
/home
cp -r ./nginx-1.19.0 /usr/local/ 复制文件到usr/local目录下
或者 移动 mv -f ./nginx-1.19.0 /usr/local/
配置是注意 40 行 不要有 text/html 原因是默认 已经存在
配置nginx
https://www.runoob.com/w3cnote/nginx-install-and-config.html
3、安装php
版本最好是7.3以上
以下是php7.0 安装过程
wget http://cn2.php.net/distributions/php-7.0.30.tar.gz
解压 tar -zxvf php-7.0.30.tar.gz
下载依赖
##安装make,已安装,可省略
yum -y install gcc automake autoconf libtool make
##安装gcc g++ glibc库
yum -y install gcc gcc-c++ glibc
//yum -y install libmcrypt-devel mhash-devel 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
yum -y install gcc openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
cd php-7.0.30
编译安装
/* 1、
./configure --prefix=/usr/local/php --with-openssl --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-libmbfl --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm --with-sodium
注意编译失败后需要解决问题后重新编译
yum install openldap yum install openldap-devel
cp -frp /usr/lib64/libldap* /usr/lib/
2、
cp -frp /usr/lib64/libldap* /usr/lib/
*/
安装
make && make install
有如下报错 configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决
yum install -y epel-release
yum install -y libmcrypt-devel
重新编译
1)配置php.ini,这是php的配置文件:
cp /home/php-7.0.30/php.ini-development /usr/local/php/lib/php.ini
2)配置php-fpm.conf,这是php-fpm配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
3)配置www.conf,配置用户的文件:*** 没有
cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
4)将php-fpm启动文件复制到init.d文件夹中一份方便启动php:
cp /usr/local/php/sbin/php-fpm /etc/init.d/php-fpm
执行命令/etc/init.d/php-fpm即可
查看是否启动:ps -ef |grep php
遇到问题
WARNING: Nothing matches the include pattern ‘/usr/local/php7/etc/php-fpm.d/*.conf’
解决方案
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
/usr/local/php/sbin/php-fpm -t
[12-Oct-2017 08:33:29] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm done
执行上面之后再次 make && make install
export PATH=$PATH:/usr/local/php/etc/php-fpm.d (配置)
安装成功后配置nginx支持php
1)更改php.ini文件,vim /usr/local/php/lib/php.ini
通过查找cgi.fix_pathinfo=1这个配置,并去除注释,并改为cgi.fix_pathinfo=0,这里并不属于nginx支持php配置相关,而是专属于nginx下php的一个安全漏洞,如果这里值为1,用户方可以通过上传图片来上传木马,然后通过url访问该图片地址,并在地址后加入/xxx.php将该图片作为php文件运行,这是只有在nginx里才会存在的问题,apache和iis都没有该问题
以上问题可以直接参看鸟哥的博客,写的相当详细:http://www.laruence.com/2010/05/20/1495.html
2)配置web专用的组和用户
添加www用户组:groupadd www
添加www用户组下的用户www:useradd -g www www
3)更改php-fpm.conf配置
将user=nobody的注释去掉,并将nobody改成上面配置的www用户
将group=nobody的注释去掉,并将nobody改成上面配置的www用户组
最后检查php-fpm.conf最后的include的值是不是正确的www.conf目录地址,如果不正确则换成正确的目录地址。
4)更改www.conf配置
将user=nobody的注释去掉,并将nobody改成上面配置的www用户
将group=nobody的注释去掉,并将nobody改成上面配置的www用户组
5)更改nginx.conf文件 /etc/local/nginx/conf/nginx.conf
将#user=nobody去掉注释并改为user=www
去除 location ~ .php . . . 这 段 代 码 的 注 释 , 并 将 f a s t c g i p a r a m 里 的 / s c r i p t s 改 为 {...}这段代码的注释,并将fastcgi_param里的/scripts改为 ...这段代码的注释,并将fastcgiparam里的/scripts改为document_root
最后将location / {…}里默认index后面添加上index.php,确保index.php作为默认的首页
6)重启php-fpm和nginx,可以killall php-fpm然后再/etc/init.d/php-pfm即可重启,/usr/local/nginx/sbin/nginx -s stop即可停止nginx,然后执行/usr/local/nginx/sbin/php即可重启。
7)在html目录里随便创建一个php文件,内容是phpinfo();,然后在浏览器中访问该文件地址,看是否得到正确的php相关信息,如果正确显示则配置成功。
** 修改php.ini
error_reporting = E_ALL & ~E_DEPRECATED 错误报告类型
short_open_tag = On 开启短标签
display_errors = Off 关闭在网页上显示错误
log_errors = On 记录错误
error_log = /opt/logs/php_errors.log 记录错误文件位置
post_max_size = 128M 允许 post 的数据大小
upload_max_filesize = 1024M 允许上传的文件大小
date.timezone = Asia/Shanghai 默认的时区
** php-fpm.conf 修改
pid = run/php-fpm.pid 进程文件位置
error_log = log/php-fpm.log 记录错误位置
daemonize = yes 守护进程运行模式
user = www 运行用户名
group = www 运行用户组
listen = 127.0.0.1:9000 CGI 监听端口和 IP
pm = static 进程管理器运行模式
pm.max_children = 32 开启子进程数量
pm.max_requests = 500 子进程重启阈值
slowlog = log/slow.log 慢查询日志
request_slowlog_timeout = 5 慢查询阈值
request_terminate_timeout = 30 请求超时阈值
// 配置redis 将安装redis 的redis.so 配置到 php.ini 文件中
extension=* 安装redis目录*/redis.so
重启php
php 配置启动(设置环境变量)
//export PATH=$PATH:/usr/local/php/bin
ln -s /usr/local/php/bin/php /usr/bin/php
php 配置文件需要移动到etc目录下
3.1安装composer
1、yum 安装
curl -sS https://getcomposer.org/installer | php
2、下载安装
chmod -R 777 /usr/local/bin/composer
并且放置到这个目录下 /usr/local/bin/composer
wget https://getcomposer.org/download/1.0.0-alpha11/composer.phar
php composer.phar init
参考
{
“name”: “myProject”,
“description”: “The Composer”,
“keywords”: [" "],
“license”: “MIT”,
“type”: “project”,
“require”: { },
“repositories”: {
“packagist”: {
“type”: “composer”,
“url”: “https://packagist.phpcomposer.com”
}
}
}
4、 安装swoole
cd /usr/local/src
wget https://github.com/swoole/swoole-src/archive/v1.9.1-stable.tar.gz
tar zxvf v1.9.1-stable.tar.gz
rm -rf v1.9.1-stable.tar.gz
cd swoole-src-1.9.1-stable
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
配置
vi /usr/local/php/etc/php.ini#编辑配置文件,在最后一行添加以下内容(查找php.ini最好的方法就是phpinfo)
添加
extension=swoole.so
:wq!#保存退出
重启
service php-fpm restart
如果报错就杀死进程方式 重启
ps -le | grep php-fpm
kill -QUIT 7378
然后 service php-fpm
或者 service php-fpm -R
安装PHP扩展phpredis
这个扩展有问题采用下面的git 包
cd /usr/local/src ### 指定安装目录
/* wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz ### 下载源码包(和php版本相关)
/* tar -zxvf 2.2.4.tar.gz ### 解压
cd phpredis-2.2.4
whereis phpize ### 查看php安装生成的phpize命令目录
#需要执行下面一行
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config ### 配置
make
make install
在make 出现错误 :
解决方案
在这地址下git 获取源码然后再重新执行
https://github.com/nicolasff/phpredis
git 地址
https://github.com/phpredis/phpredis.git
make install 后 会出现
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
修改配置
vim /usr/local/php/etc/php.ini
将 /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012
下的redis.so 复制一个到安装目录 home/redis-2.8.17/src/
[redis]
extension_dir = /usr/local/php/lib/php/extensions/no-debug-zts-20170718/ ### 目录为上一步编译安装的输出目录
extension = redis.so
git 下的 php redis 扩展包
安装git
sudo dnf install git-all
5、安装mysql
1、找是否已有mysql
rpm -qa | grep mysql
如果有 强力删除
rpm -e --nodeps mysql-libs-5.1.73-5.el6_6.x86_64
再执行一次查询
ps -aux | grep mysql
为空那么需要清理对应文件
执行
命令 whereis mysql
执行结果 mysql: /usr/bin/mysql /usr/include/mysql
命令 find / -name mysql
执行结果 /data/mysql
执行结果 /data/mysql/mysql
移除命令
rm -rf /usr/bin/mysql /usr/include/mysql /data/mysql /data/mysql/mysql
如果空那就继续
用户组
[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd |grep mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
[root@localhost /]#
下载
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
yum -y install numactl
配置
[root@localhost bin]# vi /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1
启动
/usr/local/mysql/support-files/mysql.server start
如果出现错误杀死进程然后重启
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
service mysql restart
设置开机启动
1、将服务文件拷贝到init.d下,并重命名为mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
chmod +x /etc/init.d/mysqld
3、添加服务
chkconfig --add mysqld
4、显示服务列表
chkconfig --list
重置mysql 密码
#编辑
vim /etc/my.cof
skip-grant-tables
#添加这个
#然后重启
service mysql restart
mysql -uroot -p
#直接登录没有密码
#然后设置密码
update mysql.user set authentication_string=password(‘edwin’) where user=‘root’ and Host = ‘localhost’;
#刷新权限
flush privileges;
exit;
#退出mysql 后去除之前添加的 skip-grant-tables
#然后重启
service mysql restart
设置mysql 远程连接账号密码
#第一重置密码
ALTER USER USER() IDENTIFIED BY ‘edwinwan’
// 这个是服务端登录密码
#第二步
grant all privileges on . to root@"%" identified by “edwin” with grant option;
设置远程登录账号密码
#第三步 保存设置
flush privileges;
#第四 重启mysql
service mysql restart
装完后 远程连接密码 是 edwin 而 本地连接是 edwinwan
用户名都是root
The openssl extension is missing, which means that secure HTTPS transfers are impossible.
If possible you should enable it or recompile php with --with-openssl
安装openssl
切换到php安装目录
cp ./config0.m4 ./config.m4
然后执行
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
(php-config文件的路径)
/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
出现这个表示成功了然后加这个配置到php.ini 中
extension=openssl.so
然后重启php
openssl,so
/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012
php
设计架构https://learnku.com/docs/php-design-patterns/2018/about/1524
安装composer
第一步,下载composer。(切换到项目的根目录,再执行)
php -r “readfile(‘https://getcomposer.org/installer’);” | php
下载之后后自动安装,执行 php composer.phar。查看composer是否安装成功。
第二步,将composer.phar文件移动到bin目录以便全局使用composer命令
mv composer.phar /usr/local/bin/composer(如果只是针对某个项目使用composer,可忽略此步)
第三步,切换国内源(如果第一步下载成功,可忽略此步)
composer config -g repo.packagist composer https://packagist.phpcomposer.com
我这边安装tp5 出现
Linux下的段错误(Segmentation fault)
解决方案 是这个但是我这边没有解决
https://blog.youkuaiyun.com/YSBJ123/article/details/50035169
~/segfault$ #linux 这个我这边用不了
改用git 安装
https://www.kancloud.cn/manual/thinkPHP5_1/353948
先执行
git clone https://github.com/top-think/think /www/tp5
git clone https://github.com/top-think/framework /www/thinkphp ** 修改
#默认是tp5
git checkout 5.1
#切换分支
git pull
将thinkphp 文件放到tp5 里面 也就是
git clone https://github.com/top-think/framework /www/tp5/thinkphp 即可
安装第二个版本的php 或者第三个
cd /home
wget https://www.php.net/distributions/php-7.3.19.tar.gz
tar -zxvf php-7.3.19.tar.gz
cd php-7.3.19
./configure --prefix=/usr/local/php73 --with-config-file-path=/usr/local/php73/etc
–with-curl
–with-freetype-dir
–with-gd
–with-gettext
–with-iconv-dir
–with-kerberos
–with-libdir=lib64
–with-libxml-dir
–with-mysqli
–with-openssl
–with-pcre-regex
–with-pdo-mysql
–with-pdo-sqlite
–with-pear
–with-png-dir
–with-memcache
–with-xmlrpc
–with-xsl
–with-zlib
–enable-fpm
–enable-bcmath
–enable-libxml
–enable-inline-optimization
–enable-mbregex
–enable-mbstring
–enable-pcntl
–enable-shmop
–enable-soap
–enable-sockets
–enable-sysvsem
–enable-xml
–enable-zip
//去除这个
–enable-gd-native-ttf \ --with-mysql 不支持 \被移除
make && make install
cp -R ./sapi/fpm/php-fpm.conf /usr/local/php73/etc/php-fpm.conf
cp php.ini-development /usr/local/php73/lib/php.ini
cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm73
7.2 编译项
7.2.2
./configure --prefix=/usr/local/php72 --with-config-file-path=/usr/local/php72/etc
–with-curl --with-freetype-dir --with-gd
–with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex
–with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2
–with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex
–enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm
–enable-xml --enable-zip --with-ldap
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp -R ./sapi/fpm/php-fpm.conf /usr/local/php72/etc/php-fpm.conf
cp php.ini-development /usr/local/php72/lib/php.ini
cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm72
报错 :configure: error: Cannot find ldap.h
解决办法: yum install openldap openldap-devel -y
2、报错 configure: error: Cannot find ldap libraries in /usr/lib
解决方法 : cp -frp /usr/lib64/libldap* /usr/lib/ 增加软连接
linux环境php7.2编译安装时,提示unrecognized options: –with-mcrypt, –enable-gd-native-ttf
表示已经不支持 –with-mcrypt, –enable-gd-native-ttf 将其移除后编译
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
解决办法 yum install libicu-devel
configure: error: Cannot find ldap libraries in /usr/lib.
cp -frp /usr/lib64/libldap* /usr/lib/
如果还有报错
解决方法:编辑 vim Makefile 大约77 行左右的地方: EXTRA_LIBS = … -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = … ‘-lcrypt -liconv’ 。
要执行一下 make clean 不然报错 ,然后在执行 make
更改环境变量中的值
echo $PATH
1.对所有用户永久有效
cd /etc
vim /etc/profile
加上 export PATH=/usr/local/php/bin:$PATH
保存退出
source /etc/profile
完成.
php -v
/usr/local/php73/etc/php-fpm.d里的 www.conf.com 配置文件 复制文件将文件名变为 php-fpm.conf 然后修改这个文件中的listen 9000
修改php-fpm.conf的侦听端口为9001 逐渐上加 比如9002 9003
listen = 127.0.0.1:9001
启动 php73
/etc/init.d/php-fpm73
编译时报错报错1
error: Please reinstall the libzip distribution
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make -j4 && make install
报错2
configure: error: off_t undefined; check your library configuration
修改配置
/etc/ld.so.conf/ 下的配置文件 进行编辑 添加以下内容
/usr/local/lib64 /usr/lib64
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
更新配置
ldconfig -v
再进行编译
出现这个
config.status: executing default commands
// 这个是失败的 configure: WARNING: unrecognized options: --with-mysql, --enable-gd-native-ttf
表示成功了
然后再进行 make 安装
报错3
/usr/local/include/zip.h:59:10: fatal error: zipconf.h: No such file or directory
#include <zipconf.h>
^~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1764: ext/zip/php_zip.lo] Error 1
将文件复制到该文件夹下
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
安装memcache
列表地址:http://pecl.php.net/package/memcached
源码包直接下载地址:http://pecl.php.net/get/memcached
此外还有一个git维护地址 https://github.com/php-memcached-dev/php-memcached
这个包最新版本是2017年11月份更新的,是支持php7.0的。
./configure --with-php-config=/usr/local/php/bin/php-config
http://xuexi.jade2707.top/ 邮箱发送验证码