Mysql、PHP、Nginx源码编译过程
一、源码安装php
1、下载php及需要的安装包:
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm
php-5.6.35.tar.bz2
tar jxf php-5.6.35.tar.bz2 ##解压php包
yum install libmcrypt-* -y
2、解决依赖性
yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel gcc zlib-devel prce-devel -y###安装依赖包
3.编译
./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
上图就是编译成功了,如果有报错就继续解决(缺什么就补什么)
4.安装
make && make install
5.安装成功后回出现/var/local/lnmp/php/这个目录
6。到这个目录下编辑php配置文件
cd /usr/local/lnmp/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
25 pid = run/php-fpm.pid##pid行去掉注释
修改时区
cp /root/php-5.6.35/php.ini-production /usr/local/lnmp/php/etc/php.ini
933 [Date]
934 ; Defines the default timezone used by the date functions
935 ; http://php.net/date.timezone
936 date.timezone =Asia/Shanghai
cp /root/php-5.6.35/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
useradd -s /sbin/nologin nginx
/etc/init.d/php-fpm start
nginx编译安装:
1.获得并解压安装包
tar zxf nginx-1.17.0.tar.gz
2.编译
需要解决的依赖
yum install prce-devel -y
./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
安装完成会生成/usr/local/lnmp/nginx 这个目录
修改配置文件如下
vim conf/nginx.conf
3 worker_processes 2; ##2表示cpu内核数
43 location / {
44 root html;
45 index index.php index.htm; ##添加php
46 }
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; ##注释掉
70 include fastcgi.conf; ##改为fastcgi.conf 71 }
检测配置文件语法有无错误
开启nginx,查看端口
netstat -nlpt
测试nginx
nginx是没有问题的,现在我们写一个php页面,在来测试
cd /usr/local/lnmp/nginx/html
vi index.php
再测试
没有问题,说明php和nginx的结合成功了
三、mysql的编译安装
在编译安装前县查看自己的内存,需要20g,如果较小需要扩容
安装必要的软件
yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y ##选择合适的版本,编译需要的软件
yum install -y ncurses-devel ##安装依赖性
yum install gcc gcc-c++ -y
yum install -y bison
编译:
mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=boost/boost_1_59_0/
make && make install
mysql安装好后
将编辑生成的mysql启动脚本复制到系统服务的目录中,保证脚本有可执行权限
将mysql的配置文件复制到etc下
(养成好习惯,次类操作前先备份:备份/etc/my.cnf文件为/etc/my.cnf.bak)
[root@6 support-files]# cp mysql.server /etc/init.d/mysqld##设置启动方式
[root@6 support-files]# chmod +x /etc/init.d/mysqld
[root@6 support-files]# cp /etc/my.cnf /etc/my.cnf.bak
[root@6 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
编辑配置文件
[root@6 ~]# vim /etc/my.cnf
7 [mysqld]
18 basedir = /usr/local/lnmp/mysql
19 datadir = /usr/local/lnmp/mysql/data
20 # port = .....
21 # server_id = .....
22 socket = /usr/local/lnmp/mysql/data/mysql.sock
23
30
31 #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
建立mysql组和mysql组用户mysql
[root@6 ~]# groupadd -g 27 mysql
[root@6 ~]# useradd -u 27 -g 27 mysql
[root@6 ~]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
[root@6 ~]# chown mysql.mysql /usr/local/lnmp/mysql -R
将编译生成的mysql二进制命令放进系统环境变量的文件中,保证可以直接使用二进制命令
[root@6 ~]# vim ~/.bash_profile
9
10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
[root@6 ~]# source ~/.bash_profile #调用
[root@6 ~]# chown root /usr/local/lnmp/mysql -R
[root@6 ~]# cd /usr/local/lnmp/mysql
[root@6 ~]#mkdir data
[root@6 ~]# chown mysql /usr/local/lnmp/mysql/data -R
将mysql初始化,这时data目录下不能有任何文件,如果有的话删除
[root@6 ~]# mysqld --user=mysql --initialize
2019-07-25T06:03:42.149123Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-25T06:03:43.956664Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-07-25T06:03:44.299497Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-25T06:03:44.337093Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f5814f35-aea1-11e9-888b-525400f36233.
2019-07-25T06:03:44.343367Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-07-25T06:03:44.346972Z 1 [Note] A temporary password is generated for root@localhost: d8KxxvopQp*S
安全初始化,修改新密码
[root@6 mysql]# /etc/init.d/mysqld start
[root@6 ~]# mysql_secure_installation
这里的密码是上面的localhost:后的内容(高亮部分),复制过来,
然后修改新的密码
初始化数据库
[root@6 ~]# mysql -uroot -p
Enter password:
登陆查看databases
mysql完成!!!
顺便来个论坛部署
获得一个前端的包
Discuz_X3.2_SC_UTF8.zip
[root@6 ~]# yum install unzip
[root@6 ~]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/
[root@6 sbin]# 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:80 0.0.0.0:* LISTEN 21722/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 890/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 966/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 21715/php-fpm
tcp 0 0 :::22 :::* LISTEN 890/sshd
tcp 0 0 ::1:25 :::* LISTEN 966/master
tcp 0 0 :::3306 :::* LISTEN 21653/mysqld
查看php,nginx是否都开启了
配置mysql的配置文件
[root@6 sbin]# vim /usr/local/lnmp/php/etc/php.ini
1013 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
1162 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
1221 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
[root@6 sbin]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@6 sbin]#