mysql+php

来源:互联网 发布:js输入框新增span 编辑:程序博客网 时间:2024/05/22 06:22
###mysqly源码安装+php源码安装及mysql+php的应用案例###

1.安装数据库
源码编译
[root@server1 ~]# tar zxf lamp/mysql-boost-5.7.11.tar.gz
[root@server1 ~]# ls
anaconda-ks.cfg  install.log.syslog  mysql-5.7.11
install.log      lamp                nginx-1.12.0
[root@server1 ~]# cd mysql-5.7.11/
[root@server1 mysql-5.7.11]# yum install gcc-c++ ncurses-devel  cmake-2.8.12.2-4.el6.x86_64.rpm openssl-devel -y
##解决软件包依赖性
[root@server1 mysql-5.7.11]# 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/
##-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql指定安装目录
  -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data指定数据库存放位置
  -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sockUnix socket 文件路径
  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1安装存储引擎
  -DDEFAULT_CHARSET=utf8使用 utf8 字符
  -DDEFAULT_COLLATION=utf8校验字符
  -DEXTRA_CHARSETS=all安装所有扩展字符集
[root@server1 mysql-5.7.11]# rm -fr CMakeCache.txt

[root@server1 mysql-5.7.11]# make && make install    ##安装编译


[root@server1 mysql-5.7.11]# groupadd -g 27 mysql    ##建立mysql组,mysql默认id是27
[root@server1 mysql-5.7.11]# useradd -u 27 -g 27 -s /sbin/nologin -M -d /usr/local/lnmp/mysql mysql
##建立mysql用户
[root@server1 mysql-5.7.11]# vim  /etc/passwd
 22 mysql:x:27:27::/usr/local/lnmp/mysql/data:/sbin/nologin
[root@server1 mysql-5.7.11]# df -h
Filesystem                    Size  Used Avail Use% Mounted
/dev/mapper/VolGroup-lv_root   19G  9.3G  8.1G  54% /
tmpfs                         499M     0  499M   0% /dev/shm
/dev/vda1                     485M   33M  427M   8% /boot
[root@server1 mysql-5.7.11]# useradd -u 27 -g 27 -s /sbin/nologin -M -d /usr/local/lnmp/mysql mysql
##建立mysql用户
[root@server1 mysql-5.7.11]# cd /usr/local/lnmp/mysql/bin/
[root@server1 bin]# vim ~/.bash_profile         ##全局变量,指定变量路径

10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin


[root@server1 bin]# source ~/.bash_profile         ##刷新生效
[root@server1 bin]# cd /usr/local/lnmp/mysql/support-files/
[root@server1 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server1 support-files]# cp my-default.cnf  /etc/my.cnf ##复制mysql配置文件
cp: overwrite `/etc/my.cnf'? y
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld ##mysql.server是一个脚本
[root@server1 support-files]# cd /usr/local/lnmp/mysql
[root@server1 mysql]# mysqld --initialize --user=mysql    ##mysql初始化
2017-07-21T12:30:10.018205Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-21T12:30:10.036273Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2017-07-21T12:30:10.036283Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2017-07-21T12:30:12.596757Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-21T12:30:13.401821Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-21T12:30:13.747568Z 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: 58440a03-6e10-11e7-b374-52540073a1ac.
2017-07-21T12:30:13.862374Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2017-07-21T12:30:13.863223Z 1 [Note] A temporary password is generated for root@localhost: (b<qH8A*mlha


##此出生成的密码(b<qH8A*mlha在第一次登陆数据库是要使用
[root@server1 mysql]# chown root.root . -R        ##mysql目录的所有人和所有组都改成root,. 表示当前

[root@server1 mysql]# chown mysql data -R        ##将data文件的所有人改成mysql用户



[root@server1 mysql]# /etc/init.d/mysqld start        ##开启服务
Starting MySQL.. SUCCESS!
[root@server1 mysql]# mysql -p                ##使用初始化是生成的密码认证登陆msysql
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> ^DBye                        ##此时还不能使用mysql需要进行安全设置





[root@server1 mysql]# mysql_secure_installation     ##mysql安全设置
New password:                         ##修改密码

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    ##禁止匿名用户登陆
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!


[root@server1 mysql]# mysql -p        ##使用修改后的密码认证登陆,数据库可以使用

Enter password:



2.php安装
源码安装
[root@server1 ~]# tar jxf lamp/php-5.6.20.tar.bz2
[root@server1 php-5.6.20]# cd /root/lamp/
[root@server1 lamp]# yum install -y libmcrypt-devel-2.5.8-9.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm
##两个安装包有依赖性,要一起安装
[root@server1 lamp]# yum install -y  mysql-devel libxml2-devel curl-devel libjpeg-turbo-devel-1.2.1-1.el6.x86_64  libpng-devel freetype-devel gmp-devel net-snmp-devel

##解决依赖包问题


[root@server1 lamp]# cd /root/php-5.6.20/
[root@server1 php-5.6.20]#  ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc  --with-mysql=mysqlnd --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd  --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext --with-gmp --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
##指定安装路径--prefix=/usr/local/lnmp/php
##--with-config-file-path=/usr/local/lnmp/php/etc指定配置文件存放位置
##其他均为添加指定模块

[root@server1 lamp]#make && make install



[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/
[root@server1 php]# du -sh
109M    .
[root@server1 php-5.6.20]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.20]# cd sapi/fpm/
[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]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# vim php.ini
925 date.timezone = Asia/Shanghai
[root@server1 etc]# cp php-fpm.conf.default  php-fpm.conf
[root@server1 etc]# vim php-fpm.conf
 25 pid = run/php-fpm.pid
[root@server1 etc]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@server1 etc]# cd /usr/local/lnmp/php/
[root@server1 php]# vim ~/.bash_profile        ##修改变量路径
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[root@server1 php]# source ~/.bash_profile
[root@server1 php]# netstat -antlp | grep :9000    ##php-fpm使用9000端口
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      1643/php-fpm        

[root@server1 php]#  cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf

 49         location / {
 50             root   html;
 51             index index.php index.html index.htm;
 52         }
 76         location ~ \.php$ {
 77             root           html;
 78             fastcgi_pass   127.0.0.1:9000;
 79             fastcgi_index  index.php;
 80             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 81             include        fastcgi.conf;

 82         }


[root@server1 html]# vim index.php
[root@server1 html]# cat index.php
<?php
phpinfo()
?>
[root@server1 html]# nginx
测试页面:

在安装php时加的模块在这里都有






3.应用---构建论坛 

Discuz 的基础架构采用世界上最流行的web编程组合PHP+MySQL实现,是一个经过完善设计,适用于各种服务器环境的高效论坛系统解决方案。

[root@server1 ~]# cd lamp/
[root@server1 lamp]# yum install unzip -y

[root@server1 lamp]# unzip Discuz_X3.2_SC_UTF8.zip


[root@server1 lamp]# mv  upload/ /usr/local/lnmp/nginx/html/bbs
[root@server1 lamp]# cd  /usr/local/lnmp/nginx/html/bbs
测试:


[root@server1 bbs]# chmod 777 config/ data/ uc_client/ uc_server/ -R     ##根据提示改变文件权限

测试:


[root@server1 bbs]# cd  /usr/local/lnmp/php/etc/

[root@server1 etc]# vim php.ini                     ##根据错误提示
1002 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock
1151 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
1210 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock

[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
测试:

[root@server1 etc]# ll -d  /usr/local/lnmp/mysql/data/
drwxr-x--- 5 mysql root 4096 Jul 21 20:56 /usr/local/lnmp/mysql/data/
[root@server1 etc]# chmod 775 /usr/local/lnmp/mysql/data/
测试:



[root@server1 etc]# cd  /usr/local/lnmp/nginx/html/bbs/install/
[root@server1 install]# ls
data  images  include  index.php
[root@server1 install]# rm -fr index.php