Cent OS 6.6 下安裝mysql(5.5.20)和 PHP(5.3.10)

來源:互聯網
上載者:User

標籤:

0.準備步驟(沒有串連網路的 linux):

掛載光碟片、讓網路 yum 源失效、修改光碟片 yum 檔案、安裝 c 語言編譯器 gcc。

  

1.MySQL(5.5.20)

下載 mysql 5.5.20 源碼包(由於mysql 官網使用 google cdn 的 jquery 來切換mysql 版本下載的下拉式功能表,所以牆內無法擷取linux 版本的mysql,這裡在 51cto 上下載了一個源碼包)

把源碼包 mysql-5.5.20.tar.gz 放到 /root 目錄下

① 增加組和使用者

首先查看是否有mysql 使用者:

id mysql

如果沒有,增加組和使用者:

groupadd mysql
useradd -g mysql mysql

查看使用者

id mysql

此時應該會有mysql 使用者

 

② 解壓縮

tar -zxvf mysql-5.5.20.tar.gz

安裝完之後可以查看 mysql 解壓以後的大小

du -sh mysql-5.5.20

顯示 205M

 

③ 進入 mysql -5.5.20 目錄(編譯和編譯安裝都需要在源碼包解壓後的目錄中進行)

cd mysql-5.5.20

 

④ 定義安裝位置

先建立 /usr/local/mysql

mkdir /usr/local/mysql

然後軟體配置與檢查,定義安裝位置

注意:這一步 mysql 5.5(以上) 的版本源碼安裝使用 cmake 代替原來的 configure 命令。

先安裝 cmake:

yum -y install cmake

運行 cmake

(此步可以參考mysql 官方網站:2.9 Installing MySQL from Source ---- 2.9.2 Installing MySQL Using a Standard Source Distribution )

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_DATADIR=/data/mysql/mysql -DMYSQL_USER=mysql

或者

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/mysql -DMYSQL_USER=mysql

 

安裝過程中可能會報錯,比如:

報錯1:

CMake Error at /usr/share/cmake/Modules/CMakeCXXInformation.cmake:37 (get_filename_component):  get_filename_component called with incorrect number of argumentsCall Stack (most recent call first):  CMakeLists.txt:3 (PROJECT)

  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  CMake Error: Internal CMake error, TryCompile configure of cmake failed

解決方案:安裝 gcc-c++

yum -y install gcc-c++

 

報錯2:

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.

解決方案:

a.安裝 ncurses-devel

yum -y install ncurses-devel

b.刪除CMakeCache.txt

rm CMakeCache.txt

 

⑤ make && make install

make && make install

 過程比較漫長。

安裝完成之後,查看 /usr/local/mysql

ls /usr/local/mysql

 

⑥ 改變/usr/local/mysql 目錄的許可權

 

把 mysql 檔案夾的所有者改為mysql 組的使用者 mysql

cd /usr/localchown -R mysql:mysql mysql

 

⑦ 設定開機啟動

cd /root/mysql-5.5.20cp support-files/mysql.server /etc/init.d/mysqldchmod +x /etc/init.d/mysqld ll /etc/init.d/mysqld 
chkconfig --add mysqld
chkconfig mysqld on

此時就可以使用 servers mysqld start 來啟動 mysql

 

⑧ 初始化 mysql 的預設的資料庫

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/  --user=mysql 

 

⑨ 啟動 mysql

service mysqld start

解決方案:

 cp cp /root/mysql-5.5.20/support-files/my-medium.cnf /etc/my.cnf

y 覆蓋

vim /etc/my.cnf

插入 datadir = /usr/local/mysql/data

 

再插入:

log-error = /usr/local/mysql/data/error.logpid-file = /usr/local/mysql/data/mysql.piduser = mysqltmpdir = /tmp

儲存。

如果還是不行的話,參考 http://houzhiqingjava.blog.163.com/blog/static/1673995072014395417615/

[[email protected] ~]# cd /usr/local/mysql[[email protected] mysql]# chown -R mysql.mysql .[[email protected] mysql]# su - mysql[[email protected] ~]$ cd /usr/local/mysql[[email protected] mysql]$ scripts/mysql_install_dbInstalling MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:./bin/mysqladmin -u root password ‘new-password‘./bin/mysqladmin -u root -h localhost.localdomain password ‘new-password‘Alternatively you can run:./bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd . ; ./bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd ./mysql-test ; perl mysql-test-run.plPlease report any problems with the ./bin/mysqlbug script![[email protected] mysql]$ /usr/local/mysql/bin/mysqld_safe --user=mysql &[1] 11767[[email protected] mysql]$ 120502 07:01:17 mysqld_safe Logging to ‘/usr/local/mysql/data/localhost.localdomain.err‘.120502 07:01:17 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

敲斷行符號,再次啟動 mysql

service mysqld start

錯誤原因是:沒有初始化許可權表。

 

⑩ 登入 mysql

如果報錯:

原因:mysql命令的路徑在 /usr/local/mysql/bin 下,所以你直接使用mysql命令時,無法查到該命令
解決方案:在/usr/bin 下做一個軟連結,指向真實的命令

ln -s /usr/local/mysql/bin/mysql /usr/bin

測試:

select host,user,password from mysql.user;

給root 設定密碼 123456

/usr/local/mysql/bin/mysqladmin -uroot -p password ‘123456‘

使用 \s 查看資料庫資訊

 

停止mysql:

service mysqld stop

重啟mysql:

service mysqld restart

 

 

2.PHP 5.3.10

① 準備工作(可以參考CentOS 6.3下源碼安裝LAMP(Linux+Apache+Mysql+Php)環境)

a. 安裝 libxml2 2.2.26(php 處理 xml 文檔)

把 libxml2.tar.gz 複製到 /root 目錄下

tar -zxvf libxml2-2.2.26.tar.gzcd libxml2-2.2.26./configure --prefix=/usr/local/libxml2make && make install

 

b.安裝 jpeg6

把 jpegsrc.v6b.tar.gz 複製到 /root 目錄下

解壓:

tar -zxvf jpeg6.v6b.tar.gz

 

#手動建立以下目錄mkdir -p /usr/local/jpeg6mkdir -p /usr/local/jpeg6/binmkdir -p /usr/local/jpeg6/libmkdir -p /usr/local/jpeg6/includemkdir -p /usr/local/jpeg6/manmkdir -p /usr/local/jpeg6/man1mkdir -p /usr/local/jpeg6/man/man1

cd jpeg-6b
./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
make && make install

 

c.安裝 zlib-1.2.5.1

把zlib-1.2.5.1.tar.gz 複製到 /root 下

tar -zxvf zlib-1.2.5.1cd zlib.1.2.5.1./configure     #不指定任何目錄make && make install

 

d.安裝 libpng 1.2.31

把libpng-1.2.31.tar.gz 複製到 /root 下

tar -zxvf libpng-1.2.31.tar.gz
cd libpng-1.2.31
./configure #和zlib 一樣不要帶參數,讓它預設安裝到相應目錄

make && make install

 

 e. 安裝 freetype 2.4.11 字型庫

 把 freetype-2.4.11.tar.gz 複製到 /root 下

tar -zxvf freetype-2.4.11.tar.gzcd freetype-2.4.11mkdir -p /usr/local/freetype./configure --prefix=/usr/local/freetypemake && make install

 

f.安裝 gd 2.0.35 圖形庫

把 gd-2.0.35.tar.gz 複製到 /root

tar -zxvf gd-2.0.35.tar.gzmkdir -p /usr/local/gdcd gd-2.0.35./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg6 --with-png --with-zlib --with-freetype=/usr/local/freetypemake && make install

 

 ok,準備工作完成,該裝php 了。

 

把 php-5.3.10.tar.gz 複製到 /root 下

② 解壓:

tar -zxvf php-5.3.10
cd php-5.3.10

解壓之後大小 127 M

 

③ 軟體配置與檢查,定義安裝位置

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd --with-zlib --with-libxml-dir=/usr/local/libxml2 --with-jpeg-dir=/usr/local/jpeg6 --with-png-dir --enable-mbstring=all --enable-mbregex --enable-shared

 

④ 編譯 並且 安裝

make && make install

過程很漫長。

 

⑤ 複製一份 php.ini 檔案

使用:ls |gerp ini查看跟php.ini 有關的資訊

然後copy:

cp php.ini-development /usr/local/php/lib/php.ini

或者 複製 php.ini-production (生產環境)

 

⑥ 整合 apache 和 php

進入apache 的安裝目錄

cd /usr/local/apache2

編輯:

vi conf/httpd.conf

使用 /php 尋找和 php 相關的資訊。

使用:set nu 顯示行數。

166 行

<ifModule dir_modle>       DirectoryIndex index.html</ifModule>

在 index.html 前加上 index.php

 使用 /AddType

310 行添加:

AddType application/x-httpd-php .php

儲存。

重啟 apache

bin/apachectl restart

 

進入:

cd htdocs/

編輯:

vi index.php

輸入:

<?phpphpinfo();

儲存。

重啟apache

/usr/local/apache2/bin/apachectl restart

在瀏覽器中輸入 192.168.254.100

設定時區:

vi /usr/local/php/lib/php.ini

1008 行

data.timezone = PRC

重啟 apache。

 

php 安裝配置完成。

網站檔案放在 /usr/local/apache2/htdocs ,目錄下

建立虛擬機器主機:

cd /usr/local/apache2/confvi httpd.conf

搜尋 vhosts

大約 389 行

把Virtual hosts 下面一行的 # 去掉

儲存。

 

然後

vi extra/httpd-vhosts.conf

虛擬機器主機部分修改成:

重啟apache。

修改本地主機的hosts,加入 

192.168.254.100 test.com

在瀏覽器中輸入 test.com,就可以瀏覽網站了。

  

參考:

linux下Apache+PHP+mysql+phpMyAdmin源碼包安裝配置(Ubuntu)

使用cmake方式安裝mysql-5.5.10(mysql cmake)

CentOS 6.2 源碼安裝MySQL5.5.11(解決mysql cmake 報錯)

MySQL: Starting MySQL….. ERROR! The server quit without updating PID file解決辦法( 解決mysql 無法啟動)

 

CentOS 6.3下源碼安裝LAMP(Linux+Apache+Mysql+Php)環境

CentOs5.5+mysql+nginx+php5.3.3安全安裝手冊

 

常用源碼包

常用源碼包2

Cent OS 6.6 下安裝mysql(5.5.20)和 PHP(5.3.10)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.