LAMP架构
MySQL/Mariadb介绍
1、MySQL安装
[root@aminglinux ~]# cd /usr/local/src
[root@aminglinux src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz --2018-06-23 10:06:13-- http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 正在解析主机 mirrors.sohu.com (mirrors.sohu.com)... 221.236.12.140 正在连接 mirrors.sohu.com (mirrors.sohu.com)|221.236.12.140|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:314581668 (300M) [application/octet-stream] 正在保存至: “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” 100%[==============================================>] 314,581,668 23.2KB/s 用时 95m 35s 2018-06-23 11:41:53 (53.6 KB/s) - 已保存 “mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz” [314581668/314581668])
[root@aminglinux src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz mysql-5.6.35-linux-glibc2.5-x86_64/README mysql-5.6.35-linux-glibc2.5-x86_64/data/test/db.opt mysql-5.6.35-linux-glibc2.5-x86_64/lib/libmysqlclient.a mysql-5.6.35-linux-glibc2.5-x86_64/lib/libmysqlclient.so.18 mysql-5.6.35-linux-glibc2.5-x86_64/lib/libmysqlclient.so
[root@aminglinux src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
[root@aminglinux src]# cd /usr/local/mysql [root@aminglinux mysql]# ls bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench
[root@aminglinux mysql]# useradd mysql
[root@aminglinux mysql]# mkdir /data/
[root@aminglinux 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
8.1.安装Dumper包:yum list |grep perl |grep -i dumper
[root@aminglinux mysql]# yum list |grep perl |grep -i dumper 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 [root@aminglinux mysql]# yum install -y perl-Data-Dumper.x86_64 实际上是安装perl-Data-Dumper.x86_64包 已加载插件:fastestmirror
重新初始化
[root@aminglinux mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql Installing MySQL system tables...2018-06-23 13:16:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). .... [root@aminglinux mysql]# echo $?检测是否安装成功 0
9.cp support-files/my-default.cnf /etc/my.cnf //拷贝配置文件到/etc/并改名my.cnf
[root@aminglinux mysql]# ls support-files/ binary-configure my-default.cnf mysql-log-rotate magic mysqld_multi.server mysql.server [root@aminglinux mysql]# ls support-files/my-default.cnf 查看配置文件 support-files/my-default.cnf [root@aminglinux mysql]# cp support-files/my-default.cnf /etc/my.cnf 拷贝配置文件到/etc/并改名my.cnf,确认覆盖 cp:是否覆盖"/etc/my.cnf"? y
10.cp support-files/mysql.server /etc/init.d/mysqld //拷贝启动脚本到启动目录
[root@aminglinux mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@aminglinux mysql]# vi /etc/init.d/mysqld
basedir=/usr/local/mysql datadir=/data/mysql
11.权限变更:chmod 755 /etc/init.d/mysqld
[root@aminglinux mysql]# chmod 755 /etc/init.d/mysqld^C [root@aminglinux mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10903 6月 23 13:40 /etc/init.d/mysqld [root@aminglinux mysql]# chkconfig --add mysqld [root@aminglinux 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@aminglinux mysql]# service mysqld start 启动服务 Starting MySQL.Logging to '/data/mysql/aminglinux.err'. .............................................. SUCCESS! [root@aminglinux mysql]# ps aux |grep mysql 查看进程 root 1716 0.0 0.1 11772 1568 pts/0 S 13:49 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/aminglinux.pid mysql 1824 61.5 44.5 973052 449492 pts/0 Sl 13:49 0:49 /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/aminglinux.err --pid-file=/data/mysql/aminglinux.pid root 1947 0.0 0.0 112676 984 pts/0 S+ 13:50 0:00 grep --color=auto mysq [root@aminglinux mysql]# [root@aminglinux 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 1033/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1117/master tcp6 0 0 :::22 :::* LISTEN 1033/sshd tcp6 0 0 ::1:25 :::* LISTEN 1117/master tcp6 0 0 :::3306 :::* LISTEN 1824/mysqld
kill和killall区别
mysql常用的两种引擎
2.安装mariadb
1.cd /usr/local/src //切换到下载源码包的目录
[root@aminglinux ~]# cd /usr/local/src
2.wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@aminglinux src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz --2018-06-23 16:54:04-- https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz 正在解析主机 downloads.mariadb.com (downloads.mariadb.com)... 51.255.94.155, 2001:41d0:1004:249b:: 正在连接 downloads.mariadb.com (downloads.mariadb.com)|51.255.94.155|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:541295045 (516M) [application/octet-stream] 正在保存至: “mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz”
3.tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
[root@aminglinux src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
4.mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb 解压的包移动到/usr/local下,并改名叫mariadb——>这里的改名,是为了之前安装mysql的名字有所区分
[root@aminglinux src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
5.cd /usr/local/mariadb 进入cd /usr/local/mariadb目录
[root@aminglinux ~]# cd /usr/local/mariadb [root@aminglinux mariadb]#
6.创建mysql用户,创建data——>这里因为之前安装mysql的时候,已经创建过了所以不需要创建useradd mysql 7../scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb 初始化并定义路径basedir=/usr/local/mariadb
[root@aminglinux mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb Installing MariaDB/MySQL system tables in '/data/mariadb' ... OK ...... [root@aminglinux mariadb]# echo $? 检测命令 0
8.cp support-files/my-small.cnf /usr/local/mariadb/my.cnf 拷贝配置文件
[root@aminglinux mariadb]# cd /usr/local/mariadb/ [root@aminglinux 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@aminglinux mariadb]# vim support-files/my-small.cnf # The MySQL server [mysqld] port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16K max_allowed_packet = 1M table_open_cache = 4 sort_buffer_size = 64K read_buffer_size = 256K read_rnd_buffer_size = 256K net_buffer_length = 2K thread_stack = 240K
[root@aminglinux mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf [root@aminglinux mariadb]#
9.编辑配置文件vim /usr/local/mariadb/my.cnf //定义basedir和datadir (这里面配置不用修改)
[root@aminglinux mariadb]# vim /usr/local/mariadb/my.cnf
10.拷贝启动脚本到/etc/init.d/mariadb并编辑:
[root@aminglinux mariadb]# cp support-files/mysql.server /etc/init.d/mariadb [root@aminglinux mariadb]# vim /etc/init.d/mariadb # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mariadb 定义basedir datadir=/data/mariadb 定义datadir conf=$basedir/my.cnf 自定义参数(配置文件在/etc下不用定义这个参数)
配置启动命令:在一般模式下,搜索 /start 启动命令
在 $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &中,增加--defaults-file="$conf"; 最后为 $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
11.在启动前,先查看是否有mysql服务在启动;因前面安装有MySQL,并启了服务;所以要关掉
[root@aminglinux mariadb]# ps aux |grep mysql root 1039 0.0 0.0 115388 596 ? S 16:44 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/aminglinux.pid mysql 1166 0.2 44.8 973052 452588 ? Sl 16:44 0:48 /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/aminglinux.err --pid-file=/data/mysql/aminglinux.pid root 1820 0.0 0.0 112680 980 pts/0 S+ 23:18 0:00 grep --color=auto mysq
机器装了mysql和mariadb处理
[root@aminglinux mariadb]# vim /usr/local/mariadb/my.cnf # The MySQL server [mysqld] datadir= /data/mariadb port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16K max_allowed_packet = 1M
[root@aminglinux mariadb]# /etc/init.d/mariadb start 启动服务查看进程状态 Reloading systemd: [ 确定 ] Starting mariadb (via systemctl): [ 确定 ] [root@aminglinux mariadb]# ps aux |grep mysql root 1039 0.0 0.0 115388 596 ? S 16:44 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/aminglinux.pid mysql 1166 0.2 44.9 1038848 453240 ? Sl 16:44 0:54 /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/aminglinux.err --pid-file=/data/mysql/aminglinux.pid root 2080 0.0 0.0 112680 976 pts/0 S+ 23:48 0:00 grep --color=auto mysq [root@aminglinux mariadb]# /etc/init.d/mariadb restart 重启服务再查看进程状态 Restarting mariadb (via systemctl): [ 确定 ] [root@aminglinux mariadb]# ps aux |grep mysql root 1039 0.0 0.0 115388 596 ? S 16:44 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/aminglinux.pid mysql 1166 0.2 44.9 1038848 453240 ? Sl 16:44 0:54 /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/aminglinux.err --pid-file=/data/mysql/aminglinux.pid root 2268 0.0 0.0 112676 980 pts/0 R+ 23:48 0:00 grep --color=auto mysq [root@aminglinux mariadb]# /etc/init.d/mariadb stop 进程状态不正常,停止服务 Stopping mariadb (via systemctl): [ 确定 ] [root@aminglinux mariadb]# killall mysqld 杀掉进程 [root@aminglinux mariadb]# ps aux |grep mysql root 2314 0.0 0.0 112676 976 pts/0 S+ 23:51 0:00 grep --color=auto mysq [root@aminglinux mariadb]# /etc/init.d/mariadb start 再次启动服务查看进程状态 Starting mariadb (via systemctl): [ 确定 ] [root@aminglinux mariadb]# ps aux |grep mysql root 2337 0.2 0.1 115388 1736 ? S 23:52 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/aminglinux.pid mysql 2456 6.5 5.5 1583776 55840 ? Sl 23:52 0:01 /usr/local/mariadb/binmysqld --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/aminglinux.err --pid-file=/data/mariadb/aminglinux.pid --socket=/tmp/mysql.sock --port=3306 root 2495 0.0 0.0 112676 976 pts/0 S+ 23:52 0:00 grep --color=auto mysq [root@aminglinux mariadb]#
3、安装Apache
2.2版本和2.4版本的区别
1、首先进入到/usr/local/src目录
[root@aminglinux mariadb]# cd /usr/local/src
2、下载下载Apache 2.4源码包、apr、apr-util这三个包
[root@aminglinux src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.25.tar.gz [root@aminglinux src]# wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz [root@aminglinux src]# wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.bz2
apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
3、解压并查看
[root@hf src]# tar zxvf httpd-2.4.29.tar.gz [root@hf src]# tar zxvf apr-1.6.3.tar.gz [root@hf src]# tar xjvf apr-util-1.6.1.tar.bz2 [root@aminglinux src]# ls apr-1.6.3 apr-util-1.6.1.tar.bz2 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-1.6.3.tar.gz httpd-2.4.29 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz apr-util-1.6.1 httpd-2.4.29.tar.gz
4、到/usr/local/src/apr-1.6.3,并安装apr
[root@aminglinux src]# cd /usr/local/src/apr-1.6.3 [root@aminglinux 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
安装gcc包:yum install -y gcc
[root@aminglinux apr-1.6.3]#yum install -y gcc [root@aminglinux apr-1.6.3]# ./configure --prefix=/usr/local/apr
5、用 echo $? 检查是否安装成功后执行make && make install 命令
[root@aminglinux apr-1.6.3]# echo $? 0 [root@aminglinux apr-1.6.3]# make && make install
6、安装apr-util-1.6.1;进入到/usr/local/src/apr-util-1.6.1目录并安装apr-util
[root@aminglinux apr-1.6.3]# cd /usr/local/src/apr-util-1.6.1 进入目录 [root@aminglinux apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 安装apr-util
7、用 echo $? 检查是否安装成功后执行make && make install 命令
[root@aminglinux apr-util-1.6.1]# echo $? 0 [root@aminglinux apr-util-1.6.1]# make && make install
在执行make && make install,出现(make[1]: *** [xml/apr_xml.lo] 错误 1);是因为缺少了xml解释器,只需要yum安装 expat-devel 包(yum -y install expat-devel)再去执行make && make install 会正常执行
8.安装httpd-2.4.29,首先进入到httpd-2.4.29/;安装httpd-2.4.29
[root@aminglinux apr-util-1.6.1]# cd /usr/local/src/httpd-2.4.29/ 进入目录 [root@aminglinux httpd-2.4.29]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 安装httpd-2.4.29
9、用 echo $? 检查是否安装成功后执行make && make install 命令
[root@aminglinux httpd-2.4.29]# echo $? 0 [root@aminglinux httpd-2.4.29]# make && make install
10、Apache目录
安装完成后,进入到/usr/local/apache2.4/目录下查看目录
[root@aminglinux apache2.4]# ls bin build cgi-bin conf error htdocs icons include logs man manual modules [root@aminglinux apache2.4]# ls bin/httpd bin/httpd [root@aminglinux apache2.4]# ls -l bin/httpd -rwxr-xr-x 1 root root 2334336 6月 24 01:29 bin/httpd [root@aminglinux apache2.4]# du -sh bin/httpd 2.3M bin/httpd [root@aminglinux apache2.4]# ls conf/ extra httpd.conf magic mime.types original [root@aminglinux apache2.4]# ls htdocs/ index.html [root@aminglinux apache2.4]# ls modules httpd.exp mod_dbd.so mod_proxy_http.so mod_access_compat.so mod_dir.so mod_proxy_scgi.so mod_actions.so mod_dumpio.so mod_proxy.so mod_alias.so mod_env.so mod_proxy_wstunnel.so mod_allowmethods.so mod_expires.so mod_ratelimit.so mod_auth_basic.so mod_ext_filter.so mod_remoteip.so mod_auth_digest.so mod_file_cache.so mod_reqtimeout.so mod_auth_form.so mod_filter.so mod_request.so mod_authn_anon.so mod_headers.so mod_rewrite.so mod_authn_core.so mod_include.so mod_sed.so mod_authn_dbd.so mod_info.so mod_session_cookie.so mod_authn_dbm.so mod_lbmethod_bybusyness.so mod_session_dbd.so mod_authn_file.so mod_lbmethod_byrequests.so mod_session.so mod_authn_socache.so mod_lbmethod_bytraffic.so mod_setenvif.so mod_authz_core.so mod_lbmethod_heartbeat.so mod_slotmem_shm.so mod_authz_dbd.so mod_log_config.so mod_socache_dbm.so mod_authz_dbm.so mod_log_debug.so mod_socache_memcache.so mod_authz_groupfile.so mod_logio.so mod_socache_shmcb.so mod_authz_host.so mod_macro.so mod_speling.so mod_authz_owner.so mod_mime.so mod_status.so mod_authz_user.so mod_negotiation.so mod_substitute.so mod_autoindex.so mod_proxy_ajp.so mod_unique_id.so mod_buffer.so mod_proxy_balancer.so mod_unixd.so mod_cache_disk.so mod_proxy_connect.so mod_userdir.so mod_cache.so mod_proxy_express.so mod_version.so mod_cache_socache.so mod_proxy_fcgi.so mod_vhost_alias.so mod_cgid.so mod_proxy_fdpass.so mod_watchdog.so mod_dav_fs.so mod_proxy_ftp.so mod_dav.so mod_proxy_hcheck.so
[root@aminglinux apache2.4]# /usr/local/apache2.4/bin/httpd -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::effe:fc70:7a68:994c. 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)
[root@aminglinux apache2.4]# ls /usr/local/apache2.4/modules httpd.exp mod_dbd.so mod_proxy_http.so mod_access_compat.so mod_dir.so mod_proxy_scgi.so mod_actions.so mod_dumpio.so mod_proxy.so mod_alias.so mod_env.so mod_proxy_wstunnel.so mod_allowmethods.so mod_expires.so mod_ratelimit.so mod_auth_basic.so mod_ext_filter.so mod_remoteip.so mod_auth_digest.so mod_file_cache.so mod_reqtimeout.so mod_auth_form.so mod_filter.so mod_request.so mod_authn_anon.so mod_headers.so mod_rewrite.so mod_authn_core.so mod_include.so mod_sed.so mod_authn_dbd.so mod_info.so mod_session_cookie.so mod_authn_dbm.so mod_lbmethod_bybusyness.so mod_session_dbd.so mod_authn_file.so mod_lbmethod_byrequests.so mod_session.so mod_authn_socache.so mod_lbmethod_bytraffic.so mod_setenvif.so mod_authz_core.so mod_lbmethod_heartbeat.so mod_slotmem_shm.so mod_authz_dbd.so mod_log_config.so mod_socache_dbm.so mod_authz_dbm.so mod_log_debug.so mod_socache_memcache.so mod_authz_groupfile.so mod_logio.so mod_socache_shmcb.so mod_authz_host.so mod_macro.so mod_speling.so mod_authz_owner.so mod_mime.so mod_status.so mod_authz_user.so mod_negotiation.so mod_substitute.so mod_autoindex.so mod_proxy_ajp.so mod_unique_id.so mod_buffer.so mod_proxy_balancer.so mod_unixd.so mod_cache_disk.so mod_proxy_connect.so mod_userdir.so mod_cache.so mod_proxy_express.so mod_version.so mod_cache_socache.so mod_proxy_fcgi.so mod_vhost_alias.so mod_cgid.so mod_proxy_fdpass.so mod_watchdog.so mod_dav_fs.so mod_proxy_ftp.so mod_dav.so mod_proxy_hcheck.so
11、启动Apache2.4:/usr/local/apache2.4/bin/apachectl start
[root@aminglinux apache2.4]# /usr/local/apache2.4/bin/apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::effe:fc70:7a68:994c. Set the 'ServerName' directive globally to suppress this message
[root@aminglinux apache2.4]# ps aux |grep httpd root 1379 0.0 0.2 95572 2532 ? Ss 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 1380 0.0 0.4 382400 4440 ? Sl 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 1381 0.1 0.4 382400 4444 ? Sl 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 1384 0.1 0.4 382400 4436 ? Sl 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start root 1466 0.0 0.0 112720 984 pts/0 S+ 19:15 0:00 grep --color=auto http [root@aminglinux apache2.4]# 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 1028/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1226/master tcp6 0 0 :::80 :::* LISTEN 1379/httpd tcp6 0 0 :::22 :::* LISTEN 1028/sshd tcp6 0 0 ::1:25 :::* LISTEN 1226/master tcp6 0 0 :::3306 :::* LISTEN 1165/mysqld [root@aminglinux apache2.4]#
httpd默认监听端口为80,mysqld默认监听端口为3306,25端口是发邮件的,22端口是远程登录的
安装PHP5
[root@aminglinux apache2.4]# cd /usr/local/src 进入目录 [root@aminglinux src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 下载包 --2018-06-24 19:22:13-- http://cn2.php.net/distributions/php-5.6.30.tar.gz 正在解析主机 cn2.php.net (cn2.php.net)... 36.51.255.144 正在连接 cn2.php.net (cn2.php.net)|36.51.255.144|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:19274631 (18M) [application/x-gzip] 正在保存至: “php-5.6.30.tar.gz” 6% [==> ] 1,290,364 5.55KB/s 用时 3m 28s 2018-06-24 19:25:47 (6.06 KB/s) - 在 1290364 字节处连接关闭。重试中。 --2018-06-24 19:25:48-- (尝试次数: 2) http://cn2.php.net/distributions/php-5.6.30.tar.gz 正在连接 cn2.php.net (cn2.php.net)|36.51.255.144|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 206 Partial Content 长度:19274631 (18M),剩余 17984267 (17M) [application/x-gzip] 正在保存至: “php-5.6.30.tar.gz” 100%[+++===========================================>] 19,274,631 58.6KB/s 用时 7m 59s 2018-06-24 19:33:49 (36.7 KB/s) - 已保存 “php-5.6.30.tar.gz” [19274631/19274631]) [root@aminglinux src]# tar zxvf php-5.6.30.tar.gz 解压包 ...... [root@aminglinux src]# ls 查看解压包 apr-1.6.3 httpd-2.4.29 php-5.6.30 apr-1.6.3.tar.gz httpd-2.4.29.tar.gz php-5.6.30.tar.gz apr-util-1.6.1 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz apr-util-1.6.1.tar.bz2 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@aminglinux src]#cd php-5.6.30 [root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
编译过程中会出现很多问题,大都是一些插件没有安装;
configure: error: xml2-config not found. Please check your libxml2 installation. [root@aminglinux php-5.6.30]# yum list |grep xml2 libxml2.x86_64 2.9.1-6.el7_2.3 @anaconda libxml2.i686 2.9.1-6.el7_2.3 base libxml2-devel.i686 2.9.1-6.el7_2.3 base libxml2-devel.x86_64 2.9.1-6.el7_2.3 base libxml2-python.x86_64 2.9.1-6.el7_2.3 base libxml2-static.i686 2.9.1-6.el7_2.3 base libxml2-static.x86_64 2.9.1-6.el7_2.3 base mingw32-libxml2.noarch 2.9.3-1.el7 epel mingw32-libxml2-static.noarch 2.9.3-1.el7 epel mingw64-libxml2.noarch 2.9.3-1.el7 epel mingw64-libxml2-static.noarch 2.9.3-1.el7 epel python-xml2rfc.noarch 2.5.2-2.el7 epel tinyxml2.x86_64 2.1.0-2.20140406git6ee53e7.el7 tinyxml2-devel.x86_64 2.1.0-2.20140406git6ee53e7.el7 xml2.x86_64 0.5-7.el7 epel [root@aminglinux php-5.6.30]# yum install -y libxml2-devel
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
configure: error: Cannot find OpenSSL's
[root@aminglinux php-5.6.30]# yum install -y openssl-devel ......
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
configure: error: Please reinstall the BZip2 distribution [root@aminglinux php-5.6.30]# yum install -y bzip2-devel
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
configure: error: jpeglib.h not found. [root@aminglinux php-5.6.30]# yum install -y libjpeg-devel
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
configure: error: png.h not found. [root@aminglinux php-5.6.30]# yum install -y libpng-devel
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
configure: error: freetype-config not found. [root@aminglinux php-5.6.30]# yum install -y freetype-devel
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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
configure: error: mcrypt.h not found. Please reinstall libmcrypt. [root@aminglinux php-5.6.30]# yum install -y epel-release ...... [root@aminglinux php-5.6.30]# yum install -y libmcrypt-devel
继续编译:
[root@aminglinux php-5.6.30]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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 Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
[root@aminglinux php-5.6.30]# echo $? 0
查看PHP目录、文件
[root@aminglinux php-5.6.30]# ls /usr/local/php/ bin etc include lib php [root@aminglinux php-5.6.30]# ls /usr/local/php/bin/ pear peardev pecl phar phar.phar php php-cgi php-config phpize [root@aminglinux php-5.6.30]# du -sh /usr/local/php/bin/php 36M /usr/local/php/bin/php [root@aminglinux php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so 37M /usr/local/apache2.4/modules/libphp5.so
[root@aminglinux php-5.6.30]# /usr/local/php/bin/php -m [PHP Modules] bz2 Core ctype date dom ereg exif fileinfo filter gd hash iconv json libxml mbstring mcrypt mysql 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@aminglinux php-5.6.30]# /usr/local/apache2.4/bin/httpd -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::effe:fc70:7a68:994c. 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) php5_module (shared)
[root@aminglinux php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so -rwxr-xr-x 1 root root 37753504 6月 24 20:53 /usr/local/apache2.4/modules/libphp5.so
[root@aminglinux php-5.6.30]# vim /usr/local/apache2.4/conf/httpd.conf 去搜索php5.so,会发现自动增加了一行 LoadModule php5_module modules/libphp5.so 若想使用文件中的那一个模块,将前面的 # 号去除即可使用 若想不使用哪个模块,只需要加一个 # 号即可
安装完PHP之后,需要把配置文件拷贝到指定路径下
System => Linux aminglinux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 Build Date => Jun 24 2018 20:50:43 Configure Command => './configure' '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2.4/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' 参数 Server API => Command Line Interface Virtual Directory Support => enabled Configuration File (php.ini) Path => /usr/local/php/etc 路径 Loaded Configuration File => (none) Scan this dir for additional .ini files => (none) Additional .ini files parsed => (none) PHP API => 20131106 PHP Extension => 20131226 Zend Extension => 220131226 Zend Extension Build => API220131226,TS PHP Extension Build => API20131226,TS Debug Build => no Thread Safety => enabled Zend Signal Handling => disabled :
两个配置文件
[root@aminglinux php-5.6.30]# ls /usr/local/php/etc pear.conf [root@aminglinux php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
System => Linux aminglinux 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 Build Date => Jun 24 2018 20:50:43 Configure Command => './configure' '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2.4/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' Server API => Command Line Interface Virtual Directory Support => enabled Configuration File (php.ini) Path => /usr/local/php/etc Loaded Configuration File => /usr/local/php/etc/php.ini 配置文件路径 Scan this dir for additional .ini files => (none) Additional .ini files parsed => (none) PHP API => 20131106 PHP Extension => 20131226 Zend Extension => 220131226 Zend Extension Build => API220131226,TS PHP Extension Build => API20131226,TS Debug Build => no Thread Safety => enabled Zend Signal Handling => disabled :PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
安装PHP7
[root@aminglinux php-5.6.30]# cd /usr/local/src/ [root@aminglinux src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2 [root@aminglinux src]# tar jxf php-7.1.6.tar.bz2
初始化配置
[root@aminglinux src]#cd php-7.1.6 [root@aminglinux php-7.1.6]./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/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
初始化配置完成后,然后make && make install
[root@aminglinux php-7.1.6]make && make install [root@aminglinux php-7.1.6]# echo $? 0
查看PHP7的文件
[root@aminglinux php-7.1.6]# ls /usr/local/apache2.4/modules/ httpd.exp mod_dav_fs.so mod_proxy_ftp.so libphp5.so mod_dav.so mod_proxy_hcheck.so libphp7.so [root@aminglinux php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so /usr/local/apache2.4/modules/libphp7.so [root@aminglinux php-7.1.6]# du -sh /usr/local/apache2.4/modules/libphp7.so 37M /usr/local/apache2.4/modules/libphp7.so
[root@aminglinux 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@aminglinux php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::effe:fc70:7a68:994c. 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) php5_module (shared) php7_module (shared)
[root@aminglinux php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf 搜索php5.so,会看到有两行 LoadModule php5_module modules/libphp5.so LoadModule php7_module modules/libphp7.so 想使用哪个php,就在另一个前面加 # 号注释掉,然后保存
Apache和PHP结合
编辑httpd的配置文件
1、去除ServerName警告信息
[root@aminglinux php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf 在文件中搜索 /ServerName 然后将 # ServerName www.example.com:80 前的# 去除掉保存退出即可
在去除# 号之后,运行apache,会提示79行错误
[root@aminglinux php-7.1.6]# /usr/local/apache2.4/bin/apachectl restart httpd not running, trying to start /usr/local/apache2.4/bin/apachectl: 行 79: 2348 段错误 $HTTPD -k $ARGV LoadModule php5_module modules/libphp5.so #LoadModule php7_module modules/libphp7.so 注释掉PHP7
查看httpd进程
[root@aminglinux ~]# ps aux |grep httpd root 1379 0.0 0.1 95572 1440 ? Ss 19:11 0:01 /usr/local/apache2.4/bin/httpd -k start daemon 1380 0.0 0.3 382400 3548 ? Sl 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 1381 0.0 0.3 382400 3552 ? Sl 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 1384 0.0 0.3 382400 3544 ? Sl 19:11 0:00 /usr/local/apache2.4/bin/httpd -k start root 7985 0.0 0.0 112724 984 pts/0 S+ 23:16 0:00 grep --color=auto httpd
2、更改Require all denied
[root@aminglinux ~]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 21606 50M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 189 20978 INPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0 189 20978 INPUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0 189 20978 INPUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0 6 240 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID 182 20686 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED 0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 0 0 FORWARD_direct all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FORWARD_IN_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FORWARD_IN_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FORWARD_OUT_ZONES_SOURCE all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FORWARD_OUT_ZONES all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID 0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT 24587 packets, 4426K bytes) pkts bytes target prot opt in out source destination 24587 4426K OUTPUT_direct all -- * * 0.0.0.0/0 0.0.0.0/0 Chain FORWARD_IN_ZONES (1 references) pkts bytes target prot opt in out source destination 0 0 FWDI_work all -- ens33 * 0.0.0.0/0 0.0.0.0/0 [goto] 0 0 FWDI_work all -- + * 0.0.0.0/0 0.0.0.0/0 [goto] Chain FORWARD_IN_ZONES_SOURCE (1 references) pkts bytes target prot opt in out source destination Chain FORWARD_OUT_ZONES (1 references) pkts bytes target prot opt in out source destination 0 0 FWDO_work all -- * ens33 0.0.0.0/0 0.0.0.0/0 [goto] 0 0 FWDO_work all -- * + 0.0.0.0/0 0.0.0.0/0 [goto] Chain FORWARD_OUT_ZONES_SOURCE (1 references) pkts bytes target prot opt in out source destination Chain FORWARD_direct (1 references) pkts bytes target prot opt in out source destination Chain FWDI_work (2 references) pkts bytes target prot opt in out source destination 0 0 FWDI_work_log all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FWDI_work_deny all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FWDI_work_allow all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 Chain FWDI_work_allow (1 references) pkts bytes target prot opt in out source destination Chain FWDI_work_deny (1 references) pkts bytes target prot opt in out source destination Chain FWDI_work_log (1 references) pkts bytes target prot opt in out source destination Chain FWDO_work (2 references) pkts bytes target prot opt in out source destination 0 0 FWDO_work_log all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FWDO_work_deny all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 FWDO_work_allow all -- * * 0.0.0.0/0 0.0.0.0/0 Chain FWDO_work_allow (1 references) pkts bytes target prot opt in out source destination Chain FWDO_work_deny (1 references) pkts bytes target prot opt in out source destination Chain FWDO_work_log (1 references) pkts bytes target prot opt in out source destination Chain INPUT_ZONES (1 references) pkts bytes target prot opt in out source destination 189 20978 IN_work all -- ens33 * 0.0.0.0/0 0.0.0.0/0 [goto] 0 0 IN_work all -- + * 0.0.0.0/0 0.0.0.0/0 [goto] Chain INPUT_ZONES_SOURCE (1 references) pkts bytes target prot opt in out source destination Chain INPUT_direct (1 references) pkts bytes target prot opt in out source destination Chain IN_work (2 references) pkts bytes target prot opt in out source destination 189 20978 IN_work_log all -- * * 0.0.0.0/0 0.0.0.0/0 189 20978 IN_work_deny all -- * * 0.0.0.0/0 0.0.0.0/0 189 20978 IN_work_allow all -- * * 0.0.0.0/0 0.0.0.0/0 0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 Chain IN_work_allow (1 references) pkts bytes target prot opt in out source destination 1 52 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22 ctstate NEW 0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:21 ctstate NEW Chain IN_work_deny (1 references) pkts bytes target prot opt in out source destination Chain IN_work_log (1 references) pkts bytes target prot opt in out source destination Chain OUTPUT_direct (1 references) pkts bytes target prot opt in out source destination
[root@aminglinux ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
再去用浏览器访问自己虚拟机的IP,会发现可以访问。
[root@aminglinux ~]# !vim vim /usr/local/apache2.4/conf/httpd.conf 然后搜索 /denied ,会看到
AllowOverride none Require all denied 把 denied 改成 granted
在更改完配置文件,需要重新加载配置
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK
重新加载配置文件
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl graceful [root@aminglinux ~]#
在配置文件中的,两处位置都应该改成granted,这是为了防止你在打开虚拟主机配置文件的时候,显示403Forbidden(403是它的状态码,正常情况下,状态码都是200)
3、因为要支持php,所以要增加一行php相关的配置
[root@aminglinux ~]# vim /usr/local/apache2.4/conf/httpd.conf 搜索 /AddType,然后 AddType application/x-compress .Z AddType application/x-gzip .gz .tgz 在这两行下面,增加php一行 AddType application/x-httpd-php .php
4、增加一个索引页
[root@aminglinux ~]# vim /usr/local/apache2.4/conf/httpd.conf 搜索 /Index ,找到
DirectoryIndex index.html 在index.html后加 index.php 显示为DirectoryIndex index.html index.php
检查配置文件是否有错误,然后重新加载配置文件
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK [root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl graceful
检查Apache是否支持解析php5 验证
[root@aminglinux ~]# vi /usr/local/apache2.4/htdocs/1.php 在文件中写入 phpinfo(); ?> 然后保存退出
第一项,查看是否加载php5模块,使用/usr/local/apache2.4/bin/apachectl -M命令
第二项,如果有文件,则没有显示php模块,那么就要去看apache的配置文件中有没有加载 libphp5 这一行配置,在文件中搜索/libphp5 ,如果没有这一行配置,那么肯定也是无法解析的
第三项,检查配置文件中是否加载了 AddType application/x-httpd-php .php 这一行 在 .php 前面有一行空格,需要注意下!不能遗忘!!!——>使用 /usr/local/apache2.4/bin/apachectl -t 可以检查出配置写错了
第四项,检查是否加了 index.php
检查Apache是否支持解析php7