LAMP 环境 源码编译安装 (apache2.4 + php7 + mysql5.7)
转载
LAMP 环境 源码编译安装 (apache2.4 + php7 + mysql5.7)
install common tools (安装编译器,压缩工具等软件)
yum install -y gcc gcc-c++ make cmake git wget zip unzip bzip2
httpd
dnf install -y apr* gcc gcc-c++ pcre-devel zlib-devel redhat-rpm-config
tar xf httpd-2.4.43.tar.gz
cd httpd-2.4.43/
./configure --prefix=/opt/lamp/apache24 \
--enable-deflate --enable-expires \
--enable-headers --enable-modules=most \
--enable-so --with-mpm=worker \
--enable-rewrite && make -j12 && make install
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
useradd -M -s /sbin/nologin apache
cp /opt/lamp/apache24/bin/apachectl /etc/init.d/httpd
chmod +x /etc/init.d/httpd
systemctl daemon-reload
systemctl start httpd
mysql
dnf install -y cmake bison ncurses-devel libtirpc-devel openssl-devel
wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
tar xf rpcsvc-proto-1.4.tar.gz
cd rpcsvc-proto-1.4/
./configure && make -j12 && make install
tar xf mysql-boost-5.7.30.tar.gz
tar xf mysql-5.7.30.tar.gz
cd mysql-5.7.30
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DEFAULT_CHARSET=utf8 \
-DEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_BOOST=./boost
make -j12 && make install
useradd -M -s /sbin/nologin mysql
cd /usr/local/mysql
bin/mysqld --initialize \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql
rm -rf /etc/my.cnf
mkdir etc
vi etc/my.cnf
[mysqld]
user = mysql
port = 3306
bind-address = 0.0.0.0
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = /usr/local/mysql/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
max_connections = 1024
log-error = /var/log/mysqld.log
default-time_zone = '+8:00'
# skip-grant-tables
chown mysql:mysql -R .
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl daemon-reload
systemctl start mysqld
vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
php7.3
dnf install -y zlib zlib-devel libxml2-devel \
libjpeg libjpeg-devel libpng libpng-devel gd gd-devel \
curl curl-devel libxslt-devel openssl-devel
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
sed -i -e '/gets is a security/d' srclib/stdio.in.h
make -j12 && make install
yum install autoconf automake libtool
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install
tar xf php-7.4.7.tar.xz
cd php-7.4.7/
./configure \
--prefix=/opt/lamp/php7.4.7 \
--with-apxs2=/opt/lamp/apache24/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir && make -j12 && make install
cd /opt/lamp/php.xxx
cp php.ini-development php.ini-production /opt/lamp/php7.3.9/lib/ # 复制生产环境和开发环境,作为备份
cp php.ini-development /opt/lamp/php7.3.9/lib/php.ini # 再次复制作为修改使用
将apache24 和 php7整合
cd /opt/lamp/apache24/conf
vi httpd.conf
取掉LoadModule rewrite_module modules/mod_rewrite.so 前面的注释 ‘#’
修改 AllowOverride none 为All 此版本的apache在最后一个 如下
<Directory />
AllowOverride All
Require all denied
</Directory>
修改apache的进程守护者 (找到 User 将用户和组的名称改为 创建的apache用户)
User apache
Group apache
添加默认访问index.php作为首页访问 (改为如下内容)
DirectoryIndex index.php index.html
让.php, .html文件可以执行php
AddType application/x-httpd-php .php .html
配置虚机主机 (后面步骤可不用操作)
取掉 httpd配置文件中 Include conf/extra/httpd-vhosts.conf 前面的注释 ‘#’
配置虚拟主机
vi extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName local.demo.com
DocumentRoot /var/www/demo/public
<Directory "/var/www/demo/public">
Options -Indexes +Includes +FollowSymLinks +MultiViews
#AllowOverride All
Require all granted
</Directory>
# local.demo.com/uploads
Alias /uploads "/var/www/demo/uploads"
<Directory "/var/www/demo/uploads">
Options -Indexes +Includes +FollowSymLinks +MultiViews
#AllowOverride All
Require all granted
</Directory>
</VirtualHost>
配置过程中遇到各种报错信息的处理
- 报错:Package ‘libxml-2.0’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install libxml2-devel - 报错:Package ‘krb5’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install krb5-devel - 报错:Package ‘openssl’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install openssl-devel - 报错:Package ‘sqlite3’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install sqlite-devel - 报错:Package ‘libcurl’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install libcurl-devel - 报错:Package ‘oniguruma’, required by ‘virtual:world’, not found
参见:CentOS 8 安装 oniguruma 和 oniguruma-devel 一文
\报错:Package ‘libxslt’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install libxslt-devel - 报错:Package ‘libjpeg’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install libjpeg-devel - 报错:Package ‘libzip’, required by ‘virtual:world’, not found
[root@localhost php-7.4.2]# yum install libzip-devel - 报错:configure: error: Please reinstall the BZip2 distribution
[root@yjweb php-7.4.2]# yum -y install bzip2-devel - 报错:Package ‘libpng’, required by ‘virtual:world’, not found
[root@yjweb php-7.4.2]# yum install libpng-devel - 报错:Package ‘freetype2’, required by ‘virtual:world’, not found
[root@yjweb php-7.4.2]# yum install freetype-devel