- lamp平台部署
- LAMP简介
- WEB资源类型:
- Web相关语言
- lamp平台部署步骤
- 环境说明
- 安装httpd
- 安装mysql
- 安装php
LAM(M)P:
L:linux
A:apache (httpd)
M:mysql, mariadb
M:memcached(缓存数据库数据)
P:php, perl, python
静态资源:原始形式与响应内容一致,在客户端浏览器执行
动态资源:原始形式通常为程序文件,需要在服务器端执行之后,将执行结果返回给客户端
注:动静资源不是视觉上的动和静,而是看服务器端的文件和客户端看到的文件是否相同。右键单击看源代码和服务器的资源文件内容一样==>静态资源。
Web相关语言客户端技术: html,javascript,css,jpg等
服务器端技术:php, jsp,python,asp,perl等
| 系统平台 | IP | 需要安装的服务 |
|---|---|---|
| centos8 | 192.168.240.60 | httpd-2.4 mysql-5.7 phpbr php-mysql |
lamp平台软件安装次序:
httpd --> mysql --> php安装httpd
##准备安装包与依赖包
[root@localhost lamp]# ls
apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.48.tar.gz
[root@localhost lamp]# yum -y install mark 'Development Tools' openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
##创建用户和组
[root@localhost lamp]# useradd -r -M -s /sbin/nologin apache
[root@localhost lamp]# id apache
uid=993(apache) gid=990(apache) 组=990(apache)
##将安装包进行解压
[root@localhost lamp]# tar xf apr-1.7.0.tar.gz -C /usr/local/
[root@localhost lamp]# tar xf apr-util-1.6.1.tar.gz -C /usr/local/
[root@localhost lamp]# tar xf httpd-2.4.48.tar.gz -C /usr/local/
[root@localhost lamp]# ls /usr/local/
apr-1.7.0 bin games include lib64 sbin src
apr-util-1.6.1 etc httpd-2.4.48 lib libexec share
##将$RM "$cfgfile" 删除
[root@localhost local]# cd apr-1.7.0/
[root@localhost apr-1.6.5]# vim configure
cfgfile="${ofile}T"
trap "$RM "$cfgfile"; exit 1" 1 2 15
$RM "$cfgfile"
##编译安装
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.5]# make && make install
[root@localhost apr-1.7.0]# cd ../apr-util-1.6.1/
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# make && make install
[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.48/
[root@localhost httpd-2.4.48]# ./configure --prefix=/usr/local/apache
> --enable-so
> --enable-ssl
> --enable-cgi
> --enable-rewrite
> --with-zlib
> --with-pcre
> --with-apr=/usr/local/apr
> --with-apr-util=/usr/local/apr-util/
> --enable-modules=most
> --enable-mpms-shared=all
> --with-mpm=prefork
[root@localhost httpd-2.4.48]# make && make install
##安装配置
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# which httpd
/usr/local/apache/bin/httpd
##创建软连接
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@localhost ~]# ll /usr/include/
总用量 1760
-rw-r--r--. 1 root root 1203 8月 24 19:14 alloca.h
-rw-r--r--. 1 root root 4350 8月 24 19:14 a.out.h
lrwxrwxrwx. 1 root root 26 9月 23 02:09 apache -> /usr/local/apache/include/
##设置帮助文档
[root@localhost apache]# vim /etc/man_db.conf
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man ##添加此行
[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80
##关闭防火墙跟selinux
[root@localhost ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
##设置启动配置文件
[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service
[root@localhost ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=Httpd server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:80 *:*
安装mysql
##解压软件包与下载依赖包 [root@localhost lamp]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@localhost lamp]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs ##创建mysql用户 [root@localhost ~]# useradd -r -M -s /sbin/nolong mysql [root@localhost ~]# id mysql uid=992(mysql) gid=989(mysql) 组=989(mysql) [root@localhost lamp]# cd /usr/local/ [root@localhost local]# mv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql ##更改所属组 [root@localhost local]# chown -R mysql.mysql /usr/local/mysql ##设置环境变量与软连接 [root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh [root@localhost local]# source /etc/profile.d/mysql.sh [root@localhost local]# ln -s /usr/local/mysql/include/ /usr/include/mysql/ ##设置帮助文档 [root@localhost local]# vim /etc/man_db.conf #MANDATORY_MANPATH /usr/src/pvm3/man # MANDATORY_MANPATH /usr/man MANDATORY_MANPATH /usr/share/man MANDATORY_MANPATH /usr/local/share/man MANDATORY_MANPATH /usr/local/apache/man MANDATORY_MANPATH /usr/local/mysql/man ##添加此行 ##设置库文件路径 [root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf [root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@localhost ~]# ldconfig ##创建数据库存放目录与更改所属组 [root@localhost ~]# mkdir /opt/data [root@localhost ~]# chown -R mysql.mysql /opt/data/ ##初始化数据库 [root@localhost ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data/ ##设置数据库配置文件 [root@localhost ~]# cat > /etc/my.cnf <安装php[mysqld] > basedir = /usr/local/mysql > datadir = /opt/data > socket = /tmp/mysql.sock > port = 3306 > pid-file = /opt/data/mysql.pid > user = mysql > skip-name-resolve > EOF [root@localhost ~]# cat /etc/my.cnf [mysqld] basedir = /usr/local/mysql datadir = /opt/data socket = /tmp/mysql.sock port = 3306 pid-file = /opt/data/mysql.pid user = mysql skip-name-resolve ##设置启动配置文件 [root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service [root@localhost ~]# cat /usr/lib/systemd/system/mysqld.service [Unit] Description=Mysql server daemon After=network.target [Service] Type=forking ExecStart=/usr/local/mysql/support-files/mysql.server start ExecStop=/usr/local/mysql/support-files/mysql.server stop ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target ##设置bestdir与datadir [root@localhost ~]# vim /usr/local/mysql/support-files/mysql.server # 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=/opt/data ##重新加载并设置开机自启 [root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl enable --now mysqld.service Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service. [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:* ##登录myslq并更改密码 [root@localhost ~]# mysql mysql> set password=password('lq123!'); Query OK, 0 rows affected, 1 warning (0.00 sec)
##解压二进制包 [root@localhost lamp]# ls apr-1.7.0.tar.gz httpd-2.4.48.tar.gz php-8.0.10.tar.gz apr-util-1.6.1.tar.gz mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz [root@localhost lamp]# tar xf php-8.0.10.tar.gz -C /usr/local/ ##下载依赖包 [root@localhost php-8.0.10]#yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel [root@localhost php-8.0.10]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm ##进行编译安装 [root@localhost ~]#./configure --prefix=/usr/local/php8 --with-config-file-path=/etc --enable-fpm --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix [root@localhost php-8.0.10]# make && make install ##安装后配置 [root@localhost php-8.0.10]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh [root@localhost php-8.0.10]# source /etc/profile.d/php.sh ##配置php [root@localhost php-8.0.10]# cp /etc/php.ini /opt/ [root@localhost php-8.0.10]# cp php.ini-production /etc/php.ini [root@localhost sapi]# cp fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost sapi]# chmod +x /etc/init.d/php-fpm ##http [root@localhost ~]# vim /usr/local/apache/conf/httpd.conf #LoadModule remoteip_module modules/mod_remoteip.so LoadModule proxy_module modules/mod_proxy.so ##取消注释 #LoadModule proxy_connect_module modules/mod_proxy_connect.so #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so #LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so ##取消注释 # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. #DirectoryIndex index.html index.php ##添加index.php # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php ##添加此行 AddType application/x-httpd-php-source .phps ##添加此行 # ##在配置文件的最后加入以下内容documentRoot "/usr/local/apache/htdocs/test" ServerName www.liuqiang.com ProxyRequests Off ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1 ##创建web访问目录 [root@localhost apache]# mkdir htdocs/test [root@localhost apache]# vim htdocs/test/index.php [root@localhost apache]# chown -R apache.apache /usr/local/apache/htdocs/ ##编辑php文件 [root@localhost ~]# cat /usr/local/apache/htdocs/test/index.php [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf [root@localhost etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf [root@localhost etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d [root@localhost etc]# cd php-fpm.d/ [root@localhost php-fpm.d]# ls www.conf.default [root@localhost php-fpm.d]# cp www.conf.default www.conf [root@localhost php-fpm.d]# service php-fpm start Starting php-fpm done ##重启mysql [root@localhost php-fpm.d]# systemctl restart httpd.service [root@localhost php-fpm.d]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 128 127.0.0.1:9000 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:*Options none AllowOverride none Require all granted
访问测试



