源码安装lamp(centos7)

1、源码安装lamp(centos7)
(1)源码安装apr-1.5.2和apr-util-1.5.4
 cd apr-1.5.2
 ./configure && make && make install
 cd apr-util-1.5.4
 ./configure  --with-apr=/usr/local/apr/ && make && make install


(2)安装openssl-devel
 #mod_ssl has been requested
 yum -y install openssl-devel


(3)源码安装httpd-2.4.17
 #./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd/ --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl/ --enable-mods-shared=all --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr/  --enable-cgi --enable-suexec
 ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd/ --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl/ --enable-mods-shared=all --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr/  --enable-cgi
 make && make install


(4)源码安装mysql-5.6.27-linux-glibc2.5-x86_64
 #FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:Data::Dumper
 yum -y install perl-Data-Dumper
 
 tar zxvf mysql-5.6.27-linux-glibc2.5-x86_6.tar.gz -C /uar/local/
 cd /usr/local
 ln -s mysql-5.6.27-linux-glibc2.5-x86_64/ mysql
 cd mysql


 #添加mysql用户和群组
 groupadd mysql
 useradd -r -g mysql mysql


 #修改相关目录和文件属主和所属群组
 chown -R mysql .
 chgrp -R mysql .
 或者:chown -R mysql:mysql .
 
 #将目录属主更改为root,避免mysql用户将目录删除
 chown -R root .
 chown -R mysql data
 
 #使用mysql用户权限来初始化数据库
 scripts/mysql_install_db --user=mysql


 #将mysql添加为服务
 cp support-files/mysql.server /etc/init.d/mysqld
 chkconfig --add mysqld
 
 #将mysql的bin目录加入到PATH环境变量
 #在/etc/profile最后面添加
 echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
 source /etc/profile
 
 #脚本初始化已经添加mysqld脚本,如果没有直接cp /etc/init.d/mysqld
 /etc/rc.d/init.d/mysqld 
 
 #启动mysql
 mkdir -p /var/run/mysqld/
 chown -R mysql:mysql /var/run/mysqld/
 #/var/log/mariadb/mariadb.log No such file or directory
 mkdir -p /var/log/mariadb/ /var/run/mariadb/
 touch /var/log/mariadb/mariadb.log
 chown root:mysql /var/log/mariadb/mariadb.log /var/run/mariadb/
 chmod -R 774 /var/log/mariadb/mariadb.log /var/run/mariadb/
 
 /usr/local/mysql/bin/mysqld_safe &
 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
 
 #在/etc/my.cnf 文件socket参数指定为/tmp/mysql.sock
 echo "socket=/tmp/mysql.sock">>/etc/my.cnf
 #修改root密码为love
 #mysqladmin -u root -p password love --socket=/var/lib/mysql/mysql.sock
 mysqladmin -u root -p password love
 
 
(5)源码安装php-5.6.15
 #apxs是在安装php时生成动态连接模块工具,如果不指明路径,apache就无法调用php
 #一定要添加--with-apxs2=/usr/local/apache2/bin/apxs
 #php安装完成后,可以看到会在httpd.conf文件添加"LoadModule php5_module modules/libphp5.so"
 
 #安装依赖包libxml2-devel
 #error: xml2-config not found. Please check your libxml2 installation
 yum -y install libxml2-devel
 
 #libzip:not found
 yum -y install libzip-devel
 
 #动态加载php来完成解析
 #./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache2/bin/apxs
 ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache2/bin/apxs  --enable-mbstring --with-libzip --enable-zip
 make && make install
 
 cp php.ini-development /etc/php.ini
 #不需要进行手动更改就可以让apache调用php
 #php在编译的时候会修改httpd.conf配置文件,添加如下一行
 LoadModule php5_module        modules/libphp5.so
 #如果在编译的时候没有指定--with-apxs2=/usr/local/apache2/bin/apxs,则apache无法加载php 
 
(6)lamp连接测试
 #设置service方式启动apache
 #将启动脚本复制为/etc/init.d/httpd
 cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
 
 #可以这样来停止、启动和重启apache
 service httpd stop/start/restart
 /etc/init.d/httpd stop/start/restart
 /usr/local/apache2/bin/apachectl stop/start/restart


 #或许是因为兼容性不好,无法使用chkconfig设置开机启动
 chkconfig �Cadd httpd
 
 #但是可以修改/etc/rc.local设置apache开机启动
 #在/etc/rc.local添加
 /usr/local/apache2/bin/apachectl start
 
 #修改httpd.conf:
 #如果使用yum安装apache,配置文件存放在
 /etc/httpd/conf/httpd.conf
 
 #DocumentRoot为
 /var/www/html
 
 #如果是使用源码方法安装,配置文件存放在
 /usr/local/apache2/conf/httpd.conf
 
 #DocumentRoot为
 /usr/local/apache2/htdocs 
 
 #在<IfModule></IfModule>添加如下两行,以便apache知道怎样解析php文件
 AddType application/x-httpd-php .php .phtml
 AddType application/x-httpd-php-source .phps
 
 #修改ServerName
 ServerName 192.168.137.40:80
 
 #在htdocs目录添加文件index.php,内容如下
 #读取mysql数据库中的数据表user内容
<?php
 $con=mysql_connect("localhost","root","love");
 $sql="select user,password from user";
 $db_select=mysql_select_db("mysql",$con);
 $result=mysql_query($sql,$con);
 while ($row=mysql_fetch_array($result))
 {
 echo $row["user"]." ".$row["password"];
 echo "<br/>";
 }
 mysql_close($con);
?> 
 #从mysql数据库中读取数据表user并显示

你可能感兴趣的:(lamp)