編譯安裝LAMP
(1) 系統環境:CentOS 6, 7
CentOS 6:apr, apr-util
的版本為1.3.9
,不適用于httpd-2.4
;
CentOS 7:apr, apr-util
的版本為1.4+
,
(2) 開發環境:Development Tools, Server Platform Development
(3) 各程序版本
httpd: 2.2, 2.4
php:5.3.x 5.4.x, 5.6.x
mysql:5.1, 5.5, 5.6, 5.7, 5.8, 8.0
mariadb:5.x, 10.x
(4) httpd+php
php的編譯選項:
Modules:--with-apxs
httpd MPM:
prefork:
worker, event:專用選項–enable-maintainer-zts
fpm:--enable-fpm
本次安裝以CentOS 7為例進行安裝
安裝httpd-2.4
[root@centos7 ~]# mkdir -p /usr/local/lamp #創建lamp目錄
[root@centos7 ~]# yum -y groupinstall "Development Tools" "Server Platform Development" #安裝開發環境
[root@centos7 ~]# yum -y install pcre-devel openssl-devel libevent-devel apr-devel apr-util-devel #安裝依賴包
[root@centos7 ~]# useradd -r -s /sbin/nologin apache #創建apache系統用戶
[root@centos7 ~]# tar xf httpd-2.4.6.tar.bz2 #解壓
[root@centos7 ~]# cd httpd-2.4.6/
[root@centos7 httpd-2.4.6]# ./configure --prefix=/usr/local/lamp/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr --with-apr-util=/usr #配置httpd
[root@centos7 httpd-2.4.6]# make #編譯
[root@centos7 httpd-2.4.6]# make install #安裝
[root@centos7 ~]# echo "export PATH=/usr/local/lamp/apache2/bin:$PATH" > /etc/profile.d/httpd.sh #配置PATH環境變量
[root@centos7 ~]# . /etc/profile.d/httpd.sh #生效
[root@centos7 ~]# vim /etc/httpd/httpd.conf #編輯配置文件
[root@centos7 ~]# apachectl start #啟動httpd服務
安裝mariadb
安裝MariaDB:
1.預制的包管理器格式的程序包:
rpm包:
os vendor:mariadb-devel
MariaDB官方
2.通用二進制格式的程序包:
3.源碼包編譯:項目構建工具為cmake, 而非流行的make;
本次以通用二進制格式包的安裝配置
[root@centos7 ~]# useradd -r -s /sbin/nologin mysql #創建mysql系統用戶
[root@centos7 ~]# tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local/lamp #解壓至/usr/local/lamp目錄下
[root@centos7 ~]# cd /usr/local/lamp
[root@centos7 lamp]# ln -s mariadb-VERSION-linux-x86_64 mysql #創建軟連接
[root@centos7 ~]# cd mysql
[root@centos7 mysql]# chown -R mysql:mysql ./* #修改屬主屬組為mysql
[root@centos7 mysql]# mkdir -pv /mydata/data #為mysql創建數據目錄
[root@centos7 mysql]# chown -R mysql:mysql /mydata/data #修改數據目錄屬主屬組為msql
[root@centos7 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/mydata/data --skip_name_resolve #安裝mysql
[root@centos7 mysql]# cp support-files/my-large.cnf /etc/my.cnf #生成配置文件
[root@centos7 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld #生成服務腳本文件
[root@centos7 mysql]# chkconfig --add mysqld #添加開機自啟動
[root@centos7 mysql]# chkconfig --level 2345 mysqld on #開機在2345運行級別下啟動
[root@centos7 mysql]# vim /etc/my.cnf #編輯配置文件
[root@centos7 mysql]# service mysqld start #啟動mysql服務
Starting MySQL.. SUCCESS!
[root@centos7 mysql]#
[root@centos7 ~]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh #配置PATH環境變量
[root@centos7 ~]# . /etc/profile.d/mysql.sh #生效
[root@centos7 ~]# mysql_secure_installation #可對數據庫做安全配置
[root@centos7 ~]# mysql #測試數據庫
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.46-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> #數據庫配置成功!?。。?/code>
基于module安裝php
Modules:
--with-apxs
httpd MPM:
prefork:
worker, event:專用選項--enable-maintainer-zts
[root@centos7 ~]# yum -y install gd-devel freetype-devel libxml2-devel libmcrypt-devel #安裝php依賴包
[root@centos7 ~]# tar xf php-5.4.40.tar.bz2 #解壓
[root@centos7 ~]# cd php-5.4.40/
[root@centos7 php-5.4.40]# ./configure --prefix=/usr/local/lamp/php5 --with-mysql=/usr/local/lamp/mysql --with-mysqli=/usr/local/lamp/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --with-apxs2=/usr/local/lamp/apache2/bin/apxs --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/ #配置php參數
[root@centos7 php-5.4.40]# make #編譯
[root@centos7 php-5.4.40]# make install #安裝
[root@centos7 php-5.4.40]# cp php.ini-production /etc/php.ini #復制配置文件
[root@centos7 php-5.4.40]# vim /etc/httpd/httpd.conf #編輯httpd配置文件整合httpd+php
[root@centos7 ~]# vim /usr/local/lamp/apache2/htdocs/index.php #創建默認訪問頁
測試
基于php-fpm安裝php
fpm:--enable-fpm
[root@centos7 ~]# yum -y install gd-devel freetype-devel libxml2-devel libmcrypt-devel #安裝php依賴包
[root@centos7 ~]# tar xf php-5.4.40.tar.bz2 #解壓
[root@centos7 ~]# cd php-5.4.40/
[root@centos7 php-5.4.40]# ./configure --prefix=/usr/local/lamp/php5 --with-mysql=/usr/local/lamp/mysql --with-mysqli=/usr/local/lamp/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --enable-fpm --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/ #配置php參數
[root@centos7 php-5.4.40]# make #編譯
[root@centos7 php-5.4.40]# make install #安裝
[root@centos7 php-5.4.40]# cp php.ini-production /etc/php.ini #復制配置文件
[root@centos7 php-5.4.40]# cp /usr/local/lamp/php5/php-fpm.conf.default /usr/local/lamp/php5/php-fpm.conf #生成php-fpm配置文件
[root@centos7 php-5.4.40]# vim /etc/httpd/httpd.conf #編輯httpd配置文件整合httpd+php
[root@centos7 php-5.4.40]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #生成php-fpm服務腳本文件
[root@centos7 php-5.4.40]# chkconfig --add php-fpm #添加php-fpm開機自啟動
[root@centos7 php-5.4.40]# chkconfig --level 2345 php-fpm on #開機在2345運行級別下開啟此服務
[root@centos7 ~]# service php-fpm start #開啟php-fpm服務
測試
原創文章,作者:zhai796898,如若轉載,請注明出處:http://www.www58058.com/57262