文章目录
一.PHP的源码编译
php的编译及其安装
- 官网下载php的源码包并进行解压,建立php的安装目录。
- 进入解压后的目录,开始编译:
./configure --prefix=/usr/local/lnmp/php #指定php的安装路径
--with-config-file-path=/usr/local/lnmp/php/etc #php配置文件所在目录
--with-openssl #支持openssl加密
--with-snmp
--with-gd
--with-zlib
--with-curl
--with-libxml-dir
--with-png-dir
--with-jpeg-dir
--with-freetype-dir #以上三个为php处理图片的格式
--with-gmp
--with-gettext
--with-pear
--enable-mysqlnd
--with-mysql=mysqlnd
--with-mysqli=mysqlnd#支持与mysql数据库之间建立联系
--with-pdo-mysql=mysqlnd
--enable-inline-optimization
--enable-soap
--enable-ftp
--enable-sockets
--enable-mbstring
--enable-fpm #开启php-fpm服务
--with-fpm-user=nginx #使用nginx用户来限制对php服务
--with-fpm-group=nginx
--with-mcrypt #提供了多种块算法的支持
--with-mhash #加密算法
- 编译的过程会报错,我们按照报错的内容一次一次的搜它所需要的依赖安装就行,解决编译过程遇到的依赖性问题:
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext --with-pear --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
yum install gcc -y
yum install libxml2-devel -y
yum install openssl-devel -y
yum whatprovides */easy.h
yum install libcurl-devel-7.19.7-37.el6_4.x86_64 -y
yum whatprovides */jpeglib.h
yum install libjpeg-turbo-devel-1.2.1-1.el6.x86_64 -y
yum whatprovides */png.h
yum install 2:libpng-devel-1.2.49-1.el6_2.x86_64 -y
yum install freetype-devel -y
yum whatprovides */gmp.h
yum install gmp-devel-4.3.1-7.el6_2.2.x86_64 -y
yum install pcre-devel zlib-devel -y
yum install libmcrypt-* -y
yum install net-snmp-devel -y
- 安装
[root@server1 php-5.6.35]# make && make install
php的相关配置
- 创建nginx用户实现对php的控制。
[root@server1 fpm]# useradd nginx
- 利用配置文件模板生成配置文件。
[root@server1 fpm]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf.default php.ini
[root@server1 etc]# mv php-fpm.conf.default php-fpm.conf
- 修改时区
[root@server1 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.35]# vim /usr/local/lnmp/php/etc/php.ini
- 将php的启动脚本复制到系统的启动目录下并添加执行权限,启动服务,查看php开启的端口。
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm
[root@server1 fpm]# /etc/init.d/php-fpm start
[root@server1 fpm]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@server1 fpm]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 893/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 969/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 13012/php-fpm
tcp 0 0 :::22 :::* LISTEN 893/sshd
tcp 0 0 ::1:25 :::* LISTEN 969/master
二.MYSQL的源码编译
实验环境
- rhel6.5 selinux and iptables disabled
- 因为MYSQL占用的空间大所以需要20G的硬盘,并且内存设置为2048KB,在编译安装的时候可以加快速度。
扩展根分区
步骤:
df -h
fdisk -l
fdisk /dev/vdb
mkfs.ext4 /dev/vdb1
blkid
pvcreate /dev/vdb1
pvs
vgextend VolGroup /dev/vdb1
vgs
lvextend -L 22.5G -n /dev/mapper/VolGroup-lv_root
lvs
resize2fs /dev/mapper/VolGroup-lv_root
df -h
关机,给虚拟机加CPU和内存
源码编译
- 官网下载源码编译并解压。
- 安装编译源码工具cmake
cmake跨平台工具是用来编译mysql源码的,用于设置mysql的编译参数。如安装目录,存放路径,字符编码及排序规则等等
[root@server1 ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
- 安装编译时需要的依赖包
yum install ncurses-devel -y
yum install gcc-c++ -y
yum install bison -y
- 进行编译,加上编译的条件。
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql #指定mysql存放位置
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data #指定数据库中数据存放的路径
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock #链接数据库的socket文件
-DWITH_MYISAM_STORAGE_ENGINE=1 #安装myism引擎存储
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DDEFAULT_CHARSET=utf8 #使用utf-8字符编码
-DDEFAULT_COLLATION=utf8_general_ci #校验字符
-_CHARSETS=all #安装所有的扩展集
-DWITH_BOOST=boost/boost_1_59_0/
[root@server1 mysql-5.7.17]# make && make install
注:如果编译过一次出现问题解决后再次编译回保留缓存文件,再次编译时会报错,因此需要先删除缓存文件,然后再进行编译:rm -rf CMakeCache.txt
mysql的相关配置
- 将编译完成的mysql的启动脚本复制到系统启动服务脚本的默认目录中去
[root@server1 mysql-5.7.17]# cd support-files/
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 support-files]# chmod +x /etc/init.d/mysqld
- 进入源码编译目录,再进入mysql安装的位置,在相关的配置目录下把mysql的配置文件放到/etc/my.cnf
- 编辑配置文件my.cnf,添加mysql的存放路径
[root@server1 support-files]# vim /etc/my.cnf
- 添加mysql用户。
- 将编译生成的mysql二进制命令放进系统的环境变量中,方便调用
[root@server1 support-files]# vim ~/.bash_profile
[root@server1 support-files]# source ~/.bash_profile
- 将mysql目录下的所有文件的所有组都改为mysql用户,实现mysql用户的管理。
[root@server1 support-files]# chown mysql.mysql /usr/local/lnmp/mysql/
- 执行mysql的配置初始化文件。
- 修改权限,mysql只是data目录的所有者。
[root@server1 support-files]# chown root /usr/local/lnmp/mysql/ -R
[root@server1 support-files]# chown mysql /usr/local/lnmp/mysql/data/ -R
- 开启数据库
[root@server1 support-files]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server1.err'.
SUCCESS!
- 登陆查看。
- mysql的安全初始化
[root@server1 support-files]# mysql_secure_installation
- 再次登陆
- 查看mysql的端口(3305)
[root@server1 mysql]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 917/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 993/master
tcp 0 0 :::22 :::* LISTEN 917/sshd
tcp 0 0 ::1:25 :::* LISTEN 993/master
tcp 0 0 :::3306 :::* LISTEN 25074/mysqld
三.Nginx的源码编译
Nginx的源码编译
- 官网下载源码编译包并解压,编译,安装。
tar zxf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --user=nginx --group=nginx
make && make install
nginx的相关配置
- 在配置文件中加入php的相关内容。
- 创建软链接方便调用/。
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
- 检测有无语法错误,开启服务。
[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 conf]# nginx
- 查看nginx的端口,为80。
[root@server1 conf]# netstat -antlupe
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 176997 13028/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 8135 893/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 8347 969/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 0 176229 13012/php-fpm
tcp 0 0 172.25.24.1:22 172.25.24.24:41538 ESTABLISHED 0 8696 1024/sshd
tcp 0 0 172.25.24.1:22 172.25.24.24:41780 ESTABLISHED 0 26582 26029/sshd
tcp 0 0 :::22 :::* LISTEN 0 8137 893/sshd
tcp 0 0 ::1:25 :::* LISTEN 0 8349 969/master
四.测试
- 在nginx默认发布目录下添加所测试的php页面。
[root@server1 conf]# cat /usr/local/lnmp/nginx/html/index.php
<?php
phpinfo();
?>
- 浏览器中测试。
综上,我们的LNMP架构构建成功。