軟件包鏈接:
http://pan.baidu.com/s/1mijn44g 密碼:abja
系統環境:centos 7
開發環境:Development tools、Server Platform Development
http+php的方式:PHP模塊化
個程序版本:
mariadb | mariadb-5.5.46-linux-x86_64.tar.gz |
http | httpd-2.4.10.tar.bz2 |
PHP | php-5.4.40.tar.bz2 |
一、編譯安裝mariadb
①創建MySQL用戶
~]#useradd -u 306 -r -s /sbin/nologin mysql
②將壓縮包展開至/usr/local/目錄下,並創建鏈接
~]#tar xvf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/ local]# ln -smariadb-5.5.46-linux-x86_64/ mysql
mariadb需要假設自己運行在/usr/local/mysql目錄下,所以要創建軟鏈接
③將mysql目錄下的所有文件的屬組改爲mysql
mysql]# chown -R root:mysql ./*
/usr/local/data目錄是存放MySQL數據的地方,一般會單獨放在一個存儲上,以保證數據的安全性。這裏建立一個單獨的目錄存放
]# mkdir -p /mydata/data ]# chown mysql:mysql /mydata/data/ -R
④初始化MySQL數據庫
只能在mysql目錄下運這個腳本,不能切換至scripts
]#scripts/mysql_install_db --datadir=/mydata/data --user=mysql
⑤需要給服務器一個配置文件
]#cp support-files/my-large.cnf /etc/my.cnf
如果目錄下有文件,放到 /etc/my.cnf.d/下面也行
]# vi /etc/my.cnf thread_concurrency = 2 #這項改爲CPU核心數X2 datadir=/mydata/data skip_name_resolve = ON innodb_file_per_table = ON
PS:lscpu 查看CPU核心數
⑥生成啓動腳本及系統服務
]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld ]# chmod +x /etc/rc.d/init.d/mysqld ]# chkconfig --add mysqld ]# chkconfig --list mysqld ]# service mysqld start ]# ss –tnl #查看306端口已經在監聽狀態 ]# vi /etc/profile.d/mysql.sh export PATH=/usr/local/mysql/bin:$PATH ]# . /etc/profile.d/mysql.sh
OK!到這裏已經安裝完成了,剩下的都是後續的配置了,下面安裝httpd
二、編譯安裝httpd
①開發環境設置
]#yum groupinstall "Development Tools" #中文名字叫 開發工具,中文顯示的童鞋安裝這個 ]#yum install -y pcre-devel openssl-devel libevent-devel apr-devel apr-util-devel
②編譯安裝httpd-2.4.10
~]# tar xf httpd-2.4.10.tar.bz2 ]# ./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 ]# vi /etc/profile.d/apache.sh ]# . /etc/profile.d/apache.sh ]# apachectl start ]# ss –tnl
http也安裝完成了,下面安裝PHP
三、安裝PHP
~]# yum install -y gd-develfreetype-devel libmcrypt-devel libxml2-devel ~]# tar xf php-5.4.40.tar.bz2 ./configure--prefix=/usr/local/php --with-mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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/
PS:由於我上面是編譯安裝的MySQL,所以我的--with-mysqli是上面個這個路徑,如果是yum安裝的可能是:/usr/bin/mysql_config,如果不知道就用這個命令:
]#which mysql_config
PS:--with-apxs2後面的路徑是apxs的,用下面命令查看:
~]# which apxs
~]# maek&make install [root@s1 php-5.4.40]# cp php.ini-production /etc/php.ini #手動創建配置文件 ]# mkdir /etc/php.d #輔助配置文件的目錄
PHP已經安裝完成了,要想http支持PHP格式的主頁,得編輯配置文件
]#vi /etc/httpd/httpd.conf
<IfModule dir_module> DirectoryIndex index.php index.html </IfModule> AddType application/x-httpd-php .php 查找關鍵字‘AddType’並添加
測試
重啓服務並添加PHP主頁文件
~]# apachectl stop ~]# apachectl start ~]# cd /usr/local/apache2/htdocs/ ]# mv index.html index.php ]# vi index.php <html><body><h1>It works!</h1></body></html> <?php phpinfo(); ?>
注意:如果要以fpm方式運行PHP,需要編譯時移除--with-apxs選項,額外添加--enable-fpm選項