Home >Backend Development >PHP Tutorial >mac start php-fpm
Run it directly, and there will be an error that the configuration file cannot be found.
$ php-fpm
[11-Jan-2014 16:03:03] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
[11-Jan-2014 16:03:03] ERROR: failed to load configuration file '/private/etc/php-fpm.conf'
[11-Jan-2014 16:03:03] ERROR: FPM initialization failed
You can generate the configuration file in the /private/etc/ directory, which requires root permissions (sudo)
Or place the configuration file in a directory with permissions for ordinary users, and specify the location of the configuration file through the --fpm-config parameter, as follows :
# cp /private/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
$ php-fpm --fpm-config /usr/local/etc/php-fpm .conf
[11-Jan-2014 16:10:49] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
[11- Jan-2014 16:10:49] ERROR: failed to post process the configuration
[11-Jan-2014 16:10:49] ERROR: FPM initialization failed
The error message shows: The "log" file cannot be opened correctly , the reason is that it works in the /usr/var directory by default. You can modify the configuration file to specify the correct log file path
$ vim /usr/local/etc/php-fpm.conf
Modify the php-fpm.conf file error_log item, the default prefix is /usr/var, but there is no such path
error_log = /usr/local/var/log/php-fpm.log
pid = /usr/local/var/run/php-fpm .pid
or do not modify the path of the configuration item in the configuration file, specify the relative path prefix to place the runtime file in the running parameter (-p) of php-fpm
$ php-fpm --fpm-config /usr/ local/etc/php-fpm.conf --prefix /usr/local/var
At this point, the php-fpm daemon can basically be started correctly.
Let’s take a look at the php.ini configuration file and the installation of extensions.
First look at the compilation parameters. Some values are compiled into the executable program and cannot be changed.
$ php -i|grep config
Find the location of the configuration file (php.ini) and directory, and specify the values of the following two items
'--with-config-file-path=/etc'
'- -with-config-file-scan-dir=/Library/Server/Web/Config/php'
So we need to create php.ini in the /etc directory. Mac provides it in /private/etc and /etc. The sample file php.ini.default, after verification, the two files are exactly the same, so it doesn’t matter which one is copied. Mac provides md5 instead of md5sum under Linux:
$ md5 /private/etc/php.ini.default /etc/php.ini.default
MD5 (/private/etc/php.ini.default) = 1c47241665ea5efdc55fd5809f675449
MD5 (/etc/php.ini.default) = 1c47241665ea5efdc55fd5809f675449
/etc directory permission root:wheel, Root permissions or sudo are required. For how to set the password required for the sudo command on Mac, please check
http://support.apple.com/kb/HT4103?viewlocale=zh_CN&locale=zh_CN
http://support.apple .com/kb/PH6515?viewlocale=zh_CN
# cp /etc/php.ini.default /etc/php.ini
Change to own. You don’t need to always switch to root for future modifications. It is best not to change the production environment
# chown
# chmod u+w /etc/php.ini
Install PHP extension
/Library/Server/Web/Config/php This directory does not exist , or maybe there is a Mac OS Depends on php, for example, php54-redis will depend on php54. As for whether the compiled extension can be configured to come with it, there is no experiment. The following takes the php_discuz extension (download from https://github.com/potterhe/php_discuz) as an example.
If the extension source code is in the /Users/apple/php_discuz directory
$ ./configure
$ make
After the extension is compiled, it will be stored in /Users/apple/php_discuz/modules/discuz.so by default
The extension will be in Open the configuration file
$ echo "extension=/Users/apple/php_discuz/modules/discuz.so" > /Library/Server/Web/Config/php/discuz.ini
Test and verify
$ php -i |grep discuz
discuz support => enabled
Run case test
$ php -f /Users/apple/php_discuz/discuz.php
The above introduces how to start php-fpm on Mac, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.