安装apache+PHP+Mysql

编程入门 行业动态 更新时间:2024-10-10 02:18:58

安装<a href=https://www.elefans.com/category/jswz/34/1769910.html style=apache+PHP+Mysql"/>

安装apache+PHP+Mysql

@flyok666  2018-07-01 16:58  字数 4762  阅读 333

安装apache+PHP+Mysql

未分类


版本信息: 
apache2.4 
php7.2 
mysql5.6

将所需要的软件放到/root/software/文件夹下

安装Apache及所需依赖

安装zlib

cd /root/software
tar xf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
cd ..

安装apr

tar xf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr
make
make install
cd ..

安装apr-iconv

tar xf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure --prefix=/usr/local/apr-iconv \
--with-apr=/usr/local/apr/
make
make install
cd ..

安装apr-util

tar xf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util/ \
--with-apr=/usr/local/apr/ \
--with-apr-iconv=/usr/local/apr-iconv/bin/apr-iconv
make
make install
cd ..

安装pcre

tar xf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre
make
make install
cd ..
*****出现报错***** 报错 configure: error: You need a C++ compiler for C++ support 解决:
yum install -y gcc gcc-c++
*********************

安装pcre-devel

yum -y install pcre-devel

安装httpd

tar xf httpd-2.4.17.tar.gz
cd httpd-2.4.17
./configure --prefix=/usr/local/lamp/apache2 \
--enable-modules=all \
--enable-so \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre/
make
make install
cd ..

配置httpd管理理脚本

chmod u+x httpd
cp httpd /etc/init.d/httpd

设定ServerName

echo "ServerName 127.0.0.1:80" >> /usr/local/lamp/apache2/conf/httpd.conf

开启服务

service httpd start

添加到开机启动服务

chkconfig --add httpd
chkconfig --level 345 httpd on

安装php及所需依赖

安装libxml2

ln -sf /usr/local/lib/libz.so.1.2.8 /usr/lib64/libz.so
tar xf libxml2-2.7.2.tar.gz
cd libxml2-2.7.2
./configure
make
make install
cd ..

安装jpeg

tar xf jpegsrc.v9b.gz
cd jpeg-9b/
./configure --prefix=/usr/local/jpeg \
--enable-shared \
--enable-static
make
make install
cd ..

安装png

tar xf libpng-1.4.3.tar.gz
cd libpng-1.4.3
./configure --prefix=/usr/local/png \
--enable-shared \
--enable-static
make
make install
cd ..

安装freetype

tar xf freetype-2.7.tar.gz
cd freetype-2.7
./configure --prefix=/usr/local/freetype \
--enable-shared
make
make install
cd ..

安装gd

tar xf libgd-2.2.3.tar.gz
cd libgd-2.2.3
./configure --prefix=/usr/local/gd \
--with-jpeg=/usr/local/jpeg/ \
--with-png=/usr/local/png \
--with-zlib \
--with-freetype=/usr/local/freetype \
--disable-werror
make
make install
cd ..

安装bison

yum -y install bison

安装libmcrypt

tar xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --disable-posix-threads
make
make install
cd ..

将libmcrypt所在路径保存到环境变量中,以便mcrypt安装的时候搜索所需的软件包

export LD_LIBRARY_PATH=/usr/local/lib

安装mhash

tar xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
cd ..

安装mcrypt

tar xf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure --with-libmcrypt-prefix=/usr/local
make
make install
cd ..

安装autoconf

tar xf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure
make
make install
cd ..

安装libiconv

tar xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
cd ..

错误如下:

    In file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make: *** [all] Error 2 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

解决方法:

vi libiconv-1.14/srclib/stdio.in.h
  • 1

将698行的代码:_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");替换为:

#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif

安装libXpm

yum -y install libXpm-devel

安装php

tar xf php-7.2.1.tar.gz
cd php-7.2.1
./configure --prefix=/usr/local/lamp/php \
--with-apxs2=/usr/local/lamp/apache2/bin/apxs \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-freetype-dir=/usr/local/freetype \
--with-gd=/usr/local/gd/ \
--with-zlib \
--with-jpeg-dir=/usr/local/jpeg \
--with-png-dir=/usr/local/png \
--enable-mbstring=all \
--enable-mbregex \
--enable-shared \
--disable-fileinfo \
--with-iconv=/usr/local/libiconv \
--with-libxml-dir=/usr/local \
--with-xpm-dir=/usr/lib \
--enable-fpm 
make
make installcp php.ini-development /usr/local/lamp/php/lib/php.ini
cd ..
配置时区
echo "date.timezone = PRC" >> /usr/local/lamp/php/lib/php.ini
让Apache支持php
echo "AddHandler application/x-httpd-php .php" >> /usr/local/lamp/apache2/conf/httpd.conf
重启Apache
service httpd restart

一般我们选择安装Centos的最小安装,然后我们在使用好多工具的时候就会报错!wget不会默认被安装。需要安装的看我之前的博客。 
1、配置YUM源

下载mysql源安装包

[root@localhost~]#wget .noarch.rpm

 

安装mysql源

[root@localhost~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm 
提示【Is this ok [y/d/N]: y  输入y回车】
检查MySQL源是否安装成功 
[root@localhost ~]# yum repolist enabled | grep “mysql.-community.”

 

2、安装MySQL

[root@localhost ~]# yum install mysql-community-server

 

注意:安装过程中提示【Is this ok [y/d/N]: y 输入y回车】 
出现以下表示安装成功:

Replaced:mariadb-libs.x86_64 1:5.5.56-2.el7 Complete! 

3、启动MySQL服务

[root@localhost ~]# systemctl start mysqld 
查看MySQL的启动状态 
[root@localhost ~]# systemctl status mysqld

4.开机启动

[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
  1. 查看mysql下root账号的默认密码 
    mysql5.7安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql。 
    命令:grep ‘temporary password’ /var/log/mysqld.log
[root@localhost /]# grep 'temporary password' /var/log/mysqld.log
2017-10-17T08:07:03.797098Z 1 [Note] A temporary password is generated for root@localhost: 3prjY9ktM,eL [root@localhost /]# 默认的密码是:3prjY9ktM,eL
  1. 修改配置文件 
    6.1. 默认配置文件路径 
    配置文件:/etc/myf 
    日志文件:/var/log//var/log/mysqld.log 
    服务启动脚本:/usr/lib/systemd/system/mysqld.service 
    socket文件:/var/run/mysqld/mysqld.pid 
    6.2. 修改myf文件 
    6.2.1. 修改密码策略 
    mysql的密码策略分为三种: 
    0或LOW:Length 
    1或MEDIUM:Length; numeric, lowercase/uppercase, and special characters 
    2或STRONG:Length; numeric, lowercase/uppercase, and special characters; dictionary file

在myf文件中增加如下设置

如果不需要密码策略,禁用密码策略

validate_password = off

密码选择策略 0-LOW,1-MEDIUM,2-STRONG需要提供密码字典文件

validate_password_policy = 0

6.2.2. 修改字符编码为utf8 
在[mysqld]下增加如下配置 
character_set_server = utf8 
init_connect = ‘SET NAMES utf8’

例:
[root@localhost /]# cd /etc/
[root@localhost etc]# vi myf
validate_password = off# For advice on how to change settings please see
# .7/en/server-configuration-defaults.html[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid validate_password = off #设置禁用密码策略 character_set_server = utf8 #修改字符编码为utf8 init_connect = 'SET NAMES utf8'

6.2.3. 保存myf并重启mysql服务是配置生效 
命令:systemctl restart mysqld

登录mysql

命令:mysql -uroot -p 
输入密码:默认为刚才查到的密码”3prjY9ktM,eL”

修改密码 
命令:ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘12345678’; 
或命令:set password for ‘root’@’localhost’=password(‘12345678’);

说明: 
1. 如果之前没有设置密码策略,则密码12345678则不会通过验证,密码修改会失败

  1. 密码修改不成功时则部分功能也无法使用,例如查看密码策略 show variables like ‘%password%’;

  2. 查看密码策略 
    命令:show variables like ‘%password%’; 
    此处为 validate_password = off 设置后的结果

  3. 查看字符编码 
    命令:show variables like ‘%character%’;

  4. 添加远程账户 
    命令:GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘12345678’ WITH GRANT OPTION; 
    命令:FLUSH PRIVILEGES; 使设置生效 
    如果你想允许用户myuser从ip为192.168.0.107的主机连接到mysql服务器,并使用mypassword作为密码 
    GRANT ALL PRIVILEGES ON . TO ‘root’@’192.168.59.129’ IDENTIFIED BY ‘12345678’ WITH GRANT OPTION; 
    FLUSH PRIVILEGES;

  5. 至此,可以远程连接并操作数据库啦!

7.退出Mysql命令 
quit或者exit退出mysql

8.service iptables status可以查看到iptables服务的当前状态。 
但是即使服务运行了,防火墙也不一定起作用,你还得看防火墙规则的设置 iptables -L 
在此说一下关于启动和关闭防火墙的命令: 
1) 重启后生效 
开启: chkconfig iptables on 
关闭: chkconfig iptables off 
2) 即时生效,重启后失效 
开启: service iptables start 
关闭: service iptables stop

连接测试提示:2003 can’t connect to mysql server on ‘xxx.xxx.xxx.xxx’(10038) 
解决办法:

centos查询端口是不是开放的

firewall-cmd –permanent –query-port=3306/tcp

添加对外开放端口

firewall-cmd –permanent –add-port=3306/tcp

重启防火墙

firewall-cmd –reload

创建允许远程登录的用户
mysql> CREATE USER 'itsource'@'%' IDENTIFIED BY '123456';
mysql> select password('123456');
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD 'xxxxxx';

添加mysql到系统服务

复制启动文件

cp /usr/local/lamp/mysql/support-files/mysql.server /etc/init.d/mysqld 

添加可执行权限

chmod a+x /etc/init.d/mysqld 

做了上面的步骤就可以使用 service mysqld 来控制 mysql 服务器了 
比如:service mysqld start 可以启动 mysql 服务器

添加到开机启动服务

chkconfig --add mysqld
chkconfig --level 345 mysqld on
+

转载于:.html

更多推荐

安装apache+PHP+Mysql

本文发布于:2024-02-13 06:24:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1757869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:apache   PHP   Mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!