Ubuntu搭建LAMP
環境及安裝包描述:
系統版本:ubuntu 12.0.4-server-amd
所需包:
cmake-2.8.6.tar.gz
libmcrypt-2.5.7.tar.gz
mysql-5.5.25.tar.gz
apr-1.4.6.tar.gz
apr-util-1.4.1.tar.gz
pcre-8.21.tar.gz
httpd-2.4.2.tar.bz2
php-5.4.4.tar.gz
libxml2-dev
libncurses5-dev
注:libxml2-dev和libncurses5-dev為安裝所需的依賴包,所佔空間較小,建議官網下載安裝。
本地源安裝gcc和g++
配置本地源:
載入映象並掛載
(伺服器如果沒有光碟機,可以把系統映象檔案上傳到伺服器,然後透過下面的命令掛載映象檔案掛載方式:
mount -o loop -t iso9660 /home/ubuntu-12.04.2-server-amd64.iso /media/cdrom )
root@localhost:~# mount /dev/cdrom /media/cdrom
配置原始檔
cp /etc/apt/sources.list /etc/apt/sources.listbak
nano /etc/apt/sources.list
刪除所有內容 新增一行下列內容:
deb file:///media/cdrom precise main
更新源:
root@localhost:/media/cdrom/dists/precise/main# apt-get update
Ign file: precise InRelease
Get:1 file: precise Release.gpg [198 B]
Get:2 file: precise Release [4,595 B]
Ign file: precise/main TranslationIndex
Ign file: precise/main Translation-en_US
Ign file: precise/main Translation-en
Reading package lists... Done
以上是配置本地源,如若需遠端安裝,將/etc/apt/sources.listbak複製至原位置即可
安裝gcc:
root@localhost:/media/cdrom/dists/precise/main# apt-get install gcc
Reading package lists... Done
。
。
。
檢視gcc版本,驗證安裝是否成功:
root@localhost:/media/cdrom/dists/precise/main# gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
安裝g++
root@localhost:~# apt-get install g++
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
g++-4.6 libstdc++6-4.6-dev
Suggested packages:
g++-multilib g++-4.6-multilib gcc-4.6-doc libstdc++6-4.6-dbg
libstdc++6-4.6-doc
.
.
.
安裝make
root@localhost:~/cmake-2.8.6# apt-get install make
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
make-doc
The following NEW packages will be installed:
make
.
.
.
安裝cmake編譯工具
[root@orcl10g LAMP]# tar zxvf cmake-2.8.6.tar.gz
[root@orcl10g LAMP]# cd cmake-2.8.6
[root@orcl10g cmake-2.8.6]# ./configure
[root@orcl10g cmake-2.8.6]# make
[root@orcl10g cmake-2.8.6]# make install
檢視cmake是否安裝成功
root@localhost:~/cmake-2.8.6# which cmake
/usr/local/bin/cmake
安裝libmcrypt-2.5.7
root@localhost:~# tar zxvf libmcrypt-2.5.7.tar.gz
[root@orcl10g LAMP]# cd libmcrypt-2.5.7
[root@orcl10g libmcrypt-2.5.7]# ./configure
編譯:
[root@orcl10g libmcrypt-2.5.7]# make
安裝:
[root@orcl10g libmcrypt-2.5.7]# make install
安裝libncurses5-dev
本地源沒有該包,這個包不大,需聯網安裝,RedHat 的包名為ncurses-devel
root@localhost:~# cd /etc/apt/
root@localhost:/etc/apt# mv sources.list sources.list_bak2
root@localhost:/etc/apt# cp sources.listbak sources.list
root@localhost:/etc/apt# apt-get update
root@localhost:/etc/apt# apt-get install libncurses5-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libtinfo-dev
Suggested packages:
ncurses-doc
The following NEW packages will be installed:
libncurses5-dev libtinfo-dev
0 upgraded, 2 newly installed, 0 to remove and 194 not upgraded.
Need to get 325 kB of archives.
After this operation, 1,623 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main libtinfo-dev amd64 5.9-4 [103 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu/ precise/main libtinfo-dev amd64 5.9-4 [103 kB] 31% [2 libtinfo-dev 102 kB/103 kB 99%]
安裝mysql
新增mysql使用者組
[root@orcl10g LAMP]# groupadd mysql
建立mysql使用者,不允許其直接登入系統
[root@orcl10g LAMP]# useradd -g mysql -s /sbin/nologin mysql
建立mysql 的資料存放路徑並設定目錄許可權
[root@orcl10g mysql-5.5.25]# mkdir -p /mysql/data
[root@orcl10g mysql-5.5.25]# chown -R mysql:mysql /mysql/data
解壓安裝mysql
[root@orcl10g LAMP]# tar zxvf mysql-5.5.25.tar.gz
cmake配置使安裝路徑為/usr/local/mysql5字符集設定為all
[root@orcl10g mysql-5.5.25]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5 -DEXTRA_CHARSETS=all
如果上一步未安裝libncurses5-dev 會報如下錯誤,需安裝該包後刪除CMakeCache.txt重新執行該cmake命令
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:127 (FIND_CURSES)
cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:257 (MYSQL_CHECK_READLINE)
-- Configuring incomplete, errors occurred!
無報錯,進行編譯和安裝,效果如圖:
[root@orcl10g mysql-5.5.25]# make
[root@orcl10g mysql-5.5.25]# make install
配置mysql
[root@orcl10g mysql]# cp ./support-files/my-medium.cnf /etc/my.cnf
[root@orcl10g apache2]# vi /etc/my.cnf
新增資料存放路徑:
[mysqld]
新增
datadir = /mysql/data
[root@orcl10g apache2]# chown -R mysql:mysql /usr/lcoal/msyql5
生成測試資料庫:
root@localhost:~/mysql-5.5.25# cd /usr/local/mysql5/
root@localhost:/usr/local/mysql5# /usr/local/mysql5/scripts/mysql_install_db --user=mysql
啟動資料庫
[root@orcl10g mysql-5.5.25]# /usr/local/mysql5/bin/mysqld --user=mysql
新增root密碼
[root@orcl10g apache2]# /usr/local/mysql5/bin/mysqladmin -u root password 123456
登入測試
[root@orcl10g apache2]# /usr/local/mysql5/bin/mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.5.25-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
安裝配置apache2
安裝apr-1.4.6
[root@orcl10g LAMP]# tar zxvf apr-1.4.6.tar.gz
[root@orcl10g LAMP]# cd apr-1.4.6
[root@orcl10g apr-1.4.6]# ./configure --prefix=/usr/local/apr-httpd/
[root@orcl10g apr-1.4.6]# make
[root@orcl10g apr-1.4.6]# make install
安裝apr-util-1.4.1
[root@orcl10g apr-1.4.6]# cd ..
[root@orcl10g LAMP]# tar zxvf apr-util-1.4.1.tar.gz
[root@orcl10g LAMP]# cd apr-util-1.4.1
[root@orcl10g apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/
[root@orcl10g apr-1.4.6]# make
[root@orcl10g apr-1.4.6]# make install
安裝pcre
root@localhost:~# tar zxvf pcre-8.21.tar.gz
root@localhost:~# cd pcre-8.21/
root@localhost:~/pcre-8.21# ./configure
root@localhost:~/pcre-8.21# make
root@localhost:~/pcre-8.21# make install
root@localhost:/usr/local/lib# ln -s /usr/local/lib/libpcre.so.0 /lib
解壓安裝apache
[root@orcl10g LAMP]# tar ixvf httpd-2.4.2.tar.bz2
[root@orcl10g LAMP]# cd httpd-2.4.2
指定安裝路徑,並允許讀寫,指派剛安過的apr和apr-util路徑
[root@orcl10g httpd-2.4.2]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/
編譯
[root@orcl10g httpd-2.4.2]# make
安裝
[root@orcl10g httpd-2.4.2]# make install
[root@orcl10g httpd-2.4.2]# /usr/local/apache2/bin/apachectl start
如果報以下錯誤,需修改一下配置檔案:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
[root@orcl10g httpd-2.4.2]# vi /usr/local/apache2/conf/httpd.conf
加入ServerName
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName
ServerName localhost:80
再次啟動apache
[root@orcl10g httpd-2.4.2]# /usr/local/apache2/bin/apachectl start
[root@orcl10g httpd-2.4.2]# /usr/local/apache2/bin/apachectl start
httpd (pid 15249) already running
瀏覽器輸入檢視結果:
安裝php
安裝libxml2
注:仍然需聯網安裝
root@localhost:~# cd /etc/apt/
root@localhost:/etc/apt# cp sources.listbak sources.list
root@localhost:/etc/apt# apt-get update
root@localhost:/etc/apt# apt-get install libxml2-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libxml2
The following NEW packages will be installed:
libxml2-dev
The following packages will be upgraded:
libxml2
1 upgraded, 1 newly installed, 0 to remove and 195 not upgraded.
Need to get 1,478 kB of archives.
After this operation, 2,763 kB of additional disk space will be used.
Do you want to continue [Y/n]?Y
.
.
.
解壓安裝php
[root@orcl10g LAMP]# tar zxvf php-5.4.4.tar.gz
[root@orcl10g LAMP]# cd php-5.4.4
配置:
./configure --prefix=/usr/local/php5/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql5/ --enable-mbstring
編譯
[root@orcl10g php-5.4.4]#make
安裝
[root@orcl10g php-5.4.4]#make install
[root@orcl10g php-5.4.4]#make test
生成php.ini檔案
[root@orcl10g php-5.4.4]# cp -rf php.ini-development /usr/local/php5/php.ini
環境測試:
配置apache新增php
root@localhost:~# vi /usr/local/apache2/conf/httpd.conf
新增
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
效果如圖:
重啟apache2:
root@localhost:~# /usr/local/apache2/bin/apachectl stop
root@localhost:~# /usr/local/apache2/bin/apachectl start
[root@orcl10g ~]# cd /usr/local/apache2/htdocs/
輸入指標函式顯示php資訊
[root@orcl10g htdocs]# vi index.php
寫入內容如下:
phpinfo();
?>
篇尾:
環境的啟動/關閉:
啟動apache:
root@localhost:~# /usr/local/apache2/bin/apachectl start/stop
啟動資料庫
root@localhost:~# /usr/local/mysql5/bin/mysqld --user=mysql
php專案目錄:/usr/local/apache2/htdocs/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29320885/viewspace-1189568/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Ubuntu14.04搭建LAMPUbuntuLAMP
- Ubuntu16.04搭建LAMPUbuntuLAMP
- LAMP搭建示例LAMP
- Ubuntu14.04LAMP搭建(Apache2.47+MySQL5.5+PHP5.5)UbuntuLAMPApacheMySqlPHP
- ubuntu手動編譯lampUbuntu編譯LAMP
- php環境搭建---LAMPPHPLAMP
- Centos6.5搭建LAMPCentOSLAMP
- Centos7.2搭建LampCentOSLAMP
- centos7lamp搭建CentOSLAMP
- RedHat5.4搭建LAMPRedhatLAMP
- 搭建高效能LAMP架構:LAMP+FastCGI薦LAMP架構AST
- Centos下搭建LAMP+PHPCentOSLAMPPHP
- linux搭建lamp環境LinuxLAMP
- lamp 以及ucenter、phpBB、discuz! 搭建LAMPPHP
- ubuntu16.04 lamp https配置UbuntuLAMPHTTP
- ubuntu sever 倆個命令安裝 lampUbuntuLAMP
- Ubuntu22.04 LAMP快速實戰UbuntuLAMP
- 編譯搭建LAMP伺服器編譯LAMP伺服器
- LAMP環境搭建-MySQL5.6LAMPMySql
- 【轉】 Windows下LAMP環境搭建WindowsLAMP
- 在Ubuntu上安裝LAMP伺服器UbuntuLAMP伺服器
- ubuntu18搭建LAMP環境+部署圖片上傳網頁+安裝MosquittoUbuntuLAMP網頁UI
- LAMP(CentOS 7.2)環境下搭建WordPressLAMPCentOS
- CentOS 7.3搭建LAMP環境和WordpressCentOSLAMP
- linux中lamp的搭建(rpm)LinuxLAMP
- CentOS7.3 編譯搭建 lamp 環境CentOS編譯LAMP
- centos7.3搭建lamp實現使用wordpressCentOSLAMP
- Linux下原始碼搭建LAMP環境Linux原始碼LAMP
- 搭建LAMP中安裝PHP遇到的故障LAMPPHP
- CentOS6.7原始碼搭建LAMP平臺CentOS原始碼LAMP
- lamp環境搭建與phpwind,wordprss實現LAMPPHP
- CentOS7.0 LAMP環境搭建(MariaDB)CentOSLAMP
- Linux-LAMP平臺搭建詳解LinuxLAMP
- LAMP--原始碼MySQL叢集版搭建LAMP原始碼MySql
- LAMP-CentOS7搭建Web伺服器LAMPCentOSWeb伺服器
- 圖解 Ubuntu Server 16.04 LTS 上安裝 LAMP圖解UbuntuServerLAMP
- 搭建lamp環境以及安裝配置phpmyadminLAMPPHP
- Lamp(linux+apache+mysql+php)環境搭建LAMPLinuxApacheMySqlPHP