LAMP安装步骤(操作系统CentOS6)

LAMP安装步骤(操作系统CentOS6,apache 2.4.37,mariadb5.5.62,php5.5.6)
一、准备阶段
1.系统初始环境设置
sed -i 's#HOSTNAME=CentOS6_Template#HOSTNAME=CentOS6_LAMP#g' /etc/sysconfig/network
hostname CentOS6_LAMP
sed -i "s#192.168.1.1#61.147.37.1#g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s#10.0.0.254#10.0.0.168#g" /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i "s#172.16.1.254#172.16.1.168#g" /etc/sysconfig/network-scripts/ifcfg-eth1

2.安装相关组件依赖包
yum groupinstall "Development tools" "Server Platform Development" -y
yum install autoconf patch m4 bison bzip2-devel pam-devel gmp-devel libicu-devel curl-devel pcre-devel libtool-libs libtool-ltdl-devel libwebp-devel libXpm-devel libvpx-devel libjpeg-devel libpng-devel freetype-devel oniguruma-devel aspell-devel enchant-devel readline-devel unixODBC-devel libtidy-devel openldap-devel libxslt-devel net-snmp net-snmp-devel zlib-devel openssl-devel libxml2-devel lynx expat-devel lua-devel lua jansson-devel pcre-devel ncurses-devel cmake m4 bison libaio libaio-devel numactl-devel yum-utils gcc gcc-c++ make wget perl curl bzip2 readline readline-devel net-tools python-devel ca-certificates epel-release ntpdate crontabs vim lrzsz php-mcrypt libmcrypt libmcrypt-devel libxml2 libxml2-devel -y

二、编译安装apache2.4.37
1.下载apache程序包以及相关依赖包
wget http://archive.apache.org/dist/httpd/httpd-2.4.37.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
wget http://archive.apache.org/dist/apr/apr-1.6.5.tar.gz
2.分别解压apr以及apr-util包,并编译安装至/usr/local
tar zxf apr-1.5.0.tar.gz
cd apr-1.5.0/
./configure --prefix=/usr/local/apr
make -j8 && make install
cd ..
tar zxf apr-util-1.5.1.tar.gz
cd apr-util-1.5.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make -j8 && make install
3.解压并编译安装httpd包,注意相关编译选项
tar zxf httpd-2.4.37.tar.gz
cd httpd-2.4.37/
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-z --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make -j8 && make install

4.安装后设置环境变量以及设置并启动服务
echo "export PATH=/usr/local/mysql/bin:/usr/local/apache/bin:$PATH" >/etc/profile.d/lamp.sh
. /etc/profile.d/lamp.sh
cp httpd /etc/rc.d/init.d/httpd
sed -ir '/CONFFILE/d;73a\tCONFFILE=/etc/httpd24/httpd.conf' /etc/rc.d/init.d/httpd
sed -i "203aServerName localhost:80" /etc/httpd24/httpd.conf
chkconfig --add httpd
service start httpd
ss -tnl|grep :80

三、下载mariadb并编译安装
1.下载并解压mariadb程序包(这里以版本5.5.62为例)
wget https://downloads.mariadb.org/interstitial/mariadb-5.5.62/bintar-linux-x86_64/mariadb-5.5.62-linux-x86_64.tar.gz
tar zxf mariadb-5.5.62-linux-x86_64.tar.gz -C /usr/local/
2.添加mysql用户与用户组
groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 mysql
id mysql
3.设置mysql文件夹权限以及生成初始数据库文件
cd /usr/local/
ln -s /usr/local/mariadb-5.5.62-linux-x86_64/ mysql
cd mysql
chown -R root.mysql ./*
mkdir /mydata
cd /mydata/
mkdir data/
chown mysql.mysql /mydata/data
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
chown mysql.mysql /mydata/data
4.生成mysql主配置文件以及生成服务脚本并启动服务
mkdir /etc/mysql -p
cp support-files/my-large.cnf /etc/mysql/my.cnf
sed -i '41a datadir = /mydata/data\ninnodb_file_per_table = on\nskip_name_resolve = on' /etc/mysql/my.cnf
touch /var/log/mysqld.log
chown mysql.mysql /var/log/mysqld.log
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
service mysqld start
ss -tnl|grep :3306

四、编译安装php
1.下载并解压php程序包(这里以版本5.5.6为例)
wget http://museum.php.net/php5/php-5.5.6.tar.gz
tar zxf php-5.5.6.tar.gz

2.编译安装php程序,注意相关编译选项
cd php-5.5.6/
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
make -j8 && make install

3.配置apache相应配置文件,并重启apache服务
sed -i 's#DirectoryIndex index.html#DirectoryIndex index.php index.html#g' /etc/httpd24/httpd.conf
sed -i '401aAddType application/x-httpd-php .php\nAddType application/x-httpd-php-source .phps' /etc/httpd24/httpd.conf
service httpd restart
httpd -M|grep php5

4.lamp安装完成后测试客户端访问
cd /usr/local/apache/htdocs/
mv index.html index.php
vim index.php
<?php
$conn=mysql_connect('127.0.0.1','root','');
if($conn)
echo "ok";
else
echo "failure";
mysql_close();
phpinfo();
?>
http://172.16.1.168/index.php(服务器ip地址)

猜你喜欢

转载自blog.51cto.com/9447803/2336973