centos7源码编译安装LAMP

LAMP用到的软件版本:

httpd-2.4.27.tar.gz mariadb-10.2.8-linux-x86_64.tar.gz php-7.1.10.tar.xz

安装顺序:
顺序: mariadb–>httpd–>php
httpd和mariadb顺序无所谓,PHP是最后,因为PHP编译时要指明httpd的路径

编译安装mariadb(二进制)

tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ls -sv mariadb-10.2.8-linux-x86_64 mysql
useradd -r -m -d /app/mydata -s /sbin/nologin mysql
mkdir /etc/mysql
cd mysql/
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]加三行
datadir =/mydata/data
innodb_file_per_table = ON
skip_name_resolve = ON
scripts/mysql_install_db --user=mysql datadir=/app/mydata
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
/usr/local/mysql/bin/mysql #测试是否成功
vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin/:$PATH
/usr/local/mysql/bin/mysql_secure_installation #安全初始化数据库

编译安装httpd2.4

yum install pcre-devel apr-devel apr-util-devel openssl-devel apr apr-util
tar xvf httpd-2.4.27.tar.gz
cd httpd-2.4.27
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-apr-util=/usr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install
cd /app/httpd24
cp bin/apachectl /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on

编译安装PHP

tar xvf php-7.1.10.tar.xz
cd php-7.1.10
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pdomysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
cp php.ini-production /etc/php.ini #为php提供配置文件
vim /etc/httpd24/conf/httpd.conf #编辑apache配置文件httpd.conf,以使apache支持php
AddType application/x-httpd-php .php #在最后添加两行
AddType application/x-httpd-php-source .phps
#定位至DirectoryIndex index.html
修改为DirectoryIndex index.php index.html
systemctl start httpd

注意: php-7.0以上版本使用 –enable-mysqlnd –with-mysqli=mysqlnd ,原–with-mysql不再支持

测试

vi /app/httpd24/htdocs/index.php
<?php
$mysqli=new mysqli("localhost","root","123456");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
?>

访问网站,看是否能连通数据库,记得要设置数据库密码,当然数据库最好放在其他服务器上。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值