编译安装openresty+mysql+php7
1.準(zhǔn)備
1.更新系統(tǒng)
yum makecache && yum -y update- 1
- 1
2.安裝常用基礎(chǔ)軟件
yum -y install bash-completion vim net-tools bind-utils wget screen- 1
- 1
最后別忘了重啟
3.需要下載的源碼
1.openresty
wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz- 1
- 1
2.mariaDB
wget http://sfo1.mirrors.digitalocean.com/mariadb/mariadb-5.5.47/source/mariadb-5.5.47.tar.gz- 1
- 1
3.php7
wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zip- 1
- 1
2.openresty
1.依賴關(guān)系
openresty依賴于perl 5.6.1+, libreadline, libpcre, libssl,首先安裝依賴關(guān)系。
yum install readline-devel pcre-devel openssl-devel gcc- 1
- 1
2.下載源碼
使用wget下載
wget https://openresty.org/download/ngx_openresty-1.9.7.1.tar.gz- 1
- 1
博主安裝時(shí)最新版為1.9.7.1,可以登錄http://openresty.org查看最新版本,選擇需要的版本進(jìn)行下載。
解壓下載好的壓縮包
- 1
- 1
注意將1.9.7.1替換為你下載的版本號(hào)
3. ./configure
進(jìn)入 ngx_openresty-VERSION/ 目錄, 然后輸入以下命令配置:
./configure- 1
- 1
默認(rèn), –prefix=/usr/local/openresty 程序會(huì)被安裝到/usr/local/openresty目錄。?
我們可以指定各種選項(xiàng),比如
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
具體用法參考./configure –help 或者官方文檔
4.編譯、安裝
使用make編譯
make- 1
- 1
安裝
make install- 1
- 1
5.將nginx添加到系統(tǒng)變量
PATH=/usr/local/openresty/nginx/sbin:$PATH export PATH- 1
- 2
- 1
- 2
6.默認(rèn)項(xiàng)目路徑
/usr/local/openresty/nginx/html- 1
- 1
7.啟動(dòng)、關(guān)閉、重啟nginx
nginx -c /usr/local/openresty/nginx/conf/nginx.conf //啟動(dòng)并加載配置文件 nginx -s stop //停止 nginx -s reload //重啟- 1
- 2
- 3
- 1
- 2
- 3
3.mariaDB
1.安裝依賴庫(kù)、編譯工具
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl cmake compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* zlib-devel gd-devel- 1
- 1
2.創(chuàng)建數(shù)據(jù)庫(kù)文件夾,用戶組
groupadd mysql && useradd -g mysql mysql -s /bin/false && mkdir -p /data/mysql && chown -R mysql:mysql /data/mysql && mkdir -p /usr/local/mysql- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
3.下載mariaDB 5.5.47
wget http://sfo1.mirrors.digitalocean.com/mariadb/mariadb-5.5.47/source/mariadb-5.5.47.tar.gz- 1
- 1
解壓
tar zxf mariadb-5.5.47.tar.gz- 1
- 1
進(jìn)入目錄
cd mariadb-5.5.47- 1
- 1
4.編譯、安裝mariaDB
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc && make && make install- 1
- 2
- 1
- 2
check完之后沒什么事可以去喝個(gè)茶,博主低配云主機(jī)編譯了大概12分鐘
5.刪除系統(tǒng)自帶的mariaDB配置文件
mv /etc/my.cnf /etc/my.cnf.bak- 1
- 1
6.初始化數(shù)據(jù)庫(kù),配置啟動(dòng)腳本
cd /usr/local/mysql && ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql && ln -s /usr/local/mysql/my.cnf /etc/my.cnf && cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld && chmod 755 /etc/init.d/mysqld && chkconfig mysqld on- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
7.配置mariaDB啟動(dòng)腳本
vim /etc/rc.d/init.d/mysqld- 1
- 1
改動(dòng)如下:
basedir=/usr/local/mysql #MySQL程序安裝路徑 datadir=/data/mysql #MySQl數(shù)據(jù)庫(kù)存放目- 1
- 2
- 1
- 2
然后重啟mariaDB
service mysqld restart- 1
- 1
8.將mariaDB加入系統(tǒng)環(huán)境變量
echo 'export PATH=$PATH:/usr/local/mysql/bin'>>/etc/profile && source /etc/profile- 1
- 1
9.把MariaDB的庫(kù)文件鏈接到系統(tǒng)默認(rèn)的位置,在編譯PHP等軟件時(shí)可以不用指定其庫(kù)文件地址
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql && ln -s /usr/local/mysql/include/mysql /usr/include/mysql && mkdir /var/lib/mysql && ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
10.設(shè)置root賬戶mariaDB密碼
mysql_secure_installation- 1
- 1
接下來屏幕會(huì)出現(xiàn)一系列代碼,代碼及操作記錄如下
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not foundNOTE: 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):<– 回車 OK, successfully used password, moving on…Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation.Set root password? [Y/n] <– y 回車 New password: <– 設(shè)置用戶名為root的mysql密碼 Re-enter new password: <– 密碼確認(rèn) Password updated successfully! Reloading privilege tables.. … Success!By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.Remove anonymous users? [Y/n] <– y 回車 … Success!Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] <– y 回車 … Success!By default, MariaDB comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.Remove test database and access to it? [Y/n] <– y 回車 - Dropping test database… … Success! - Removing privileges on test database… … Success!Reloading the privilege tables will ensure that all changes made so far will take effect immediately.Reload privilege tables now? [Y/n] <– y 回車 … Success!Cleaning up…All done! If you’ve completed all of the above steps, your MariaDB installation should now be secure.Thanks for using MariaDB!- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
至此,mariaDB設(shè)置完畢
4.php7
1.下載php7
wget -c --no-check-certificate -O php7-src-master.zip https://github.com/php/php-src/archive/master.zip- 1
- 1
解壓
unzip -q php7-src-master.zip- 1
- 1
進(jìn)入目錄
cd php-src-master- 1
- 1
2.安裝依賴包
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel- 1
- 1
3.編譯、安裝
./buildconf- 1
- 1
此時(shí)會(huì)生成configure文件,然后
export LD_LIBRARY_PATH=/usr/local/libgd/lib && ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-mysql=/usr/local/mysql \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --with-mysql-sock=/tmp/mysql.sock \ --with-pdo-mysql=/usr/local/mysql \ --with-gd \ --with-png-dir=/usr/local/libpng \ --with-jpeg-dir=/usr/local/jpeg \ --with-freetype-dir=/usr/local/freetype \ --with-xpm-dir=/usr/ \ --with-vpx-dir=/usr/local/libvpx/ \ --with-zlib-dir=/usr/local/zlib \ --with-t1lib=/usr/local/t1lib \ --with-iconv \ --enable-libxml \ --enable-xml \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --enable-opcache \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --enable-ftp \ --enable-gd-native-ttf \ --with-openssl \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-mcrypt \ --with-curl \ --enable-exif \ --enable-ctype && make && make install- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
在check完之后沒什么事再去喝個(gè)茶吧,博主大概也用了12分鐘?
安裝完成后提示信息
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
恭喜你,成功了
4.復(fù)制php配置文件到安裝目錄:
cp php.ini-production /usr/local/php/etc/php.ini- 1
- 1
5.備份系統(tǒng)自帶配置文件:
mv /etc/php.ini /etc/php.ini.bak- 1
- 1
6.添加軟鏈接到 /etc目錄:
ln -s /usr/local/php/etc/php.ini /etc/php.ini- 1
- 1
7.拷貝模板文件為php-fpm配置文件:
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf- 1
- 1
8.添加軟連接到 /etc目錄:
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf- 1
- 1
#####4-8合并操作
cp php.ini-production /usr/local/php/etc/php.ini && mv /etc/php.ini /etc/php.ini.bak && ln -s /usr/local/php/etc/php.ini /etc/php.ini && cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
9.修改php配置文件
vim /usr/local/php/etc/php.ini- 1
- 1
1.將disable_functions =?(禁用掉某些比較“危險(xiǎn)”函數(shù),大概在298行),改為
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname- 1
- 1
2.將expose_php = On(禁止顯示php版本的信息,大概在359行),修改為
expose_php = Off- 1
- 1
3.將;date.timezone =(大概在912行),修改為
date.timezone = Asia/Shanghai- 1
- 1
4.將
;short_open_tag; Default Value: On; Development Value: Off; Production Value: Off- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
(支持PHP短標(biāo)簽,大概在151行),修改為
short_open_tag?
Default Value: On?
Development Value: Off?
Production Value: Off?
5.將?;opcache.enable=0?(支持opcode緩存,大概在1732行),修改為
opcache.enable=1- 1
- 1
6.將;opcache.enable_cli=0(支持opcode緩存,大概在1735行),修改為
opcache.enable_cli=1- 1
- 1
然后配置opcode緩存,取消以下配置項(xiàng)的注釋(從1732行向下)
opcache.memory_consumption=64 opcache.interned_strings_buffer=4 opcache.max_accelerated_files=2000 opcache.revalidate_freq=2 opcache.fast_shutdown=1- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
10.修改php-fpm配置項(xiàng)
vim /usr/local/php/etc/php-fpm.conf- 1
- 1
取消注釋
pid = run/php-fpm.pid- 1
- 1
新增
user = www group = www- 1
- 2
- 1
- 2
11.拷貝php-fpm腳本到啟動(dòng)目錄,給予執(zhí)行權(quán)限, 設(shè)置開機(jī)啟動(dòng)
cp /usr/local/src/php-7.1.0/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm && chmod +x /etc/rc.d/init.d/php-fpm && chkconfig php-fpm on- 1
- 2
- 3
- 1
- 2
- 3
12.配置nginx支持php
location ~ \.php\$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/openresty/nginx/html$fastcgi_script_name; include fastcgi_params; }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
5.配置匯總
根目錄: /usr/local/openresty/nginx/html/?
Nginx配置文件: /usr/local/openresty/nginx/conf/nginx.conf?
php配置文件: /usr/local/php/etc/php.ini?
PHP默認(rèn)拓展文件夾:/usr/lib64/php/modules/?
PHP拓展可放置于:/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012?
MySQL配置文件: /etc/my.cnf?
mysql程序安裝路徑: basedir=/usr/local/mysql?
MySQl數(shù)據(jù)庫(kù)存放目錄: datadir=/data/mysql
來源:http://blog.csdn.net/leiflyy/article/details/50497931
總結(jié)
以上是生活随笔為你收集整理的编译安装openresty+mysql+php7的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 变动率怎么算
- 下一篇: php7与php 5.5 运行效率比较(