lamp独立部署和分离部署
1.httpd安装
yum 源配置
#已安装 [root@localhost ~]# ls /etc/yum.repos.d/ CentOS-Linux-AppStream.repo CentOS-Linux-Debuginfo.repo CentOS-Linux-FastTrack.repo CentOS-Linux-Plus.repo epel-modular.repo epel-testing-modular.repo CentOS-Linux-BaseOS.repo CentOS-Linux-Devel.repo CentOS-Linux-HighAvailability.repo CentOS-Linux-PowerTools.repo epel-playground.repo epel-testing.repo CentOS-Linux-ContinuousRelease.repo CentOS-Linux-Extras.repo CentOS-Linux-Media.repo CentOS-Linux-Sources.repo epel.repo [root@localhost ~]# yum -y install epel-release vim
安装开发者工具包
[root@localhost ~]# dnf grouplist
[root@localhost ~]# dnf -y groups mark install "Development Tools"
创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin apache
安装依赖包
[root@localhost ~]# dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
下载安装apr和apr-util,httpd
#官网下载通过xftp传输 [root@localhost ~]# ls anaconda-ks.cfg apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 'httpd-2.4.46 (1).tar.bz2'
解压
[root@localhost ~]# tar xf apr-1.6.5.tar.bz2 [root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2 [root@localhost ~]# tar xf httpd-2.4.46\ \(1\).tar.bz2 [root@localhost ~]# ls anaconda-ks.cfg apr-1.6.5 apr-1.6.5.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 httpd-2.4.46 'httpd-2.4.46 (1).tar.bz2'
[root@localhost ~]# cd apr-1.6.5
[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.6.5]# ./configure --prefix=/usr/local/apr 配置过程略... [root@localhost apr-1.6.5]# make && make install 编译安装过程略... [root@localhost apr-1.6.5]# cd /usr/src/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 ~]# cd httpd-2.4.46 [root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/apache \ --sysconfdir=/etc/httpd24 \ --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.38]# 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 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd [root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man_db.conf
#关闭防火墙
[root@localhost httpd-2.4.46]# systemctl stop firewalld
[root@localhost httpd-2.4.46]# setenforce 0
[root@localhost httpd-2.4.46]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# vim /etc/selinux/config
selinux=xxx改成disabled
root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
2.mysql安装
安装依赖包
yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
创建用户和组
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
下载二进制mysql包
#已下载通过xftp [root@localhost ~]# ls anaconda-ks.cfg mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
解压
[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ #改名 [root@localhost ~]# cd /usr/local/ [root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ls
apache apr apr-util bin etc games include lib lib64 libexec mysql sbin share src
改属主属组
[root@localhost local]# chown -R mysql.mysql mysql/ [root@localhost local]# ll total 0 drwxr-xr-x. 13 root root 152 May 14 04:37 apache drwxr-xr-x. 6 root root 58 May 14 04:31 apr drwxr-xr-x. 5 root root 43 May 14 04:32 apr-util drwxr-xr-x. 2 root root 6 Nov 3 2020 bin drwxr-xr-x. 2 root root 6 Nov 3 2020 etc drwxr-xr-x. 2 root root 6 Nov 3 2020 games drwxr-xr-x. 2 root root 6 Nov 3 2020 include drwxr-xr-x. 2 root root 6 Nov 3 2020 lib drwxr-xr-x. 3 root root 17 May 14 03:09 lib64 drwxr-xr-x. 2 root root 6 Nov 3 2020 libexec drwxr-xr-x. 9 mysql mysql 129 May 14 05:06 mysql drwxr-xr-x. 2 root root 6 Nov 3 2020 sbin drwxr-xr-x. 5 root root 49 May 14 03:09 share drwxr-xr-x. 2 root root 6 Nov 3 2020 src
环境变量
[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 ~]# ln -s /usr/local/mysql/include /usr/include/mysql [root@localhost ~]# vim /etc/ld.so.conf.d/mysql.cnf #这里写入/usr/local/mysql/lib 库文件
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.cnf
/usr/local/mysql/lib
[root@localhost ~]# ldconfig [root@localhost ~]# echo 'MANPATH /usr/local/mysql/man' >> /etc/man_db.conf #文档
创建数据目录
[root@localhost ~]# mkdir /opt/data [root@localhost ~]# chown -R mysql.mysql /opt/data/
初始化数据
[root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data 2021-05-14T15:23:02.624095Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2021-05-14T15:23:02.836340Z 0 [Warning] InnoDB: New log files created, LSN=45790 2021-05-14T15:23:02.869153Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2021-05-14T15:23:02.923422Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 46347540-b4c8-11eb-a547-000c297a9e6b. 2021-05-14T15:23:02.923958Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2021-05-14T15:23:03.691702Z 0 [Warning] CA certificate ca.pem is self signed. 2021-05-14T15:23:03.921605Z 1 [Note] A temporary password is generated for root@localhost: S<dm*p(wi1=u [root@localhost ~]# echo 'S<dm*p(wi1=u > ' > pass [root@localhost ~]# ls anaconda-ks.cfg apr-1.6.5 apr-1.6.5.tar.bz2 apr-util-1.6.1 apr-util-1.6.1.tar.bz2 httpd-2.4.46 'httpd-2.4.46 (1).tar.bz2' mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz pass
生成配置文件
[root@localhost ~]# cat > /etc/my.cnf <<EOF [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 ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/opt/data
启动mysql
[root@localhost ~]# service mysqld start Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'. SUCCESS! [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:80 *:* LISTEN 0 128 [::]:22 [::]:*
登录mysql直接安装依赖
[root@localhost ~]# dnf -y install ncurses-compat-libs
登录修改密码
[root@localhost ~]# cat pass S<dm*p(wi1=u [root@localhost ~]# mysql -uroot -p'S<dm*p(wi1=u' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.33 Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set password=password('4564949a'); Query OK, 0 rows affected, 1 warning (0.00 sec)
#开机自动启动
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3.php安装
安装依赖
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
安装php
[root@localhost ~]# dnf -y install php*
[root@localhost ~]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright (c) 1999-2018, by Zend Technologies
启动
[root@localhost ~]# systemctl start php-fpm [root@localhost ~]# systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2021-05-14 05:50:07 -10; 7s ago Main PID: 57603 (php-fpm) Status: "Ready to handle connections" Tasks: 6 (limit: 4748) Memory: 41.4M CGroup: /system.slice/php-fpm.service ├─57603 php-fpm: master process (/etc/php-fpm.conf) ├─57604 php-fpm: pool www ├─57605 php-fpm: pool www ├─57606 php-fpm: pool www ├─57607 php-fpm: pool www └─57608 php-fpm: pool www May 14 05:50:07 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager... May 14 05:50:07 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager. [root@localhost ~]# systemctl enable php-fpm #开机自动启动 Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# ls /etc/php-fpm.d/
www.conf
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
listen =0.0.0.0:9000
[root@localhost ~]# systemctl restart php-fpm
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
4.配置apache
启用代理模块
在apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩展,因此,这两个模块都要加载,编辑httpd.conf文件,取消以下两行内容的注释:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
[root@localhost ~]# vim /etc/httpd24/httpd.conf
5.配置虚拟主机
在需要使用fcgi的虚拟主机中添加类似如下两行:
ProxyRequests Off //关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
例如:
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/idfsoft.com/$1
以上设置表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
创建虚拟主机目录
#创建 [root@localhost ~]# cd /usr/local/apache/htdocs/ [root@localhost htdocs]# mkdir runtime [root@localhost htdocs]# cd runtime/ [root@localhost runtime]# vim index.php [root@localhost httpd24]# cat /usr/local/apache/htdocs/runtime/index.php <?php phpinfo(); ?> #软链接 [root@localhost runtime]# chown -R apache.apache /usr/local/apache/htdocs/ [root@localhost runtime]# ll total 4 -rw-r--r--. 1 apache apache 22 May 14 20:27 index.php #主配置文件 [root@localhost httpd24]# ls extra httpd.conf magic mime.types original [root@localhost httpd24]# vim httpd.conf # Various default settings #Include /etc/httpd24/extra/httpd-default.conf Include /etc/httpd24/extra/vhosts.conf #在AddType这后面添加
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps #Apache配置文件 [root@localhost extra]# vim vhosts.conf [root@localhost extra]# cat vhosts.conf <VirtualHost *:80> DocumentRoot "/usr/local/apache/htdocs/runtime" ServerName www.Mariko.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/runtime/$1 <Directory "/usr/local/apache/htdocs/runtime"> Options none AllowOverride none Require all granted </Directory> </VirtualHost> #将index.php添加上去
[root@localhost httpd24]# vim httpd.conf


重启apache
[root@localhost ~]# apachectl stop [root@localhost ~]# apachectl start


浙公网安备 33010602011771号