操做環境:CentOS 7.2php
LAMP即Linux Apache Mariadb phphtml
1、普通的yum安裝構建mysql
yum install mariadb-server httpd php php-mysqllinux
[root@localhost ~]# yum install httpd php php-mysql mariadb-server Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package httpd-2.4.6-40.el7.centos.x86_64 already installed and latest version Package php-5.4.16-36.el7_1.x86_64 already installed and latest version Package php-mysql-5.4.16-36.el7_1.x86_64 already installed and latest version Package 1:mariadb-server-5.5.44-2.el7.centos.x86_64 already installed and latest version Nothing to do [root@localhost ~]#
給mariadb添加額外配置/etc/my.cnfsql
設置mariadb的root用戶密碼數據庫
#首先啓動mysql服務 [root@localhost ~]# systemctl start mariadb #鍵入mysql_secure_installation,更改密碼 [root@localhost ~]# mysql_secure_installation /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):
編輯網頁測試文件apache
[root@localhost ~]# cat /var/www/html/phpinfo.php <?php phpinfo(); ?> [root@localhost ~]# cat /var/www/html/php-mysql.php <?php $conn = mysql_connect('127.0.0.1','root','xiaoshui'); if($conn) echo 'success'; else echo 'failure'; ?> [root@localhost ~]#
重啓httpd服務而後測試centos
關閉數據庫再次測試bash
[root@localhost ~]# systemctl stop mariadb [root@localhost ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* [root@localhost ~]# #3306端口關閉
(1)操做環境:
CentOS 7:httpd-2.4, mariadb, php-5.4
安裝次序:httpd, mariadb, php
(2) 開發環境:
Development Tools, Server Platform Development
(3)包版本
mariadb:ariadb-5.5.46-linux-x86_64.tar.gz
httpd:httpd-2.4.10.tar.bz2
php:php-5.4.40.tar.bz2
安裝MariaDB:(通用二進制格式的程序包)
將壓縮包展開至/usr/local下,並建立連接mysql
[root@localhost ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/ [root@localhost ~]# cd /usr/local/ [root@localhost local]# ls bin etc games include lib lib64 libexec mariadb-5.5.46-linux-x86_64 sbin share src [root@localhost local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql ‘mysql’ -> ‘mariadb-5.5.46-linux-x86_64’ [root@localhost local]# ls bin etc games include lib lib64 libexec mariadb-5.5.46-linux-x86_64 mysql sbin share sr
查看是否有mysql用戶和mysql組,若是沒有,則添加
[root@localhost local]# id mysql uid=27(mysql) gid=27(mysql) groups=27(mysql)
建立mysql的數據目錄並更改屬組屬主
[root@localhost local]# mkdir /mydata/data -pv mkdir: created directory ‘/mydata’ mkdir: created directory ‘/mydata/data’ [root@localhost local]# chown -R mysql.mysql /mydata/data/
更改mysql的安裝目錄中文件的屬組,改成mysql
[root@localhost mysql]# chown -R root:mysql ./* [root@localhost mysql]# ll total 204 drwxr-xr-x 2 root mysql 4096 Oct 16 15:03 bin -rw-r--r-- 1 root mysql 17987 Oct 10 2015 COPYING -rw-r--r-- 1 root mysql 26545 Oct 10 2015 COPYING.LESSER drwxr-xr-x 3 root mysql 17 Oct 16 15:03 data -rw-r--r-- 1 root mysql 8245 Oct 10 2015 EXCEPTIONS-CLIENT drwxr-xr-x 3 root mysql 18 Oct 16 15:03 include -rw-r--r-- 1 root mysql 8694 Oct 10 2015 INSTALL-BINARY drwxr-xr-x 3 root mysql 4096 Oct 16 15:03 lib drwxr-xr-x 4 root mysql 28 Oct 16 15:03 man drwxr-xr-x 11 root mysql 4096 Oct 16 15:03 mysql-test -rw-r--r-- 1 root mysql 108813 Oct 10 2015 README drwxr-xr-x 2 root mysql 29 Oct 16 15:03 scripts drwxr-xr-x 27 root mysql 4096 Oct 16 15:03 share drwxr-xr-x 4 root mysql 4096 Oct 16 15:03 sql-bench drwxr-xr-x 3 root mysql 4096 Oct 16 15:03 support-files
安裝msyql並添加選項
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data --skip_name_resolve Installing MariaDB/MySQL system tables in '/mydata/data' ... 161016 15:18:52 [Note] ./bin/mysqld (mysqld 5.5.46-MariaDB) starting as process 1489 ... OK Filling help tables... 161016 15:18:52 [Note] ./bin/mysqld (mysqld 5.5.46-MariaDB) starting as process 1497 ... OK To start mysqld at boot time you have to copy .......省略...... The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Support MariaDB development by buying support/new features from MariaDB Corporation Ab. You can contact us about this at sales@mariadb.com. Alternatively consider joining our community based development effort: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
複製樣例配置文件,並作以下修改
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost mysql]# ls /etc/rc.d/init.d/mysqld /etc/rc.d/init.d/mysqld chkconfig --add mysqld
將編譯文件中的bin目錄整合至PATH
[root@localhost php-5.4.40]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
更改mysql的默認root密碼爲xiaoshui
root@localhost php-5.4.40]# mysql_secure_installation /usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none):
啓動服務
[root@localhost mysql]# service mysqld start Starting MySQL... [ OK ]
編譯安裝httpd
安裝好以下的開發包
[root@localhost ~]# yum install pcre-devel openssl-devel libevent-devel apr-devel apr-util-devel -y
解壓httpd源碼包並cd至解壓的目錄
[root@localhost ~]# tar xf httpd-2.4.10.tar.bz2 [root@localhost ~]# cd httpd-2.4.10/ [root@localhost httpd-2.4.10]#
配置相應的編譯選項生成makefile文件以下
#安裝目錄在/usr/local/apache2,配置文件所在目錄爲/etc/httpd等等其餘的選項 [root@localhost httpd-2.4.10]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-pcre --with-zlib --with-apr=/usr --with-apr-util=/usr
執行make和make install
[root@localhost httpd-2.4.10]# make && make install
添加編譯的bin目錄至環境變量,而後重讀配置文件啓動服務
[root@localhost httpd-2.4.10]# echo "export PATH=/usr/local/apache2/bin:$PATH" > /etc/profile.d/httpd.sh [root@localhost httpd-2.4.10]# . /etc/profile.d/httpd.sh [root@localhost httpd-2.4.10]# apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message [root@localhost httpd-2.4.10]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* #80端口成功開啓!
編譯安裝php5:
安裝以下開發包
[root@localhost ~]# yum install gd-devel freetype-devel libxml2-devel libmcrypt-devel
解壓php源碼包
[root@localhost ~]# tar xf php-5.4.40.tar.bz2
編譯安裝生成makefile文件
[root@localhost php-5.4.40]# ./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-openssl --enable-mbstring --enable-xml --enable-sockets --with-freetype-dir --with-gd --with-libxml-dir=/usr --with-zlib --with-jpeg-dir --with-png-dir --with-mcrypt --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php.ini --with-config-file-scan-dir=/etc/php.d/
執行make && make install
[root@localhost php-5.4.40]# make && make install ......省略... Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf You may want to add: /usr/local/php5/lib/php to your php.ini include_path /root/php-5.4.40/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin ln -s -f /usr/local/php5/bin/phar.phar /usr/local/php5/bin/phar Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
複製樣例文件至/etc/下作php的配置文件
[root@localhost php-5.4.40]# cp php.ini-production /etc/php.ini
提供網站測試頁(編譯安裝的網站根路徑默認在安裝目錄下的htdocs目錄下)
[root@localhost php-5.4.40]# cat /usr/local/apache2/htdocs/phpinfo.php <h1>Htdocs<h1> <?php phpinfo(); ?> [root@localhost php-5.4.40]# cat /usr/local/apache2/htdocs/php-mysql.php <h1>Htdocs<h1> <?php $conn = mysql_connect('127.0.0.1','root','xiaoshui'); if($conn) echo 'success'; else echo 'failure'; ?>
編譯php爲httpd的模塊後,編輯/etc/httpd/httpd.conf整合php至httpd:
重啓服務測試
關閉mysql服務再次測試
[root@localhost php-5.4.40]# service mysqld stop Shutting down MySQL.. [ OK ] [root@localhost php-5.4.40]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::*
編譯安裝中出現的問題:
若是出現了mcrypt.h錯誤,提示從新安裝,使用yum -y libmcrypt.devel安裝此開發包