How to set up LNMP(linux+nginx+mysql+php) developer tool on your ubuntu server

Install all software:
sudo apt-get install nginx
sudo apt-get install php7.0-fpm
sudo apt-get install php7.0-curl
sudo apt-get install php7.0-gd php7.0-mcrypt php7.0-mysql
sudo apt-get install mysql-server mysql-client

Please remember your mysql database root password!!!

Let's config up.

1. Add nginx user and group, nginx server and php-fpm will run as nginx user.
sudo groupadd nginx 
sudo groupadd nginx
sudo useradd -g nginx nginx
sudo service php7.0-fpm restart

2. Config php-fpm
/etc/php/7.0/fpm/php.ini
cgi.fix_pathinfo=0

/etc/php/7.0/fpm/pool.d/www.conf
listen = /run/php/php7.0-fpm.sock
listen.owner = nginx
listen.group = nginx

sudo service php7.0-fpm restart

3. Config nginx
/etc/nginx/nginx.conf
user nginx nginx;
location ~ \.php$ {
    include fastcgi.conf;
    fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
}

sudo service nginx restart

PS:keep the user/group of php-fpm same as nginx server, I have marked as blue nginx above.


And it should not the same user that owns your virtual host directory for better security.
My websites are in vhosts folder, the user/group are errong_leng.
drwxrwxr-x  4 errong_leng errong_leng 4096 May 19 09:11 vhosts

Ok. let's do the test.
cat index.php
<?php
phpinfo();
?>

Everything looks fine.




cat index.php 
<?php
phpinfo();
?>
drwxrwxr-x  4 errong_leng errong_leng 4096 May 19 09:11 vhosts
drwxrwxr-x  4 errong_leng errong_leng 4096 May 19 09:11 vhosts
drwxrwxr-x  4 errong_leng errong_leng 4096 May 19 09:11 vhosts
drwxrwxr-x  4 errong_leng errong_leng 4096 May 19 09:11 vhosts

No comments:

Post a Comment

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...