前言:yum安装好是好,方便是方便但是内部相关的依赖是不好找,因此要想变成大神那么就要从源码编译安装,而且源码安装还能减少不必要的错误
前期准备
- 将防火墙与selinux关闭
- http://httpd.apache.org/download.cgi //http压缩包
- http://apr.apache.org/download.cgi //http插件包这里要注意安装相同版本的如1.6对应也要1.6
- http://mirrors.sohu.com/mysql/ //mysql压缩包
- http://www.php.net/downloads.php //PHP压缩包
安装httpd(apache)服务
- yum -y install gcc gcc-c++ make pcre-devel expat-devel perl
- tar xf apr-1.6.2.tar.gz
- tar xf apr-util-1.6.0.tar.gz
- tar xf httpd-2.4.29.tar.bz2
- mv apr-1.6.2 httpd-2.4.29/srclib/apr
- mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
- cd httpd-2.4.29
- ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
- make && make install
- cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
- vi /etc/init.d/httpd
- chkconfig --add httpd //将httpd加入到SERVICE管理器
- systemctl daemon-reload //重载系统系统管理器
- vi /usr/local/httpd/conf/httpd.conf
修改 ServerName www.test.com - ln -s /usr/local/httpd/conf/httpd.conf /etc/
- ln -s /usr/local/httpd/bin/* /usr/local/bin/
- httpd –t
- systemctl start httpd
- systemctl enable httpd
- netstat -anpt | grep 80
访问centos返回it workw代表成功
安装mysql
- yum -y install ncurses ncurses-devel bison cmake
- useradd -s /sbin/nologin mysql
- tar xf mysql-boost-5.7.20.tar.gz -C /opt/
- cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //定义安装目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //连接数据库socket路径
-DSYSCONFDIR=/etc \ //指定初始化参数文件目录(my.cnf)
-DSYSTEMD_PID_DIR=/usr/local/mysql \ //数据库目录
-DDEFAULT_CHARSET=utf8 \ //指定默认使用的字符集编码
-DDEFAULT_COLLATION=utf8_general_ci \ //指定默认使用的字符集校对规则,utf8_general_ci是适用于UTF-8字符集的通用规则
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ //支持InnoDB引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ //安装支持数据库分区
-DMYSQL_DATADIR=/usr/local/mysql/data
-DWITH_BOOST=boost
-DWITH_SYSTEMD=1
记得把中文去了不然不知道会报什么错,(注意:如果在CMAKE的过程中有报错,当报错解决后,需要把源码目录中的CMakeCache.txt文件删除,然后再重新CMAKE,否则错误依旧)
- make && make install
- chown -R mysql.mysql /usr/local/mysql/
- vi /etc/my.cnf
(里面内容全部删除,替换成以下内容)
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
chown mysql:mysql /etc/my.cnf
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
//把这两个路径添加到环境变量中,并放到profile文件中使之开机自运行,否则不生效echo 'export PATH' >> /etc/profile
source /etc/profile //立即生效
cd /usr/local/mysql/
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld
netstat -anpt | grep 3306 //查看服务运行状态
systemctl enable mysqld //设为开机启动
mysqladmin -u root -p password "abc123"
//给root账号设置密码为abc123
注意:提示输入的是原始密码(原始没有密码,直接回车)mysql -u root –p //登录数据库
注意:有密码的加“-p”,如果没有密码不用加“-p”
搭建PHP运行环境
https://www.cnblogs.com/chenppp/p/13388748.html //php7.4安装方法
https://www.cnblogs.com/chenppp/p/13276602.html //nginx1.18安装方法
https://www.cnblogs.com/ansibee/p/8087476.html //安装完成后需要添加服务才可以
可能会报错:oniguruma包报错 加上编译参数: --with-libdir=lib64https://www.cnblogs.com/cndavidwang/p/12343847.html
https://blog.csdn.net/gshzh00/article/details/90901121 //开机自启动nginx
https://www.jianshu.com/p/33b44a14ebf7 //开启自启动php-fpm
https://segmentfault.com/a/1190000018849299 //php7.2教程
- 执行nginx所在安装目录并启动 /usr/local/nginx/sbin/nginx
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
(注意:如果安装过程出错,修改下面文件,添加一行)
vi /usr/local/httpd/bin/apxs
#!/usr/bin/perl –w
- tar xjvf php-7.1.10.tar.bz2
- cd php-7.1.10
- ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql-sock=/usr/local/mysql/mysql.sock --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip
- make && make install
- cp php.ini-development /usr/local/php/lib/php.ini
- vi /usr/local/php/lib/php.ini //编辑配置文件
mysqli.default_socket = /usr/local/mysql/mysql.sock //将php与mysql关联
date.timezone = Asia/Shanghai //时区设置
/usr/local/php/bin/php –m //验证安装的模块 - vi /etc/httpd.conf //编辑Apache配置文件,使httpd支持php网页解析
添加以下两行内容:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改以下内容:
DirectoryIndex index.php index.html //此处注意,php文件必须放前面,优先读取 - rm -f /usr/local/httpd/htdocs/index.html //删除默认html文件
- vi /usr/local/httpd/htdocs/index.php //编辑php测试网页
添加以下内容(php信息)
phpinfo();
?> - systemctl start httpd //重启httpd服务
- 常用的编译参数
--help获取./configure脚本帮助
--prefix=: 指定安装路径;多数程序都有默认安装路径;
--sysconfidr=: 指定配置文件安装路径;
--with-PACKAGE[=ARG]:在自由软件社区里,有使用已有软件包和库的优秀传统.当用'configure'来配置一个源码树时,
可以提供其他已经安装的软件包的信息
--without-PACKAGE:有时候你可能不想让你的软件包与系统已有的软件包交互。例如,你可能不想让你的新编译器使用
GNU ld
--enable-FEATURE:一些软件包可能提供了一些默认被禁止的特性,可以使用'--enable-FEATURE'来起用它
--disable-EEATURE:关闭指定的默认特性
1. 安装成功后配置环境变量
打开: /etc/profile 尾部添加
PATH=$PATH:/usr/local/php-7.2.19/bin
export PATH
2. 保存后刷新环境变量
source /etc/profile #更新
3.查看环境变量:
echo $PATH
4.看到php环境变量的路径后,以后就可以直接使用php命令了,查看php版本
php -v
6.现在的PHP没有.ini文件和配置文件,还需要配置PHP-FPM:
cp php.ini-production /etc/php.ini
cp /usr/local/php-7.2.19/etc/php-fpm.conf.default /usr/local/php-7.2.19/etc/php-fpm.conf
cp /usr/local/php-7.2.19/etc/php-fpm.d/www.conf.default /usr/local/php-7.2.19/etc/php-fpm.d/www.conf
cp /usr/localsoft/php-7.2.19/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
7.php-fpm的启动、停止和重启
service php-fpm start #启动
service php-fpm stop #停止
service php-fpm restart #重启
apache下配置多站点
https://blog.csdn.net/qq_27229113/article/details/81252253 //转载他人项目
配置git仓库及安装git
- yum remove git //卸载yum源安装的git
- make configure //解压并进入文件,执行
- ./configure --prefix=/usr/local/git //指定安装目录
- make profix=/usr/local/git //编译
- make install //安装
- echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile //修改环境变量
- source /etc/profile //重启环境变量
- git --version //查看当前版本
参考1:https://blog.51cto.com/13043516/2152749
参考2:https://www.cnblogs.com/dee0912/p/5815267.html
参考3:https://www.jianshu.com/p/2dbe08bc8d40
*参考4:https://www.linuxidc.com/Linux/2018-03/151133.htm
编译安装swoole
1.官网下载
- https://gitee.com/swoole/swoole
2.生成configure,注意要装autoconfig否则无法生成(yum -y install autoconf) - /usr/local/php-7.2.19/bin/phpize //php工具生成前面是你安装路径
- ./configure --with-php-config=/usr/local/php-7.2.19/bin/php-config
- make && make install
- php.ini 引入swool.so文件
编译安装git
*解压后可能会缺少configure 执行autoconf
*可能还会缺少zlib.h: No such file or directory //yum install zlib-devel
- ./configure --prefix=/usr/local/git
- make && make install
*修改环境变量
vi ~/.bash_profile
PATH=$PATH:/home/git
php7安装phpredis
https://blog.csdn.net/guo_qiangqiang/article/details/103178556