一、httpd
[root@localhost ~]# systemctl stop firewalld
[root@www ~]# systemctl disable firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/sysconfig/selinux
[root@localhost ~]# rpm -e httpd --nodeps (检查是否安装httpd)
错误:未安装软件包 httpd
[root@localhost ~]# yum -y install apr-util-devel pcre-devel gcc*(开发环境)
安装所需的软件包
[root@localhost ~]# tar zxvf httpd-2.4.25.tar.gz (解压)
[root@localhost ~]# cd httpd-2.4.25
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-deflate
备注:
./configure:指定安装包功能,配置
--prefix:路径前缀 制定程序的安装目录
--enable-so:启用动态加载模块DSO的支持,使httpd具备进一步扩展功能的能力
--enable-rewrite:启用网页地址重写功能,用于网站优化
--enable-charset-lite:启动字符集支持,以便支持使用各种字符集编码的网页
--enable-cgi:启用cgi脚本程序支持,扩展网站的应用访问能力;c通用g网关i接口
--enable-deflate:网页压缩
[root@localhost httpd-2.4.25]# make && make install
[root@localhost httpd-2.4.25]# ls /usr/local/httpd/
bin build cgi-bin conf error htdocs icons include logs man manual modules
备注:
bin:命令
logs:存放日志
conf:存放配置文件
htdocs:网站文档
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ (命令优化)
[root@localhost ~]# httpd -v
Server version: Apache/2.4.25 (Unix)
Server built: Jun 11 2024 14:58:13
[root@localhost ~]# apachectl start
[root@localhost ~]# netstat -anpt | grep httpd
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf (关闭消息提示)
[root@localhost systemd]# cd /lib/systemd/system
[root@localhost system]# vim httpd.service (httpd系统服务,保持后缀名必须是.service)
[Unit]
Description=zhangsan
After=network.target (在apache之后启动)
[Service]
Type=forking (启动方式)
PIDFile=/usr/local/httpd/logs/httpd.pid (文件放置位置)
ExecStart= /usr/local/bin/apachectl $OPTIONS (启动。关闭apachecyl)
ExecReload= /bin/kill -HUP $MAINPID (重载)
[Install]
WantedBy=multi-user.target (多用户目标)
[root@localhost system]# systemctl daemon-reload
[root@localhost system]# systemctl enable httpd.service
[root@localhost system]# systemctl start httpd
[root@localhost system]# netstat -anpt | grep httpd
1.虚拟主机(基于主机名)
虚拟主机(单个主机运行多个站点)
站点1:httpd---ip+80
站点2:httpd---ip+80
-
基于ip的虚拟主机
-
基于端口的虚拟主机
3.基于主机名的虚拟主机
[root@localhost ~]# cd /usr/local/httpd/htdocs/ (默认站点位置)
[root@localhost htdocs]# ls
index.html
102为虚拟主机提供域名解析
[root@localhost ~]# vim /etc/hosts
192.168.10.101 www.accp.com
192.168.10.101 www.benet.com
[root@localhost ~]# mkdir -p /var/www/html/accpcom (创建站点目录)
[root@localhost ~]# mkdir -p /var/www/html/benetcom
[root@localhost ~]# echo "www.accp.com">/var/www/html/accpcom/index.html
[root@localhost ~]# echo "www.benet.com">/var/www/html/benetcom/index.html
[root@localhost ~]# cd /usr/local/httpd/conf/
[root@localhost conf]# ls
extra httpd.conf magic mime.types original
[root@localhost conf]# cd extra/
[root@localhost extra]# ls
httpd-autoindex.conf httpd-info.conf httpd-mpm.conf httpd-userdir.conf
httpd-dav.conf httpd-languages.conf httpd-multilang-errordoc.conf httpd-vhosts.conf
httpd-default.conf httpd-manual.conf httpd-ssl.conf proxy-html.conf
[root@localhost extra]# vim httpd-vhosts.conf (虚拟主机)
<Directory "/var/www/html">
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot "/var/www/html/benetcom" (网站文件位置)
ServerName www.benet.com (与客户端hosts名称一致)
ServerAlias www.dummy-host.example.com
ErrorLog "logs/www.benet.com.error_log"
CustomLog "logs/www.benet.com.access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/var/www/html/accpcom"
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
</VirtualHost>
[root@localhost extra]# vim /usr/local/httpd/conf/httpd.conf (主配置文件去掉注释符)
Include conf/extra/httpd-vhosts.conf (490)
[root@localhost extra]# systemctl restart httpd
102测试
[root@localhost ~]# curl www.accp.com
[root@localhost ~]# curl www.benet.com
2.虚拟主机(基于IP)
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vim ifcfg-ens33:0
[root@localhost network-scripts]# systemctl restart network
[root@localhost ~]# cd /usr/local/httpd/conf/extra/
<VirtualHost 192.168.10.210:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/var/www/html/accpcom"
ServerName www.accp.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
</VirtualHost>
<VirtualHost 192.168.10.101:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/var/www/html/benetcom"
ServerName www.benet.com
ErrorLog "logs/www.benet.com.error_log"
CustomLog "logs/www.benet.com.access_log" common
</VirtualHost>
102客户机访问即可
[root@localhost ~]# curl 192.168.10.101
[root@localhost ~]# curl 192.168.10.210
3.虚拟主机(基于端口)
Listen 80
Listen 8080
<VirtualHost 192.168.10.210:80>
..........
</VirtualHost>
<VirtualHost 192.168.10.101:8080>
[root@localhost extra]# netstat -anpt | grep httpd
客户机102检测
[root@localhost ~]# curl 192.168.10.210
[root@localhost ~]# curl 192.168.10.101:8080
二、Mysql
<安装所需的mysql软件包>
[root@localhost ~]#yum -y install ncurses-devel autoconf
备注:
初始化mysql需要autoconf,它是自动化配置脚本生成工具,安装自动化脚本生成工具
[root@localhost ~]# tar zxvf mysql-5.6.36.tar.gz
[root@localhost mysql-5.6.36]# yum -y install cmake (利用yum安装cmake,进行编译没有config)
[root@localhost mysql-5.6.36]# useradd -M -s /sbin/nologin mysql (特有的程序运行mysql)
备注:
sbin/nologin 不允许使用命令语句登陆系统
[root@localhost mysql-5.6.36]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
[root@localhost mysql-5.6.36]# make && make install
[root@localhost ~]# cd /usr/local/
[root@localhost local]# chown -R mysql:mysql mysql/ (更改属主属组)
[root@localhost ~]# rm -rf /etc/my.cnf (删除该文件,非源码包生成)
[root@localhost ~]# cd mysql-5.6.36
[root@localhost mysql-5.6.36]# cd support-files/
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf (my-default.cnf源码包的配置文件)
初始化:
[root@localhost ~]# cd /usr/local/mysql/scripts/
[root@localhost scripts]# ls
mysql_install_db (用于初始化)
[root@localhost scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
备注:
--user=mysql 指定用户
--basedir=/usr/local/mysql 指定目录路径
--datadir=/usr/local/mysql/data 数据文件位置
[root@localhost ~]# vim /etc/profile (全局变量文件)
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost ~]# source /etc/profile (重载该文件)但是还无法正常使用
[root@localhost mysql-5.6.36]# cd support-files/
mysql.server (mysql服务配置文件)
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]# chmod +x /etc/init.d/mysqld (名称一致)
[root@localhost support-files]# chkconfig --add mysqld (将mysqld添加为系统服务)
[root@localhost support-files]# chkconfig mysqld on (开机自启)
[root@localhost support-files]# systemctl restart mysqld
[root@localhost support-files]# netstat -anpt | grep mysqld (mysql端口号3306)
[root@localhost ~]# mysql -uroot (登录mysql)
备注:
-u 指定用户
-p 密码
mysql> set password=password("pwd123");
" "密码是一个字符串用引号
password("pwd123") :利用password函数对密码进行加密
; 结尾+;表示语句的结束
[root@localhost ~]# mysql -uroot -ppwd123 (验证,且-u与root之间没有空格;-p和pwd123之间my空格)
三、PHP
<安装所需要的php压缩包>
[root@localhost ~]# tar zxvf php-5.5.38.tar.gz
[root@localhost ~]#yum -y install zlib-devel libxml2 libxml2-devel lxz-devel
备注:
zlib-devel 提供压缩
libxml2 文件
libxml2-devel 对应函数库
lxz-devel
若lxz-devel无法安装,可以使用阿里云安装
在另一个终端安装相应包:
101(1)
[root@localhost ~]# yum -y install libmcrypt libmcrypt-devel mcrypt mhash
[root@localhost php-5.5.38]# ./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-config-file-path=/usr/local/php5 --enable-mbstring
备注:
--prefix=/usr/local/php5
--with-mcrypt (加密)
--with-apx2=/usr/local/httpd/bin/apxs (与apache中so联动)
--with-mysql=mysqlnd (函数集)
--with-mysqli=mysqlnd (扩展函数集)
--with-config-file-path=/usr/local/php5 (配置文件)
--enable-mbstring (多字符串)
[root@localhost php-5.5.38]# make && make install
[root@localhost php-5.5.38]# cp php.ini-development /usr/local/php5/php.ini (复制php配置文件)
[root@localhost php-5.5.38]# vim /usr/local/php5/php.ini
default_charset = "UTF-8" (字符集)
short_open_tag = On (开启短语)
extension=php_mysqli.dll (开启MySQL)
加密
<安装zend-loader-php>
[root@localhost ~]# tar zxvf zend-loader-php5.5-linux-x86_64_update1.tar.gz
[root@localhost zend-loader-php5.5-linux-x86_64]# ls
opcache.so README.txt ZendGuardLoader.so
备注:
ZendGuardLoader.so模块文件
[root@localhost zend-loader-php5.5-linux-x86_64]# cp ZendGuardLoader.so /usr/local/php5/lib/php/
[root@localhost ~]# vim /usr/local/php5/php.ini
zend_extenstion=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
LoadModule php5_module modules/libphp5.so (确认php是否安装成功)
AddType application/x-httpd-php .php (添加php程序397)
index.php (php默认索引文件259)
[root@localhost ~]# httpd -t (检查语法)
Syntax OK
[root@localhost ~]# systemctl restart httpd (重启)
四、测试LAMP连接性
1.PHP与网页正确连接
[root@localhost ~]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# vim test1.php
<?php
phpinfo( );
?>
2.PHP与MYSQL连接
[root@localhost htdocs]# vim test2.php
<?php
$link=mysqli_connect('localhost','root','pwd123');
if($link) echo "连接成功";
mysqli_close($link);
?>
五、部署PHPMyAdmin
<复制安装包>
[root@localhost ~]# tar zxvf phpMyAdmin-4.7.2-all-languages.tar.gz
[root@localhost ~]# mv phpMyAdmin-4.7.2-all-languages /usr/local/httpd/htdocs/phpMyAdmin
[root@localhost ~]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html phpMyAdmin test1.php test2.php (检查是否安装成功)
[root@localhost phpMyAdmin]# cp config.sample.inc.php config.inc.php (php连接MySQL)
网页测试