23312321 发表于 2016-12-6 08:47:29

编译安装lamp

软件包链接:
http://pan.baidu.com/s/1mijn44g   密码:abja
系统环境:centos 7

开发环境:Development tools、Server Platform Development

http+php的方式:PHP模块化

个程序版本:


mariadbmariadb-5.5.46-linux-x86_64.tar.gz
httphttpd-2.4.10.tar.bz2
PHPphp-5.4.40.tar.bz2
一、编译安装mariadb
①创建MySQL用户

1
~]#useradd -u 306 -r -s /sbin/nologin mysql




②将压缩包展开至/usr/local/目录下,并创建链接


1
2
~]#tar xvf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/
local]# ln -smariadb-5.5.46-linux-x86_64/ mysql




mariadb需要假设自己运行在/usr/local/mysql目录下,所以要创建软链接
③将mysql目录下的所有文件的属组改为mysql

1
mysql]# chown -R root:mysql ./*




/usr/local/data目录是存放MySQL数据的地方,一般会单独放在一个存储上,以保证数据的安全性。这里建立一个单独的目录存放

1
2
]# mkdir -p /mydata/data
]# chown mysql:mysql /mydata/data/ -R




④初始化MySQL数据库
只能在mysql目录下运这个脚本,不能切换至scripts

1
]#scripts/mysql_install_db --datadir=/mydata/data --user=mysql




⑤需要给服务器一个配置文件

1
]#cp support-files/my-large.cnf /etc/my.cnf




如果目录下有文件,放到 /etc/my.cnf.d/下面也行


1
2
3
4
5
]# vi /etc/my.cnf
thread_concurrency = 2   #这项改为CPU核心数X2
datadir=/mydata/data
skip_name_resolve = ON
innodb_file_per_table = ON




PS:lscpu 查看CPU核心数
⑥生成启动脚本及系统服务

1
2
3
4
5
6
7
8
9
]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
]# chmod +x /etc/rc.d/init.d/mysqld
]# chkconfig --add mysqld
]# chkconfig --list mysqld
]# service mysqld start
]# ss –tnl         #查看306端口已经在监听状态
]# vi /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
]# . /etc/profile.d/mysql.sh




OK!到这里已经安装完成了,剩下的都是后续的配置了,下面安装httpd





二、编译安装httpd
①开发环境设置


1
2
]#yum groupinstall "Development Tools"#中文名字叫 开发工具,中文显示的童鞋安装这个
]#yum install -y pcre-devel openssl-devel libevent-devel apr-devel apr-util-devel




②编译安装httpd-2.4.10

1
2
~]# tar xf httpd-2.4.10.tar.bz2
]# ./configure --prefix=/usr/local/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





1
2
3
4
5
]# make&make install
]# vi /etc/profile.d/apache.sh
]# . /etc/profile.d/apache.sh
]# apachectl start
]# ss –tnl




http也安装完成了,下面安装PHP





三、安装PHP


1
2
3
~]# yum install -y gd-develfreetype-devel libmcrypt-devel libxml2-devel
~]# tar xf php-5.4.40.tar.bz2
./configure--prefix=/usr/local/php --with-mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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/apache2/bin/apxs --with-config-file-path=/etc/php.ini--with-config-file-scan-dir=/etc/php.d/




PS:由于我上面是编译安装的MySQL,所以我的--with-mysqli是上面个这个路径,如果是yum安装的可能是:/usr/bin/mysql_config,如果不知道就用这个命令:

1
]#which mysql_config





PS:--with-apxs2后面的路径是apxs的,用下面命令查看:

1
~]# which apxs





1
2
3
~]# maek&make install
# cp php.ini-production /etc/php.ini    #手动创建配置文件
]# mkdir /etc/php.d      #辅助配置文件的目录





PHP已经安装完成了,要想http支持PHP格式的主页,得编辑配置文件
]#vi /etc/httpd/httpd.conf

1
2
3
4
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
AddType application/x-httpd-php .php 查找关键字‘AddType’并添加




测试
重启服务并添加PHP主页文件

1
2
3
4
5
6
7
8
9
~]# apachectl stop
~]# apachectl start
~]# cd /usr/local/apache2/htdocs/
]# mv index.html index.php
]# vi index.php
<html><body><h1>It works!</h1></body></html>
<?php
      phpinfo();
?>






注意:如果要以fpm方式运行PHP,需要编译时移除--with-apxs选项,额外添加--enable-fpm选项







页: [1]
查看完整版本: 编译安装lamp