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地址)