微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Mac OS上编译安装Nginx+PHP+MariaDB开发环境的教程

因为甲骨文的尿性。mariadb应该要顶替MysqL了。所以抛弃MysqL

1,编译Nginx

分别下载Nginx,openssl,pcre 编译openssl的时候会提示

rush:plain;"> WARNING! If you wish to build 64-bit library,then you have to invoke ‘./Configure darwin64-x86_64-cc' *manually*.

如果你不停止编译就会出错。这个问题应该是 openssl/config脚本猜对你的系统是64位,但是 会根据$KERNEL_BITS来判断是否开启x86_64编译,认 是不开启的(很奇怪的设置,虽然会给你5秒时间停止编译并手动开启),所以你生成的openssl库文件是32位的,最后静态链接Nginx会出错。目前看来没有很好的方法把x86_64的参数传到openssl配置文件中 (openssl/config 猜测os架构,设置编译的参数是32位还是64位,认是32位,然后调用openssl/Configure生成Makefile)

可以在configure之前export KERNEL_BITS=64,如果还是不起作用 就要手到修改了 进入Nginx目录

代码如下:
figure ./configure –prefix=/usr/locale/Nginx –with-openssl=../openssl-1.0.1i –with-pcre=../pcre-8.33

手动修改 objs/Makefile:

rush:plain;"> ./config –prefix=/Users/xxx/Downloads/openssl-1.0.1e/.openssl no-shared no-threads

改成

代码如下:
figure darwin64-x86_64-cc –prefix=/Users/xxx/Downloads/openssl-1.0.1e/.openssl no-shared no-threads

再make

2,编译PHP

下载PHP源码和一些类库 zlib:http://www.zlib.net/ GD库:https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz 不好下 freetype:http://sourceforge.net/projects/freetype/ libpng:http://www.libpng.org/pub/png/libpng.html libjpeg:http://www.ijg.org/

curl: http://curl.haxx.se/download.html

mhash: http://sourceforge.net/projects/mhash/ mcrypt: http://mcrypt.hellug.gr/ 还有bzip2。 gettext 和libtool 在gnu官网,不过速度不行,其他的库我用了系统自带。懒得再折腾,到时候没啥补啥。 除了libtool直接扔在了/usr,其他我都装在了/usr/local的一个个单独目录里面。比如jpeg就是/usr/local/jpeg方便以后修改

代码如下:

./configure –prefix=/Users/saint/bin/PHP –enable-inline-optimization –enable-fpm –with-mcrypt=/usr/local/libmcrypt –with-zlib –enable-mbstring –with-openssl –with-MysqL –with-MysqLi –with-MysqL-sock –with-gd –with-jpeg-dir=/usr/local/jpeg –enable-gd-native-ttf –enable-pdo –with-gettext –with-curl –with-pdo-MysqL –enable-sockets –enable-bcmath –enable-xml –with-bz2=/usr –enable-zip –enable-freetype –with-png-dir=/usr/local/libpng –with-pcre-regex –with-iconv-dir=/usr –with-gettext=/usr/local/gettext

3.编译mariadb

编译mariabd需要先安装cmake。去www.cmake.org下载安装tar zxf mariadb-5.5.32.tar.gz

rush:bash;"> cd mariadb-5.5.32 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
rush:plain;"> -DMysqL_UNIX_ADDR=/tmp/MysqL.sock \ -DMysqL_DATADIR=/data/mariadb \ -DSYSconfdIR=/usr/local/mariadb \ -DMysqL_USER=MysqL \ -DMysqL_TCP_PORT=3306 \ -DWITH_XTradB_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EXTRA_CHARSETS=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DEXTRA_CHARSETS=all \ -DWITH_BIG_TABLES=1 \ -DWITH_DEBUG=0
rush:bash;"> make && make install

/bin/cp support-files/my-small.cnf /usr/local/mariadb/my.conf
cp support-files/MysqL.server /usr/local/mariadb/MysqLd

my.cf

代码如下:

cat > /etc/my.cnf << EOF [mysqld] basedir = /usr/local/mariadb datadir = /data/mariadb pid-file = /data/mariadb/mariadb.pid character-set-server = utf8 collation-server = utf8_general_ci user = mysql port = 3306 default_storage_engine = InnoDB innodb_file_per_table = 1 server_id = 1 log_bin = mysql-bin binlog_format = mixed expire_logs_days = 7 bind-address = 0.0.0.0 # name-resolve skip-name-resolve skip-host-cache #lower_case_table_names = 1 ft_min_word_len = 1 query_cache_size = 64M query_cache_type = 1 skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M # LOG log_error = /data/mariadb/mariadb-error.log long_query_time = 1 slow_query_log slow_query_log_file = /data/mariadb/mariadb-slow.log # Oher #max_connections = 1000 open_files_limit = 65535 [client] port = 3306 EOF /usr/local/mariadb/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb --datadir=/data/mariadb chown mysql.mysql -R /data/mariadb export PATH=$PATH:/usr/local/mariadb/bin echo 'export PATH=$PATH:/usr/local/mariadb/bin' >> /etc/profile source /etc/profile

rush:bash;"> /usr/local/mariadb/bin/MysqL -e “grant all privileges on *.* to root@'127.0.0.1′ identified by “dbrootpwd” with grant option;” /usr/local/mariadb/bin/MysqL -e “grant all privileges on *.* to root@'localhost' identified by “dbrootpwd” with grant option;” /usr/local/mariadb/bin/MysqL -uroot -pdbrootpwd -e “delete from MysqL.user where Password=”;” /usr/local/mariadb/bin/MysqL -uroot -pdbrootpwd -e “delete from MysqL.db where User=”;” /usr/local/mariadb/bin/MysqL -uroot -pdbrootpwd -e “drop database test;”

4.后续安装扩展

PHP提供了一个PHPize工具供我们安装需要的扩展。

下面介绍PHPize的使用:

(1).找到自己原来编译的PHP安装目录,例如我的目录是/home/saint/Development/PHP,在该目录下,找到bin/PHPize。如果没有这个工具,则说明没有安装该工具,那么需要安装PHP.dev,一般都会有这个工具。

(2).要扩展的话,就需要有一个和当前已安装的PHP的版本一样的PHP的源包,当前PHP版本可以用过PHPinfo()查看。

(3).打开源包目录,进入到ext目录,例如我就进入到:/home/saint/Development/PHP-5.5.6/ext下,ext下有各个PHP带有的扩展模块,进入到ext/sockets中。

(4).cd到ext/sockets后,运行PHPize程序:

rush:bash;"> /home/saint/Development/PHP/bin/PHPize

执行后,可以看到PHPize会帮我们生成了对应的configure文件

(5).通过configure来配置,执行下面的命令:

rush:bash;"> ./configure --enable-sockets --with-PHP-config=/home/saint/Development/PHP/bin/PHP-config

make

make install

注: PHP-config文件PHPize是同一个目录下的

(6).更改PHP.ini,增加下面的语句:

代码如下:

extension=”/home/saint/Development/PHP/lib/PHP/extensions/no-debug-non-zts-20121226/sockets.so

觉得难看可以将那个日期文件删除

(7).重启Nginx

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐