lamp平台建构
环境说明:
系统平台 | IP | 需要安装的服务 |
---|---|---|
contos7 | 192.168.111.142 | httpd mysql php |
安装顺序:
httpd > mysql > php
安装httpd
[root@apache ~]# yum -y install vim wget
[root@apache ~]# yum groups mark install 'Development Tools' -y
[root@apache ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
[root@apache src]# wget https://dlcdn.apache.org/httpd/httpd-2.4.49.tar.gz
[root@apache src]# wget https://dlcdn.apache.org/apr/apr-1.7.0.tar.gz
[root@apache src]# wget https://dlcdn.apache.org/apr/apr-util-1.6.1.tar.gz
[root@apache src]# ls
apr-1.7.0.tar.gz httpd-2.4.49.tar.gz
apr-util-1.6.1.tar.gz kernels
debug mysql57-community-release-el7-10.noarch.rpm
[root@apache src]# tar xf apr-1.7.0.tar.gz
[root@apache src]# tar xf apr-util-1.6.1.tar.gz
[root@apache src]# tar xf httpd-2.4.49.tar.gz
[root@apache src]# ls
apr-1.7.0 httpd-2.4.49
apr-1.7.0.tar.gz httpd-2.4.49.tar.gz
apr-util-1.6.1 kernels
apr-util-1.6.1.tar.gz mysql57-community-release-el7-10.noarch.rpm
debug
[root@apache src]# cd apr-1.7.0
[root@apache apr-1.7.0]# vim configure
cfgfile="${ofile}T"
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile" //将此行加上注释,或者删除此行
[root@apache apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@apache apr-1.7.0]# make && make install
[root@apache src]# cd ../apr-util-1.6.1
[root@apache apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@apache apr-util-1.6.1]# make && make install
[root@apache apr-util-1.6.1]# cd ../httpd-2.4.49/
[root@apache httpd-2.4.49]# ./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@apache httpd-2.4.49]# make && make install
[root@apache ~]# ls /usr/local/apache/
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@apache ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@apache ~]# source /etc/profile.d/httpd.sh
[root@apache ~]# which httpd
/usr/local/apache/bin/httpd
[root@apache ~]# ln -s /usr/local/apache/include/ /usr/include/apache
[root@apache ~]# ll /usr/local
lrwxrwxrwx. 1 root root 26 9月 23 16:56 apache -> /usr/local/apache/include/
[root@apache ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /usr/man
MANDATORY_MANPATH /usr/share/man
MANDATORY_MANPATH /usr/local/share/man
MANDATORY_MANPATH /usr/local/apache/man
[root@apache ~]# vim /usr/local/apache/conf/httpd.conf
ServerName www.example.com:80 //取消这一行的注释
[root@apache ~]# cat /usr/lib/systemd/system/sshd.service > /usr/lib/systemd/system/httpd.service
[root@apache ~]# vim /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@apache ~]# systemctl daemon-reload
[root@apache ~]# systemctl status httpd
● httpd.service - Httpd server daemon
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: dd)
Active: inactive (dead)
[root@apache ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /u/systemd/system/httpd.service.
[root@apache ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@apache ~]# systemctl status httpd
● httpd.service - Httpd server daemon
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: di)
Active: active (running) since 四 2021-09-23 19:59:03 CST; 31s ago
Process: 37910 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, statuCCESS)
Main PID: 37913 (httpd)
CGroup: /system.slice/httpd.service
├─37913 /usr/local/apache/bin/httpd -k start
├─37914 /usr/local/apache/bin/httpd -k start
├─37915 /usr/local/apache/bin/httpd -k start
├─37916 /usr/local/apache/bin/httpd -k start
├─37917 /usr/local/apache/bin/httpd -k start
└─37918 /usr/local/apache/bin/httpd -k start
9月 23 19:59:03 apache.lamp systemd[1]: Starting Httpd server daemon...
9月 23 19:59:03 apache.lamp systemd[1]: Started Httpd server daemon.
安装mysql
[root@apache ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
[root@apache ~]# useradd -r -M -s /sbin/nologin mysql
[root@apache ~]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@apache ~]# cd /usr/local/
[root@apache local]# ls
apache etc lib sbin
apr games lib64 share
apr-util httpd libexec src
bin include mysql-5.7.34-linux-glibc2.12-x86_64
[root@apache local]# mv mysql-5.7.34-linux-glibc2.12-x86_64 mysql
[root@apache local]# chown -R mysql.mysql mysql
[root@apache local]# ll
drwxr-xr-x. 9 mysql mysql 129 9月 23 20:16 mysql
[root@apache ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@apache ~]# source /etc/profile.d/mysql.sh
[root@apache ~]# ls /usr/local/mysql/
bin docs include lib LICENSE man README share support-files
[root@apache ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@apache ~]# vim /etc/man_db.conf
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@apache ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@apache ~]# ldconfig
[root@apache ~]# mkdir /opt/data
[root@apache ~]# chown -R mysql.mysql /opt/data
[root@apache ~]# bash
[root@apache ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data
[root@apache ~]# 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@apache ~]# cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/mysql.service
[root@apache ~]# vim /usr/lib/systemd/system/mysql.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
[root@apache ~]# vim /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/opt/data
[root@apache ~]# systemctl daemon-reload
[root@apache ~]# systemctl start mysqld
[root@apache ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::22 :::*
[root@apache ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 MySQL Community Server (GPL)
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>
mysql> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
报错
[root@localhost ~]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# sudo yum install libncurses*
安装php
[root@apache ~]# 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-mysqlnd libzip-devel libsqlite3x libsqlite3x-devel oniguruma libzip-devel https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@apache ~]# cd /usr/src/
[root@apache src]# wget https://www.php.net/distributions/php-8.0.10.tar.gz
[root@apache ~]# cd /usr/src/php-8.0.10
[root@apache php-8.0.10]# ./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@apache php-8.0.10]# make install
[root@apache ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@apache ~]# source /etc/profile.d/php.sh
[root@apache ~]# cd /usr/src/php-8.0.10
[root@apache php-8.0.10]# cp php.ini-production /etc/php.ini
[root@apache php-8.0.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@apache ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@apache ~]# cd /usr/local/php8/etc/
[root@apache etc]# cp php-fpm.conf.default php-fpm.conf
[root@apache etc]# cd php-fpm.d/
[root@apache php-fpm.d]# cp www.conf.default www.conf
[root@apache ~]# service php-fpm start
Starting php-fpm done
[root@apache ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
配置apache
[root@localhost php-8.0.10]# vim /usr/local/apache/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
// 取消这两行的注释
配置虚拟机
[root@localhost php-8.0.10]# cd /usr/local/apache/
[root@localhost apache]# ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@localhost apache]# ls htdocs/
index.html
[root@localhost apache]# mkdir htdocs/test
[root@localhost apache]# vim htdocs/test/index.php
<?php
phpinfo();
?>
[root@localhost apache]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost apache]# vim conf/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/test"
ServerName www.shaoyaobang.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
<Directory "/usr/local/apache/htdocs/test">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>