shell 安装lamp
自己vim 一個腳本
#!/bin/bash
#下載并安裝httpd
wget http://archive.apache.org/dist/httpd/httpd-2.2.9.tar.gz?
tar fvz httpd-2.2.9.tar.gz
cd httpd-2.2.9
./configure --with-mpm=prefork --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atormics --enable-mods-shared=most --enable-so
make && make instal
#修改httpd的html的目錄并啟動httpd
echo "<Directory /var/www/html>" >>/usr/local/apache2/conf/httpd.conf
echo "Options FollowSymLinks +Indexes" >>/usr/local/apache2/conf/httpd.conf
echo "AllowOverride None" >>/usr/local/apache2/conf/httpd.conf
echo "Order allow,deny" >>/usr/local/apache2/conf/httpd.conf
echo "allow from all" >>/usr/local/apache2/conf/httpd.conf
echo "</Directory>" >>/usr/local/apache2/conf/httpd.conf
sed -i '155s/usr\/local\/apache2\/htdocs/var\/www\/html/' /usr/local/apache2/conf/httpd.conf
mkdir /var/www/html -pv
/usr/local/apache2/bin/apachectl -k start
cd ..
?自定義apache啟動腳本!
#!/bin/bash
APACHE=/usr/local/apache2/bin/apachectl
start() {
??????? $APACHE -k start
}
stop() {
??????? $APACHE -k stop
}
restart() {
??????? $APACHE -k restart
}
case $1 in
start)
??????? start;;
stop)
??????? stop;;
restart)
??????? restart;;
*)
??????? echo "start|stop|restart"
??????? ;;
esac
chmod +x /etc/init.d/apache
#下載和安裝mysql
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.50.tar.gz
tar -xzf mysql-5.1.50.tar.gz
cd mysql-5.1.508.tar.gz
#添加用戶mysql
groupadd mysql
useradd -g mysql mysql
yum install gcc gcc-c++ ncurses-devel libtool openssl-devel -y
./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
make && make install
#將mysql的lib文件加載到系統變量中
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
#刷新
ldconfig
chown -R mysql.mysql /usr/local/mysql/
cp /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf
sed -i -r '27a datadir\t\t\= /usr/local/mysql/data' /etc/my.cnf
sed -i '40s/^/#/' /etc/my.cnf
mkdir -pv /usr/local/mysql/data
chown mysql.mysql /usr/local/mysql/data
/usr/local/mysql/bin/mysql_install_db --user=mysql
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
chkconfig mysqld on
export PATH=$PATH:/usr/local/mysql/bin
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
cd..
#下載安裝php
wget http://jp2.php.net/get/php-5.3.19.tar.bz2/from/au1.php.net/mirror
yum install libxml2-devel curl-devel libpng-devel freetype-devel libjpeg-devel -y
tar -jxf php-5.3.19.tar.bz2
cd php-5.3.19
./configure --prefix=/usr/local/php5 --enable-mbstring --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
make && make install
#添加默認頁index.php 以便httpd服務器可以正確的搜索該文件首頁
sed -i "217s/$/ index.php/" /usr/local/apache2/conf/httpd.conf
sed -i "218a AddType application/x-httpd-php .php" /usr/local/apache2/conf/httpd.conf
cp /root/lamp/php-5.3.19/php.ini-dist /usr/local/php5/php.ini
/usr/local/apache2/bin/apachectl -k stop
/usr/local/apache2/bin/apachectl -k start
記得要改權限
測試
echo "<? phpinfo() ?>" >/var/www/html/index.php
lamp驗證連接數據庫
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
??????? {
??????? die('Could not connect:' . mysql_error());
??????? }
mysql_select_db("ab", $con);
$result = mysql_query("SELECT * FROM persons");
while($row = mysql_fetch_array($result))
??????? {
??????? echo $row['name'] . " " . $row['city'];
??????? echo "<br />";
??????? }
mysql_close($con);
?>
轉載于:https://blog.51cto.com/zhangshujian/1074221
總結
以上是生活随笔為你收集整理的shell 安装lamp的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 优教卡教师版在哪里有?
- 下一篇: MongoDB replSet