Apache(httpd)和PHP是一个总体,PHP是以一个模块的形式和Apache(httpd)结合在一块儿的,Apache(httpd)不能直接和MySQL通讯,只能经过PHP模块链接MySQL传递数据,而后PHP模块将搜集到数据传递Apache(httpd),Apache(httpd)再讲数据传递给用户。这种行为叫作动态请求。php
用户浏览器经过Apache(httpd)访问网站上一些静态的文件(图片),而后返回给用户,并无经过MySQL,叫静态请求。MySQL里面存储数据,并不存储图片信息。html
安装MySQL思路python
[root@xuexi-001 ~]# cd /usr/local/src/ ······//进入到src目录下 [root@xuexi-001 src]# ls ······//查看当前目录下的文件 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz ······//解压下载好的Mysql文件 [root@xuexi-001 src]# ls mysql-5.6.36-linux-glibc2.5-x86_64 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql ······//移动mysql-5.6.36-linux-glibc2.5-x86_64目录至/usr/local/下并更名字为 mysql [root@xuexi-001 src]# cd /usr/local/mysql/ [root@xuexi-001 mysql]# ls bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench [root@xuexi-001 mysql]# useradd mysql [root@xuexi-001 mysql]# mkdir /data/ [root@xuexi-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql ······//执行初始化 FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper ······ //报错 提示错误信息,缺乏perl和Dumper包 [root@xuexi-001 mysql]# yum list |grep perl |grep -i dumper ······//进行模糊搜索 grep -i 忽略大小写 perl-Data-Dumper.x86_64 2.145-3.el7 base perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel perl-Data-Dumper-Names.noarch 0.03-17.el7 epel perl-XML-Dumper.noarch 0.81-17.el7 base ······//在不确认是依赖于哪一个包的状况下 这几个包都安装上,这里须要安装的包是 perl-Data-Dumper [root@xuexi-001 mysql]# yum install -y perl-Data-Dumper [root@xuexi-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql ······ //执行初始化 提示报错信息,缺乏libaio Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory [root@xuexi-001 mysql]# yum install -y libaio ······//安装libaio这个包 [root@xuexi-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql ······ //执行初始化成功 Installing MySQL system tables...2018-06-23 00:22:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-06-23 00:22:31 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-06-23 00:22:31 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 3004 ... 2018-06-23 00:22:31 3004 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-06-23 00:22:31 3004 [Note] InnoDB: The InnoDB memory heap is disabled 2018-06-23 00:22:31 3004 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-06-23 00:22:31 3004 [Note] InnoDB: Memory barrier is not used 2018-06-23 00:22:31 3004 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-06-23 00:22:31 3004 [Note] InnoDB: Using Linux native AIO 2018-06-23 00:22:31 3004 [Note] InnoDB: Using CPU crc32 instructions 2018-06-23 00:22:31 3004 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-06-23 00:22:31 3004 [Note] InnoDB: Completed initialization of buffer pool 2018-06-23 00:22:31 3004 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2018-06-23 00:22:31 3004 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2018-06-23 00:22:31 3004 [Note] InnoDB: Database physically writes the file full: wait... 2018-06-23 00:22:31 3004 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2018-06-23 00:22:32 3004 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2018-06-23 00:22:33 3004 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2018-06-23 00:22:33 3004 [Warning] InnoDB: New log files created, LSN=45781 2018-06-23 00:22:33 3004 [Note] InnoDB: Doublewrite buffer not found: creating new 2018-06-23 00:22:33 3004 [Note] InnoDB: Doublewrite buffer created 2018-06-23 00:22:33 3004 [Note] InnoDB: 128 rollback segment(s) are active. 2018-06-23 00:22:33 3004 [Warning] InnoDB: Creating foreign key constraint system tables. 2018-06-23 00:22:33 3004 [Note] InnoDB: Foreign key constraint system tables created 2018-06-23 00:22:33 3004 [Note] InnoDB: Creating tablespace and datafile system tables. 2018-06-23 00:22:33 3004 [Note] InnoDB: Tablespace and datafile system tables created. 2018-06-23 00:22:33 3004 [Note] InnoDB: Waiting for purge to start 2018-06-23 00:22:33 3004 [Note] InnoDB: 5.6.36 started; log sequence number 0 2018-06-23 00:22:33 3004 [Note] Binlog end 2018-06-23 00:22:33 3004 [Note] InnoDB: FTS optimize thread exiting. 2018-06-23 00:22:33 3004 [Note] InnoDB: Starting shutdown... 2018-06-23 00:22:35 3004 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK ·····//第一个 Filling help tables...2018-06-23 00:22:35 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2018-06-23 00:22:35 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 2018-06-23 00:22:35 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 3026 ... 2018-06-23 00:22:35 3026 [Note] InnoDB: Using atomics to ref count buffer pool pages 2018-06-23 00:22:35 3026 [Note] InnoDB: The InnoDB memory heap is disabled 2018-06-23 00:22:35 3026 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2018-06-23 00:22:35 3026 [Note] InnoDB: Memory barrier is not used 2018-06-23 00:22:35 3026 [Note] InnoDB: Compressed tables use zlib 1.2.3 2018-06-23 00:22:35 3026 [Note] InnoDB: Using Linux native AIO 2018-06-23 00:22:35 3026 [Note] InnoDB: Using CPU crc32 instructions 2018-06-23 00:22:35 3026 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2018-06-23 00:22:35 3026 [Note] InnoDB: Completed initialization of buffer pool 2018-06-23 00:22:35 3026 [Note] InnoDB: Highest supported file format is Barracuda. 2018-06-23 00:22:35 3026 [Note] InnoDB: 128 rollback segment(s) are active. 2018-06-23 00:22:35 3026 [Note] InnoDB: Waiting for purge to start 2018-06-23 00:22:35 3026 [Note] InnoDB: 5.6.36 started; log sequence number 1625977 2018-06-23 00:22:35 3026 [Note] Binlog end 2018-06-23 00:22:35 3026 [Note] InnoDB: FTS optimize thread exiting. 2018-06-23 00:22:35 3026 [Note] InnoDB: Starting shutdown... 2018-06-23 00:22:37 3026 [Note] InnoDB: Shutdown completed; log sequence number 1625987 OK ······//第二个 To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password 'new-password' ./bin/mysqladmin -u root -h xuexi-001 password 'new-password' Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: Found existing config file ./my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as ./my-new.cnf, please compare it with your file and take the changes you need. WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server ····· //检查执行是否成功,检查文件里面有两个OK。另外一种方法 使用echo $? 看看结果是不是0 [root@xuexi-001 mysql]# echo $? 0 [root@xuexi-001 mysql]# ls support-files/my-default.cnf support-files/my-default.cnf ······//mysql模板配置文件 [root@xuexi-001 mysql]# cp support-files/my-default.cnf /etc/my.cnf ······ // mysql的配置文件叫 my.cnf 并且是固定在/etc/目录下 [root@xuexi-001 mysql]# ls /etc/my.cnf /etc/my.cnf ······// 系统中有一个自带的/etc/my.cnf若是想使用自带的my.cnf 须要更改里面的配置文件内容 [root@xuexi-001 mysql]# vi /etc/my.cnf [mysqld] datadir=/data/mysql ······// 须要更改mysql路径 socket=/tmp/mysql.sock ······//socket改成/tmp/下 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] #log-error=/var/log/mariadb/mariadb.log #pid-file=/var/run/mariadb/mariadb.pid ······//后面这两行内容暂时不用能够注释 # # include all files from the config directory # #!includedir /etc/my.cnf.d ······//配置文件完成后,须要拷贝启动脚本 [root@xuexi-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld ······//将启动脚本文件拷贝至/etc/init.d/下并更名为mysqld [root@xuexi-001 mysql]# vi /etc/init.d/mysqld ······//编辑启动脚本文件 #!/bin/sh # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB # This file is public domain and comes with NO WARRANTY of any kind # MySQL daemon start/stop script. ······ # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mysql datadir=/data/mysql ······//须要更改的两个地方 # Default value, in seconds, afterwhich the script should timeout waiting # for server start. ······ [root@xuexi-001 mysql]# chmod 755 /etc/init.d/mysqld ······//赋予755权限,默认权限为755 [root@xuexi-001 mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10592 6月 23 00:51 /etc/init.d/mysqld [root@xuexi-001 mysql]# chkconfig --add mysqld ······//设置开机启动,须将mysqld加入到系统服务启动列表中 [root@xuexi-001 mysql]# chkconfig --list \ 注:该输出结果只显示 SysV 服务,并不包含 原生 systemd 服务。SysV 配置数据 可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。 查看在具体 target 启用的服务请执行 'systemctl list-dependencies [target]'。 mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 ······//查看系统服务启动列表 其余方式启动 [root@xuexi-001 mysql]# service mysqld start [root@xuexi-001 mysql]# /etc/init.d/mysqld start ······ [root@xuexi-001 mysql]# service mysqld start Starting MySQL.Logging to '/data/mysql/xuexi-001.err'. . SUCCESS! [root@xuexi-001 mysql]# ps aux |grep mysql ······//查看启动的进程 root 3652 0.0 0.0 11772 1604 pts/0 S 01:10 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/xuexi-001.pid mysql 3789 0.8 24.0 1300780 449572 pts/0 Sl 01:10 0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xuexi-001.err --pid-file=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sock root 3831 0.0 0.0 112676 980 pts/0 R+ 01:12 0:00 grep --color=auto mysql [root@xuexi-001 mysql]# netstat -lntp ······//查看监听的端口 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 934/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1136/master tcp6 0 0 :::22 :::* LISTEN 934/sshd tcp6 0 0 ::1:25 :::* LISTEN 1136/master tcp6 0 0 :::3306 :::* LISTEN 3789/mysqld 若是没有将启动脚本/etc/init.d/下或者没有启动脚本可使用如下方法启动(命令行启动) [root@xuexi-001 mysql]# service mysqld stop Shutting down MySQL.. SUCCESS! ······//中止mysql服务 [root@xuexi-001 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql & [1] 4112 [root@xuexi-001 mysql]# 180623 01:23:00 mysqld_safe Logging to '/data/mysql/xuexi-001.err'. 180623 01:23:00 mysqld_safe Starting mysqld daemon with databases from /data/mysql ^C ······//使用命令行启动服务 [root@xuexi-001 mysql]# !ps ······//查看启动进程 ps aux | grep mysql root 4112 0.0 0.0 113260 1616 pts/0 S 01:22 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql mysql 4237 1.9 24.0 1300780 449536 pts/0 Sl 01:22 0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xuexi-001.err --pid-file=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sock root 4260 0.0 0.0 112676 984 pts/0 R+ 01:23 0:00 grep --color=auto mysql
若是使用命令行的模式启动的mysql,要想关闭Mysql就须要使用killall mysqldmysql
[root@xuexi-001 mysql]# killall mysqld [root@xuexi-001 mysql]# 180623 01:27:33 mysqld_safe mysqld from pid file /data/mysql/xuexi-001.pid ended [1]+ 完成 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql [root@xuexi-001 mysql]# !ps ps aux | grep mysql root 4308 0.0 0.0 112676 980 pts/0 R+ 01:27 0:00 grep --color=auto mysql
不到万不得已不要使用kill ,可以使用kill + pid 数据传输过程当中强制杀死会形成数据的丢失以及磁盘的损坏 ,最好使用killall + 服务名称 ,killall相对安全。使用killall会先中止当前的写读操做,而后将没有写入到磁盘的数据慢慢写入到磁盘中去,直到数据传输完成,才把进程杀死。linux
basedir=/usr/local/mariadbweb
datadir=/data/mariadbsql
conf=/usr/local/mariadb数据库
[root@xuexi-001 ~]# cd /usr/local/src/ [root@xuexi-001 src]# ls mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# tar -zxvf mariadb-10.2.6-linux-glibc_214-x86_64 [root@xuexi-001 src]# ls mariadb-10.2.6-linux-glibc_214-x86_64 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb [root@xuexi-001 src]# cd /usr/local/mariadb/ [root@xuexi-001 mariadb]# ls bin DESTINATION lib scripts COPYING docs man share COPYING.thirdparty EXCEPTIONS-CLIENT mysql-test sql-bench CREDITS include README.md support-files data INSTALL-BINARY README-wsrep [root@xuexi-001 mariadb]# useradd mysql [root@xuexi-001 mariadb]# mkdir /data/ [root@xuexi-001 mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb Installing MariaDB/MySQL system tables in '/data/mariadb' ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: '/usr/local/mariadb//bin/mysqladmin' -u root password 'new-password' '/usr/local/mariadb//bin/mysqladmin' -u root -h xuexi-001 password 'new-password' Alternatively you can run: '/usr/local/mariadb//bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb' You can test the MariaDB daemon with mysql-test-run.pl cd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ [root@xuexi-001 mariadb]# echo $? 0 [root@xuexi-001 mariadb]# ls support-files/ binary-configure my-large.cnf mysql-log-rotate wsrep_notify magic my-medium.cnf mysql.server my-huge.cnf my-small.cnf policy my-innodb-heavy-4G.cnf mysqld_multi.server wsrep.cnf [root@xuexi-001 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf [root@xuexi-001 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb [root@xuexi-001 mariadb]# vi /etc/init.d/mariadb basedir=/usr/local/mariadb datadir=/data/mariadb conf=/usr/local/mariadb/my.cnf ······ //须要修改的配置内容 $bindir/mysqld_safe --defarults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" & ······ //须要修改的配置内容 [root@xuexi-001 mariadb]# service mariadb start Reloading systemd: [ 肯定 ] Starting mariadb (via systemctl): [ 肯定 ] [root@xuexi-001 mariadb]# ps aux |grep mariadb root 2099 0.0 0.0 115388 1752 ? S 21:47 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/xuexi-001.pid mysql 2215 3.8 3.0 1125124 56608 ? Sl 21:47 0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/xuexi-001.err --pid-file=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sock --port=3306 root 2257 0.0 0.0 112676 984 pts/0 R+ 21:48 0:00 grep --color=auto mariadb [root@xuexi-001 mariadb]# netstat -ltnp 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 919/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1264/master tcp6 0 0 :::22 :::* LISTEN 919/sshd tcp6 0 0 ::1:25 :::* LISTEN 1264/master tcp6 0 0 :::3306 :::* LISTEN 2215/mysqld
出现的问题:apache
[root@xuexi-001 mariadb]# ps aux |grep mariadb root 2099 0.0 0.0 115388 1752 ? S 21:47 0:00 /bin/sh /usry.cnf --datadir=/data/mysql --pid-file=/data/mysql/xuexi-001.pid mysql 2215 0.2 3.4 1125124 64252 ? Sl 21:47 0:00 /usr/local/mir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/liile=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sock --port=3306 root 2311 0.0 0.0 112676 984 pts/0 R+ 21:54 0:00 grep --color
在以上操做过程当中指定了datadir=/data/mariadb 这里显示的是--datadir=/data/mysqljson
解决这个问提须要在Mariadb 配置文件中增长 datadir=/data/mariadb 由于同时启用了MySQL和mariadb 系统会从/etc/my.cnf中寻找
[root@xuexi-001 mariadb]# vi /usr/local/mariadb/my.cnf [mysqld] datadir = /data/mariadb ······//增长这一行
[root@xuexi-001 mariadb]# killall mysqld ······//先关掉mysql 服务 [root@xuexi-001 mariadb]# service mariadb start Starting mariadb (via systemctl): [ 肯定 ] [root@xuexi-001 mariadb]# ps aux | grep mariadb root 2757 0.0 0.0 115388 1748 ? S 22:11 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/xuexi-001.pid mysql 2876 1.3 3.1 1125024 59228 ? Sl 22:11 0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/xuexi-001.err --pid-file=/data/mariadb/xuexi-001.pid --socket=/tmp/mysql.sock --port=3306 root 2912 0.0 0.0 112676 984 pts/0 R+ 22:11 0:00 grep --color=auto mariadb
./configure --prefix=/usr/local/apr
make && make install
./configure
--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
./configure
--prefix=/usr/local/apache2.4
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util
--enable-so
--enable-mods-shared=most
make && make install
[root@xuexi-001 ~]# cd /usr/local/src/ [root@xuexi-001 src]# ls apr-1.6.3.tar.gz httpd-2.4.33.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.5.4.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# tar -zxvf apr-1.6.3.tar.gz [root@xuexi-001 src]# tar -zxvf apr-util-1.5.4.tar.gz [root@xuexi-001 src]# tar -zxvf httpd-2.4.33.tar.gz [root@xuexi-001 src]# ls apr-1.6.3 httpd-2.4.33 apr-1.6.3.tar.gz httpd-2.4.33.tar.gz apr-util-1.5.4 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.5.4.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# cd apr-1.6.3 [root@xuexi-001 apr-1.6.3]# ls apr-config.in build-outputs.mk helpers misc strings apr.dep CHANGES include mmap support apr.dsp CMakeLists.txt libapr.dep network_io tables apr.dsw config.layout libapr.dsp NOTICE test apr.mak configure libapr.mak NWGNUmakefile threadproc apr.pc.in configure.in libapr.rc passwd time apr.spec docs LICENSE poll tools atomic dso locks random user build emacs-mode Makefile.in README buildconf encoding Makefile.win README.cmake build.conf file_io memory shmem [root@xuexi-001 apr-1.6.3]# ./configure --prefix=/usr/local/apr [root@xuexi-001 apr-1.6.3]# echo $? 0 [root@xuexi-001 apr-1.6.3]# make && make install [root@xuexi-001 apr-1.6.3]# echo $? 0
[root@xuexi-001 src]# cd apr-util-1.5.4 [root@xuexi-001 apr-util-1.5.4]# ls aprutil.dep CHANGES include NWGNUmakefile aprutil.dsp CMakeLists.txt ldap README aprutil.dsw config.layout libaprutil.dep README.cmake aprutil.mak configure libaprutil.dsp renames_pending apr-util.pc.in configure.in libaprutil.mak strmatch apr-util.spec crypto libaprutil.rc test apu-config.in dbd LICENSE uri buckets dbm Makefile.in xlate build docs Makefile.win xml buildconf encoding memcache build.conf export_vars.sh.in misc build-outputs.mk hooks NOTICE [root@xuexi-001 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ [root@xuexi-001 apr-util-1.5.4]# echo $? 0 [root@xuexi-001 apr-util-1.6.1]# make && make install xml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录 #include <expat.h> yum -y install libtool libtool-ltdl-devel.x86_64 expat-devel pcre.x86_64 pcre-devel.x86_64 gcc
[root@xuexi-001 ~]# cd /usr/local/src/ [root@xuexi-001 src]# ls apr-1.6.3 httpd-2.4.33 apr-1.6.3.tar.gz httpd-2.4.33.tar.gz apr-util-1.5.4 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.5.4.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 src]# cd httpd-2.4.33 [root@xuexi-001 httpd-2.4.33]# ls ABOUT_APACHE CMakeLists.txt INSTALL NWGNUmakefile acinclude.m4 config.layout InstallBin.dsp os Apache-apr2.dsw configure LAYOUT README Apache.dsw configure.in libhttpd.dep README.cmake apache_probes.d docs libhttpd.dsp README.platforms ap.d emacs-style libhttpd.mak ROADMAP build httpd.dep LICENSE server BuildAll.dsp httpd.dsp Makefile.in srclib BuildBin.dsp httpd.mak Makefile.win support buildconf httpd.spec modules test CHANGES include NOTICE VERSIONING [root@xuexi-001 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most [root@xuexi-001 httpd-2.4.33]# make [root@xuexi-001 httpd-2.4.33]# make install
[root@xuexi-001 httpd-2.4.33]# cd /usr/local/apache2/······//切换到apache2目录下 [root@xuexi-001 apache2]# ls bin build cgi-bin conf error htdocs icons include logs man manual modules ······// 注:较经常使用目录bin(可执行文件存放目录)、conf(配置文件所在目录)、htdocs(存放一个访问页)、logs(日志文件存放目录)、modules(存放扩展模块)。 查看Apache所加载的模块: root@xuexi-001 apache2]# /usr/local/apache2/bin/apachectl -M 或者使用 [root@xuexi-001 apache2]# /usr/local/apache2/bin/httpd -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9625:3e1d:12c7:4fe6. Set the 'ServerName' directive globally to suppress this message Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) ······//AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::65d2:adc:20d3:8c74. Set the 'ServerName' directive globally to suppress this message #此处错误提示没影响。 启动: [root@xuexi-001 apache2]# /usr/local/apache2/bin/apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9625:3e1d:12c7:4fe6. Set the 'ServerName' directive globally to suppress this message 检测状态: [root@xuexi-001 apache2]# ps aux | grep httpd root 53115 0.0 0.1 95580 2528 ? Ss 23:21 0:00 /usr/local/apache2/bin/httpd -k start daemon 53116 0.4 0.2 382408 4432 ? Sl 23:21 0:00 /usr/local/apache2/bin/httpd -k start daemon 53117 0.0 0.2 382408 4432 ? Sl 23:21 0:00 /usr/local/apache2/bin/httpd -k start daemon 53118 0.2 0.2 382408 4432 ? Sl 23:21 0:00 /usr/local/apache2/bin/httpd -k start root 53201 0.0 0.0 112720 972 pts/0 R+ 23:22 0:00 grep --color=auto httpd [root@xuexi-001 apache2]# netstat -lntp 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 922/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1275/master tcp6 0 0 :::80 :::* LISTEN 53115/httpd tcp6 0 0 :::22 :::* LISTEN 922/sshd tcp6 0 0 ::1:25 :::* LISTEN 1275/master
[root@xuexi-001 apr-1.6.3]# ./configure --prefix=/usr/local/apr checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu Configuring APR library Platform: x86_64-pc-linux-gnu checking for working mkdir -p... yes APR Version: 1.6.3 checking for chosen layout... apr checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/usr/local/src/apr-1.6.3': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details ······// 没有安装gcc语言编译器须要安装gcc [root@xuexi-001 apr-1.6.3]# yum install -y gcc
collect2: error: ld returned 1 exit status make[2]: *** [htpasswd] 错误 1 make[2]: 离开目录“/usr/local/src/httpd-2.4.33/support” make[1]: *** [all-recursive] 错误 1 make[1]: 离开目录“/usr/local/src/httpd-2.4.33/support” make: *** [all-recursive] 错误 1 [root@xuexi-001 httpd-2.4.33]# yum install -y libxml2-devel 说明:缺乏了xml相关的库,须要安装libxml2-devel包。直接安装并不能解决问题,由于httpd调用的apr-util已经安装好了,可是apr-util并无libxml2-devel包支持 [root@xuexi-001 ~]# rm -rf /usr/local/apr-util/ [root@xuexi-001 ~]# cd /usr/local/src/apr-util-1.6.1 [root@xuexi-001 apr-util-1.6.1]# make clean ······// 安装完libxml2-devel 包以后,须要删除apr-util 文件以及清除缓存,并从新安装apr-util [root@xuexi-001 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@xuexi-001 apr-util-1.6.1]# make && make install ······//还须要从新编译httpd 也是须要先清除缓存,方法同上 [root@xuexi-001 src]# cd httpd-2.4.33 [root@xuexi-001 httpd-2.4.33]# make clean [root@xuexi-001 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most [root@xuexi-001 httpd-2.4.33]# make [root@xuexi-001 httpd-2.4.33]# make install
[root@xuexi-001 ~]# cd /usr/local/src/ [root@xuexi-001 src]# ls apr-1.6.3 apr-util-1.6.1.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-1.6.3.tar.gz httpd-2.4.33 mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz apr-util-1.6.1 httpd-2.4.33.tar.gz php-5.6.36.tar.bz2 [root@xuexi-001 src]# tar -zxvf php-5.6.36.tar.gz [root@xuexi-001 src]# ls apr-1.6.3 httpd-2.4.33 php-5.6.36 apr-1.6.3.tar.gz httpd-2.4.33.tar.gz php-5.6.36.tar.gz apr-util-1.6.1 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.6.1.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 php-5.6.36]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif [root@xuexi-001 php-5.6.36]# make && make install [root@xuexi-001 php-5.6.36]# ls -l /usr/local/apache2/modules/libphp5.so -rwxr-xr-x 1 root root 37744104 6月 25 01:01 /usr/local/apache2/modules/libphp5.so ······//PHP模块文件 [root@xuexi-001 php-5.6.36]# vi /usr/local/apache2/conf/httpd.conf ······//apache 的配置文件 [root@xuexi-001 php-5.6.36]# cp php.ini-production /usr/local/php/etc/php.ini
报错:configure: error: Cannot find OpenSSL's <evp.h>
解决: [root@xuexi-001 php-5.6.36]# yum install -y openssl-devel.x86_64
报错: configure: error: Please reinstall the BZip2 distribution
解决: [root@xuexi-001 php-5.6.36]# yum install -y bzip2-devel
报错: checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> configure: error: jpeglib.h not found.
解决: [root@xuexi-001 php-5.6.36]# yum install -y libjpeg-devel
报错: checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes configure: error: png.h not found.
解决: [root@xuexi-001 php-5.6.36]# yum install -y libpng-devel
报错: checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes If configure fails try --with-xpm-dir=<DIR> configure: error: freetype-config not found.
解决: [root@xuexi-001 php-5.6.36]# yum install -y freetype-devel
报错: configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决: [root@xuexi-001 php-5.6.36]# yum install -y epel-release [root@xuexi-001 php-5.6.36]# yum install -y libmcrypt-devel
[root@xuexi-001 ~]# cd /usr/local/src/ [root@xuexi-001 src]# ls apr-1.6.3 httpd-2.4.33 php-5.6.36 apr-1.6.3.tar.gz httpd-2.4.33.tar.gz php-5.6.36.tar.gz apr-util-1.6.1 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.6.1.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz php-7.1.6.tar.bz2 [root@xuexi-001 src]# tar -jxvf php-7.1.6.tar.bz2 [root@xuexi-001 src]# ls apr-1.6.3 httpd-2.4.33 php-5.6.36 apr-1.6.3.tar.gz httpd-2.4.33.tar.gz php-5.6.36.tar.gz apr-util-1.6.1 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz php-7.1.6 apr-util-1.6.1.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz php-7.1.6.tar.bz2 [root@xuexi-001 src]# cd php-7.1.6 [root@xuexi-001 php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif [root@xuexi-001 php-7.1.6]# make && make install [root@xuexi-001 php-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini 查看加载的模块: [root@xuexi-001 php-7.1.6]# /usr/local/php7/bin/php -m [PHP Modules] bz2 Core ctype date dom exif fileinfo filter gd hash iconv json libxml mbstring mcrypt mysqli openssl pcre PDO pdo_mysql pdo_sqlite Phar posix Reflection session SimpleXML soap sockets SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib [Zend Modules]
[root@xuexi-001 php-7.1.6]# vi /usr/local/apache2/conf/httpd.conf ······//若是不想用哪一个就在配置文件前面加# 注释掉 LoadModule php5_module modules/libphp5.so LoadModule php7_module modules/libphp7.so
<?php
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl restart AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9625:3e1d:12c7:4fe6. Set the 'ServerName' directive globally to suppress this message
[root@xuexi-001 ~]# vim /usr/local/apache2/conf/httpd.conf #ServerName www.example.com:80 此处的# 删除改成 ServerName www.example.com:80 [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl restart httpd not running, trying to start /usr/local/apache2/bin/apachectl: 行 79: 1563 段错误 $HTTPD -k $ARGV 提示错误信息,此时须要将安装好的PHP5和PHP7中两个中的一个关掉,不能同时开启两个PHP. [root@xuexi-001 ~]# vim /usr/local/apache2/conf/httpd.conf LoadModule php5_module modules/libphp5.so #LoadModule php7_module modules/libphp7.so [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl start httpd (pid 1591) already running [root@xuexi-001 ~]# ps aux |grep httpd root 1591 0.0 0.4 255720 8868 ? Ss 16:09 0:00 /usr/local/apache2/bin/httpd -k restart daemon 1592 0.0 0.4 542548 8980 ? Sl 16:09 0:00 /usr/local/apache2/bin/httpd -k restart daemon 1593 0.0 0.4 542548 8980 ? Sl 16:09 0:00 /usr/local/apache2/bin/httpd -k restart daemon 1594 0.0 0.4 542548 8980 ? Sl 16:09 0:00 /usr/local/apache2/bin/httpd -k restart root 1685 0.0 0.0 112720 968 pts/0 R+ 16:10 0:00 grep --color=auto httpd
1.首先访问网站,直接输入IP ---> 显示没法访问,先检查网络是否通。
C:\Users\Administrator>ping 192.168.5.130 正在 Ping 192.168.5.130 具备 32 字节的数据: 来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64 192.168.5.130 的 Ping 统计信息: 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms
2.检查80端口是否通,首先打开windows上telnet服务
测试80端口是否通,80端口不通
3.在linux 虚拟机上设定一条规则 临时添加80端口
[root@xuexi-001 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
4.在windows 上测试80端口。显示这种It works!表明80端口已经通了
5.打开网页测试。网页测试成功
防止在打开虚拟主机配置文件的时候显示403
[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.conf Require all denied······// 将此处 denied 修改成 granted [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK······//检查配置文件语法是否正确 [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful·······//`从新加载配置文件,并不会重启。
增长一行 与php相关的配置
AddType application/x-httpd-php .php
[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.conf AddType application/x-compress .Z AddType application/x-gzip .gz .tgz······//在配置文件中找到这两行,在这两行后面加入下面这一行有关PHP的,帮助PHP解析。 AddType application/x-httpd-php .php
添加内容(索引页)
在配置文件内容找到DirectoryIndex index.html ,这后面加入 index.php ,改成 DirectoryIndex index.html index.php
[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.conf <IfModule dir_module> DirectoryIndex index.html index.php [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t Syntax OK [root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful ······// 检查配置文件,并从新加载配置文件
先写一个PHP的脚本
[root@xuexi-001 ~]# vi /usr/local/apache2/htdocs/1.php <?php phpinfo(); ?> ~
访问 : 192.168.5.130/1.php
若是PHP 没有被解析,须要从如下几点排查问题
1.查看PHP模块有没有加载
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) php5_module (shared)
若是没有加载,能够查看有没有模块文件,若是有文件并无显示,就要查看配置文件中有没有libphp5.so
[root@xuexi-001 ~]# ls /usr/local/apache2/modules/libphp5.so /usr/local/apache2/modules/libphp5.so [root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.conf LoadModule php5_module modules/libphp5.so
2.查看配置文件中有没有添加 “AddType application/x-httpd-php .php” .php前面有空格
3.在配置文件内容找到DirectoryIndex index.html ,这后面加入 index.php ,改成 DirectoryIndex index.html index.php