pache(httpd) + MySQL + PHP三個能夠在一臺機器上,也能夠分開,。可是Apache(httpd)和PHP是一隻都在一塊兒的。php
用戶瀏覽器————>Apache————>PHP ————>MySQLhtml
Apache讀取分爲動態文件和靜態文件。mysql
動態文件,存在MySQL。如密碼,帖子,linux
靜態文件,圖片等,存在linux服務器裏。web
讀取動態文件,須要經過PHP再到MySQL。sql
MySQL是一個關係型數據庫,由mysql ab公司開發,mysql在2008年被sun公司收購(10億刀),2009年sun公司被oracle 公司收購(74億刀)數據庫
MySQL官網https://www..com 最新版本5.7GA/8.0DMRapache
MySQL5.6變化較大,5.7性能上有很大提高windows
Mariadb 爲MySQL的一個分支,官網https://mariadb.com/最新版本10.3api
MariaDB主要由SkySQL公司(現改名爲MariaDB公司)維護,SkySQL公司由MySQL原做者帶領大部分原班人馬創立。
Mariadb5.5版本對應MySQL的5.5,10.0對應MySQL5.6
Community 社區版本,Enterprise 企業版,GA 指通用版本,在生產環境中用的,DMR開發里程碑發佈版,RC發行候選版本,Beta開放測試版本,Alpha內部測試版本
[root@aminglinux-01 ~]# cd /usr/local/src/ [root@aminglinux-01 src]# ls httpd-2.2.32 httpd-2.2.32.tar.gz [root@aminglinux-01 src]# [root@aminglinux-01 src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
地址在r.aminglinux.com找
tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@aminglinux-01 src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
[root@aminglinux-01 src]# cd /usr/local/mysql/ [root@aminglinux-01 mysql]# useradd mysql [root@aminglinux-01 mysql]# mkdir /data/ (若是目錄已經存在無需建立)
[root@aminglinux-01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper [root@aminglinux-01 mysql]#
提示缺乏Perl模塊
能夠百度或者google搜索問題。
或者搜索一下yum包:yum list |grep perl |grep -i dumper
[root@aminglinux-01 mysql]# yum list |grep perl |grep -i dumper perl-Data-Dumper.x86_64 2.145-3.el7 base perl-Data-Dumper-Concise.noarch 2.020-6.el7 epel perl-Data-Dumper-Names.noarch 0.03-17.el7 epel perl-XML-Dumper.noarch 0.81-17.el7 base [root@aminglinux-01 mysql]#
若是不肯定是哪一個包就都安裝上
其實是依賴這個包: perl-Data-Dumper.x86_64
而後再進行初始化,進行指定
root@bigdata-159:/usr/local/mysql# ./bin/mysqld -- defaults-file=/etc/my.cnf --initialize --user=mysql ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@example.com data]# yum install -y libaio //安裝後在初始化就OK了
繼續初始化
Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as ./my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server [root@aminglinux-01 mysql]#
能夠echo $?一下,若是是0 ,證實沒有問題。初始化成功
[root@aminglinux-01 mysql]# echo $? 0
配置文件在 support-files/
[root@aminglinux-01 mysql]# ls support-files/ binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server [root@aminglinux-01 mysql]#
模板配置文件: my-default.cnf
拷貝 默認配置文件就放到/etc/my.cnf
[root@aminglinux-01 mysql]# ls support-files/ binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server [root@aminglinux-01 mysql]# cp support-files/my-default.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"?
若是以前就有了,多是哪個rpm包在安裝時候生成的,能夠rpm -qf /etc/my.cnf查看一下是那個rpm包生成的。也可使用。可是須要改一下配置文件。
如下是自帶my.cnf文件的修改。
[root@aminglinux-01 mysql]# vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d ~ ~ ~ "/etc/my.cnf" 19L, 570C
改過以後
[mysqld] datadir=/data/mysql 改 socket=/tmp/mysql.sock 改 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] #log-error=/var/log/mariadb/mariadb.log 改 #pid-file=/var/run/mariadb/mariadb.pid 改 # # include all files from the config directory # #!includedir /etc/my.cnf.d 改 ~
須要copy [root@aminglinux-01 mysql]# cp support-files/mysql.server
[root@aminglinux-01 mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@aminglinux-01 mysql]#
而後進行編輯
[root@aminglinux-01 mysql]# vi /etc/init.d/mysqld
須要修改幾個地方。
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files. # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mysql 須要修改 datadir=/data/mysql 須要修改 # Default value, in seconds, afterwhich the script should timeout waiting # for server start. # Value here is overriden by value in my.cnf. # 0 means don't wait at all # Negative numbers mean to wait indefinitely service_startup_timeout=900
權限變動,755。默認也是755
[root@aminglinux-01 ~]# ls -l /etc/init.d/mysqld -rwxr-xr-x. 1 root root 10907 9月 27 09:42 /etc/init.d/mysqld [root@aminglinux-01 ~]#
加入系統服務裏
[root@aminglinux-01 ~]# chkconfig --add mysqld [root@aminglinux-01 ~]#
[root@aminglinux-01 ~]# chkconfig --list 注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。 若是您想列出 systemd 服務,請執行 'systemctl list-unit-files'。 欲查看對特定 target 啓用的服務請執行 'systemctl list-dependencies [target]'。 mysqld 0:關 1:關 2:開 3:開 4:開 5:開 6:關 netconsole 0:關 1:關 2:關 3:關 4:關 5:關 6:關 network 0:關 1:關 2:開 3:開 4:開 5:開 6:關 [root@aminglinux-01 ~]#
能夠手動起這個服務
[root@aminglinux-01 ~]# service mysqld start Starting MySQL.Logging to '/data/mysql/aminglinux-01.err'. .. SUCCESS! [root@aminglinux-01 ~]#
查看進程和端口
[root@aminglinux-01 ~]# ps aux |grep mysql root 2372 0.0 0.1 11760 1600 pts/0 S 09:52 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/aminglinux-01.pid mysql 2507 2.5 45.5 973048 455352 pts/0 Sl 09:52 0:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/aminglinux-01.err --pid-file=/data/mysql/aminglinux-01.pid --socket=/tmp/mysql.sock root 2536 0.0 0.0 112664 976 pts/0 R+ 09:54 0:00 grep --color=auto mysql [root@aminglinux-01 ~]#
[root@aminglinux-01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 910/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1212/master tcp6 0 0 :::3306 :::* LISTEN 2507/mysqld tcp6 0 0 :::22 :::* LISTEN 910/sshd tcp6 0 0 ::1:25 :::* LISTEN 1212/master [root@aminglinux-01 ~]#
若是啓動腳本有問題或者沒有啓動模板等還有另外一種啓動方法。/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[root@aminglinux-01 ~]# service mysqld stop Shutting down MySQL.. SUCCESS! [root@aminglinux-01 ~]# !ps ps aux |grep mysql root 2619 0.0 0.0 112664 976 pts/0 S+ 10:00 0:00 grep --color=auto mysql
[root@aminglinux-01 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &(&符號是把命令丟到後臺去) [1] 2648 [root@aminglinux-01 ~]# 170927 10:03:24 mysqld_safe Logging to '/data/mysql/aminglinux-01.err'. 170927 10:03:24 mysqld_safe Starting mysqld daemon with databases from /data/mysql [root@aminglinux-01 ~]# !ps ps aux |grep mysql root 2648 0.0 0.1 113256 1588 pts/0 S 10:03 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql mysql 2771 0.7 45.0 973048 450268 pts/0 Sl 10:03 0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/aminglinux-01.err --pid-file=/data/mysql/aminglinux-01.pid --socket=/tmp/mysql.sock root 2804 0.0 0.0 112664 976 pts/0 R+ 10:04 0:00 grep --color=auto mysql [root@aminglinux-01 ~]#
--defaults-file=/etc/my.cnf 指定配置文件所在目錄
命令行的開啓只能用kill來進行關閉服務,用killall更安全,否則會致使數據在內存中還沒寫到磁盤裏就殺掉了。killall 會先停掉,保存,而後殺掉。
[root@aminglinux-01 ~]# killall mysqld [root@aminglinux-01 ~]# 170927 10:36:39 mysqld_safe mysqld from pid file /data/mysql/aminglinux-01.pid ended [1]+ 完成 /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql [root@aminglinux-01 ~]# !ps ps aux |grep mysql root 3013 0.0 0.0 112664 972 pts/0 R+ 10:36 0:00 grep --color=auto mysql [root@aminglinux-01 ~]#
若是進程殺了一分鐘尚未殺掉,可能還在寫數據,要在等一下子。
[root@aminglinux-01 ~]# cd /usr/local/src [root@aminglinux-01 src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
httpd-2.2.32 mariadb-10.2.6-linux-glibc_214-x86_64 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz httpd-2.2.32.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz [root@aminglinux-01 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb [root@aminglinux-01 src]#
[root@aminglinux-01 mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb Installing MariaDB/MySQL system tables in '/data/mariadb' ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB 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 aminglinux-01 password 'new-password' Alternatively you can run: './bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '.' ; ./bin/mysqld_safe --datadir='/data/mariadb' You can test the MariaDB daemon with mysql-test-run.pl cd './mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira 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 Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ [root@aminglinux-01 mariadb]# echo $? 0 [root@aminglinux-01 mariadb]#
[root@aminglinux-01 mariadb]# cd /usr/local/mariadb/ [root@aminglinux-01 mariadb]# ls support-files/ binary-configure my-huge.cnf my-large.cnf my-small.cnf mysql-log-rotate policy wsrep_notify magic my-innodb-heavy-4G.cnf my-medium.cnf mysqld_multi.server mysql.server wsrep.cnf [root@aminglinux-01 mariadb]#
這裏面有好幾個配置模板,怕跟以前裝的mysql衝突,因此此次換個文件夾copy
[root@aminglinux-01 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf [root@aminglinux-01 mariadb]#
[root@aminglinux-01 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb [root@aminglinux-01 mariadb]#
修改配置文件和啓動腳本,配置文件修改的話,須要改mysqld, 基本上不用改。
啓動腳本,須要修改
# # If you want to affect other MySQL variables, you should make your changes # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files. # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mariadb 修改 datadir=/data/mariadb 修改 conf=$basedir/my.cnf 新加,新加後須要在下面啓動命令定義一下 # Default value, in seconds, afterwhich the script should timeout waiting # for server start. # Value here is overridden by value in my.cnf. # 0 means don't wait at all
case "$mode" in 'start') # Start daemon # Safeguard (relative paths, core dumps..) cd $basedir echo $echo_n "Starting MySQL" if test -x $bindir/mysqld_safe then # Give extra arguments to mysqld with the my.cnf file. This script # may be overwritten at next upgrade. $bindir/mysqld_safe (須要加的)--defaults-file=$conf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" & wait_for_ready; return_value=$? # Make lock for RedHat / SuSE if test -w "$lockdir"
定義conf是爲了避免跟以前安裝的mysql出現衝突,通常不會有mysql和mariadb同時安裝的狀況,若是隻有一個,能夠不用定義。直接把my.cnf 放到etc下
[root@aminglinux-01 ~]# /etc/init.d/mariadb start Starting mariadb (via systemctl): [ 肯定 ] [root@aminglinux-01 ~]# ps aux |grep mariadb root 2542 0.0 0.1 115380 1740 ? S 23:01 0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/aminglinux-01.pid mysql 2658 5.9 5.8 1125120 58608 ? Sl 23:01 0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/aminglinux-01.err --pid-file=/data/mysql/aminglinux-01.pid --socket=/tmp/mysql.sock --port=3306 root 2704 0.0 0.0 112664 972 pts/0 R+ 23:01 0:00 grep --color=auto mariadb [root@aminglinux-01 ~]#
#### Apache是一個基金會的名字,httpd纔是咱們要安裝的軟件包,早期它的名字就叫apache
2.4源碼包: http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
apr-util: http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.0.tar.bz2
apr和apr-util是一個通用的函數庫,它讓httpd 能夠不關心底層的操做系統平臺,能夠很方便的移植(從linux移植到windows)
[root@aminglinux-01 apr-1.6.2]# ./configure --prefix=/usr/local/apr
[root@aminglinux-01 apr-1.6.2]# make && make install
安裝下一個
[root@aminglinux-01 apr-1.6.2]# cd ../apr-util-1.6.0/ [root@aminglinux-01 apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@aminglinux-01 apr-util-1.6.0]# make && make install
出現報錯
xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個文件或目錄
可能缺expat的開發庫,yum install expat-devel解決
安裝httpd2.4
[root@aminglinux-01 httpd-2.4.27]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
出現報錯
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@aminglinux-01 httpd-2.4.27]# yum list |grep pcre pcre.x86_64 8.32-15.el7_2.1 @anaconda ghc-pcre-light.x86_64 0.4-13.el7 epel ghc-pcre-light-devel.x86_64 0.4-13.el7 epel mingw32-pcre.noarch 8.38-1.el7 epel mingw32-pcre-static.noarch 8.38-1.el7 epel mingw64-pcre.noarch 8.38-1.el7 epel mingw64-pcre-static.noarch 8.38-1.el7 epel pcre.i686 8.32-17.el7 base pcre.x86_64 8.32-17.el7 base pcre-devel.i686 8.32-17.el7 base pcre-devel.x86_64 8.32-17.el7 base pcre-static.i686 8.32-17.el7 base pcre-static.x86_64 8.32-17.el7 base pcre-tools.x86_64 8.32-17.el7 base pcre2.i686 10.23-2.el7 base pcre2.x86_64 10.23-2.el7 base pcre2-devel.i686 10.23-2.el7 base pcre2-devel.x86_64 10.23-2.el7 base pcre2-static.i686 10.23-2.el7 base pcre2-static.x86_64 10.23-2.el7 base pcre2-tools.x86_64 10.23-2.el7 base pcre2-utf16.i686 10.23-2.el7 base pcre2-utf16.x86_64 10.23-2.el7 base pcre2-utf32.i686 10.23-2.el7 base pcre2-utf32.x86_64 10.23-2.el7 base [root@aminglinux-01 httpd-2.4.27]#
一般運行庫都是-devel或-lib,因此安裝下pcre-devel.x86_64
[root@aminglinux-01 httpd-2.4.27]# yum -y install pcre-devel.x86_64
[root@aminglinux-01 httpd-2.4.27]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
[root@aminglinux-01 httpd-2.4.27]# echo $? 0
make 安裝
make
而後
make install
collect2: error: ld returned 1 exit status 錯誤提示
####### collect2: error: ld returned 1 exit status 錯誤提示 ##################### collect2: error: ld returned 1 exit status make[2]: *** [htpasswd] 錯誤 1 make[2]: 離開目錄「/usr/local/src/httpd-2.4.27/support」 make[1]: *** [all-recursive] 錯誤 1 make[1]: 離開目錄「/usr/local/src/httpd-2.4.27/support」 make: *** [all-recursive] 錯誤 1 #### 解決辦法 1 ####(我是用這個解決的) [root@LONG httpd-2.4.27]# make clean [root@LONG httpd-2.4.27]# cd .. [root@LONG src]# rm -rf apr-1.6.2 [root@LONG src]# rm -rf apr-util-1.6.0 [root@LONG src]# rm -rf httpd-2.4.27 # 從新安裝apr,apr-util,httpd
/usr/local/apache2.4/bin/httpd -M //查看加載的模塊
啓動Apache
[root@aminglinux-01 apache2]# /usr/local/apache2.4/bin/apachectl start AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::dbd:48aa:6994:bf39. Set the 'ServerName' directive globally to suppress this message
[root@aminglinux-01 apache2]# ps aux |grep httpd root 55858 0.0 0.2 95520 2532 ? Ss 00:41 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 55859 0.0 0.4 382348 4428 ? Sl 00:41 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 55860 0.0 0.4 382348 4428 ? Sl 00:41 0:00 /usr/local/apache2.4/bin/httpd -k start daemon 55861 0.0 0.4 382348 4428 ? Sl 00:41 0:00 /usr/local/apache2.4/bin/httpd -k start root 55963 0.0 0.0 112668 972 pts/0 S+ 00:42 0:00 grep --color=auto httpd [root@aminglinux-01 apache2]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 915/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1414/master tcp6 0 0 :::3306 :::* LISTEN 2658/mysqld tcp6 0 0 :::80 :::* LISTEN 55858/httpd tcp6 0 0 :::22 :::* LISTEN 915/sshd tcp6 0 0 ::1:25 :::* LISTEN 1414/master [root@aminglinux-01 apache2]#
成功安裝
先下載
[root@aminglinux-01 ~]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2 --2017-09-28 13:58:22-- http://cn2.php.net/distributions/php-5.6.30.tar.bz2 正在解析主機 cn2.php.net (cn2.php.net)... 202.108.35.250, 202.108.35.235 正在鏈接 cn2.php.net (cn2.php.net)|202.108.35.250|:80... 已鏈接。 已發出 HTTP 請求,正在等待迴應... 200 OK 長度:15011816 (14M) [application/octet-stream] 正在保存至: 「php-5.6.30.tar.bz2」 100%[=================================================================================================>] 15,011,816 3.70MB/s 用時 4.2s 2017-09-28 13:58:27 (3.44 MB/s) - 已保存 「php-5.6.30.tar.bz2」 [15011816/15011816]) [root@aminglinux-01 ~]#
解壓: tar jxvf php-5.6.30.tar.bz2
編譯php
[root@aminglinux-01 src]# cd php-5.6.30/ [root@aminglinux-01 php-5.6.30]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
--prefix=/usr/local/php 指定安裝目錄
--with-apxs2=/usr/local/apache2.4/bin/apxs 這個是apache的一個工具,這個工具可讓咱們不用人工的干涉它,會自動的幫把擴展的模塊放到apache的modules,而且在配置文件里加上一行load ,modules
--with-config-file-path=/usr/local/php/etc 指定配置文件所在路徑
--with-mysql=/usr/local/mysql 指定mysql的路徑
報錯:configure: error: xml2-config not found. Please check your libxml2 installation.
缺乏庫:yum install -y libxml2-devel
又報錯:configure: error: Cannot find OpenSSL's <evp.h>
yum install -y openssl-devel
報錯:configure: error: Please reinstall the BZip2 distribution
yum install -y bzip2-devel
報錯:configure: error: jpeglib.h not found.
yum install -y libjpeg-devel
報錯:configure: error: png.h not found.
yum install -y libpng-devel
報錯: configure: error: freetype-config not found.
yum install -y freetype-devel
報錯: configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y epel-release 先安裝擴展源 yum install -y libmcrypt-devel
出現這個就表明安裝好啦
+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands [root@aminglinux-01 php-5.6.30]#
安裝:make
make install
copy配置文件(由於以前編譯參數有定義過,因此須要改一下)
[root@aminglinux-01 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
查看是否有配置文件
[root@aminglinux-01 php-5.6.30]# /usr/local/php/bin/php -i |less PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0 phpinfo() PHP Version => 5.6.30 System => Linux aminglinux-01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 Build Date => Sep 28 2017 15:40:08 Configure Command => './configure' '--prefix=/usr/local/php' '--with-apxs2=/usr/local/apache2.4/bin/apxs' '--with-config-file-path=/usr/local/php/etc' '--with-mysql=/usr/local/mysql' '--with-pdo-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-zlib-dir' '--with-bz2' '--with-openssl' '--with-mcrypt' '--enable-soap' '--enable-gd-native-ttf' '--enable-mbstring' '--enable-sockets' '--enable-exif' Server API => Command Line Interface Virtual Directory Support => enabled Configuration File (php.ini) Path => /usr/local/php/etc Loaded Configuration File => /usr/local/php/etc/php.ini
php只是做爲Apache的模塊應用,因此不須要啓動。
[root@aminglinux-01 php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
make && make install
模塊:ls /usr/local/apache2.4/modules/libphp7.so
同拷貝配置文件:cp php.ini-production /usr/local/php/etc/php.ini
打開它,這裏面有4個地方須要修改。
# ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80 #
改爲以下,否則啓動會提示有警告
# ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName www.example.com:80 #
改完如發現如下錯誤,系統安裝了php5,和7 把php7註釋掉就恢復。
[root@aminglinux-01 ~]# /usr/local/apache2.4/bin/apachectl restart AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::dbd:48aa:6994:bf39. Set the 'ServerName' directive globally to suppress this message httpd not running, trying to start /usr/local/apache2.4/bin/apachectl: 行 79: 127106 段錯誤 $HTTPD -k $ARGV [root@aminglinux-01 ~]#
在運行一次,就不會有提示警告了,若是出現如下錯誤,說明同時起了兩個php,把php7.1註釋掉就行了
[root@aminglinux-01 ~]# /usr/local/apache2.4/bin/apachectl restart httpd not running, trying to start /usr/local/apache2.4/bin/apachectl: 行 79: 127111 段錯誤 $HTTPD -k $ARGV [root@aminglinux-01 ~]#
註釋:在php.conf 找到php7
LoadModule php5_module modules/libphp5.so #LoadModule php7_module modules/libphp7.so
<Directory /> AllowOverride none Require all denied </Directory>
改成:
<Directory /> AllowOverride none Require all granted </Directory>
修改他的目的是,容許全部請求,若是不設置該行,則咱們訪問的時候會報403錯誤。
AddType application/x-gzip .gz .tgz
下面添加一行:
AddType application/x-httpd-php .php
不加不能php解析
第四個更改,接着找到下面這一段:
<IfModule dir_module> DirectoryIndex index.html </IfModule>
將該行修改成:
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
而後
[root@aminglinux-01 httpd-2.4.27]# /usr/local/apache2.4/bin/apachectl -t Syntax OK [root@aminglinux-01 httpd-2.4.27]# /usr/local/apache2.4/bin/apachectl graceful [root@aminglinux-01 httpd-2.4.27]#
建立一個腳本(都是在htdocs目錄下)
vi /usr/local/apache2.4/htdocs/1.php
寫入一下內容
<?php phpinfo(); ?>
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
apache正常啓動的狀況,用網頁是能夠
[root@aminglinux-01 httpd-2.4.27]# /usr/local/apache2.4/bin/apachectl graceful [root@aminglinux-01 httpd-2.4.27]#
[root@aminglinux-01 ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK
而後訪問:http://192.168.245.128/1.php 若是能正常訪問,說明php解析正常。
若是沒有成功解析,能夠-M查看有沒有 加載php模塊。
mysql5.5源碼編譯安裝 http://www.aminglinux.com/bbs/thread-1059-1-1.html
mysql5.7二進制包安裝(變化較大) http://www.apelearn.com/bbs/thread-10105-1-1.html
apache dso https://yq.aliyun.com/articles/6298