LEMP on Debian 7 Rumi, December 3, 2016December 3, 2016 Installing MySQL 5 In order to install MySQL, we run apt-get install mysql-server mysql-client You will be asked to provide a password for the MySQL root user – this password is valid for the user root@localhost as well as root@server1.example.com, so we don’t have to specify a MySQL root password manually later on: New password for the MySQL “root” user: <– yourrootsqlpassword Repeat password for the MySQL “root” user: <– yourrootsqlpassword PHP-FPM & PHP modules installation Use the below command to install PHP-FPM & PHP modules. PHP initially called Personal Home Page, now it is called asHypertext Preprocessor. PHP is a opensource software which is designed for web development purpose. It is used for server-side scripting language as well as general-purpose programming language. $ sudo apt-get install php5 php5-fpm php5-mysql php5-cli php5-curl php5-gd php5-mcrypt Installing Nginx Nginx is available as a package for Ubuntu 14.04 which we can install, As Apache2 is installed by default so we will remove it first & then install nginx: service apache2 stop update-rc.d -f apache2 remove apt-get remove apache2 apt-get install nginx Start nginx afterwards: service nginx start Type in your web server’s IP address or hostname into a browser (e.g. http://192.168.0.100), and you should see the nginx home page. The default vhost is defined in the file /etc/nginx/sites-available/default – let’s modify it as follows: vi /etc/nginx/sites-available/default [...] server { listen 80; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; allow ::1; deny all; } # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests #location /RequestDenied { # proxy_pass http://127.0.0.1:8080; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } [...] Uncomment both listen lines to make nginx listen on port 80 IPv4 and IPv6. server_name _; makes this a default catchall vhost (of course, you can as well specify a hostname here like www.example.com). I’ve added index.php to the index line. root /usr/share/nginx/html; means that the document root is the directory /usr/share/nginx/html. Now save the file and reload nginx: service nginx reload Next open /etc/php5/fpm/php.ini vi /etc/php5/fpm/php.ini … and set cgi.fix_pathinfo=0: Reload PHP-FPM: service php5-fpm reload Now create the following PHP file in the document root /usr/share/nginx/html: vi /usr/share/nginx/html/info.php <?php phpinfo(); ?> Now we call that file in a browser (e.g. http://192.168.0.100/info.php). Getting MySQL Support In PHP5 To get MySQL support in PHP, we can install the php5-mysql package. It’s a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this: apt-cache search php5 Pick the ones you need and install them like this: apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It’s similar to other PHP opcode cachers, such as eAccelerator and Xcache. It is strongly recommended to have one of these installed to speed up your PHP page. APC can be installed as follows: apt-get install php-apc Now reload PHP-FPM: service php5-fpm reload Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module: Install phpMyAdmin phpMyAdmin is a free open-source web-based administration tool for managing the MySQL, MariaDB servers which will help us to manage the database easily. $ sudo apt-get -y install phpmyadmin Make sure your system should have database installed (MySQL, MariaDB, etc) before proceeding phpMyAdmin installation. Here choose Yes to configure database for phpmyadmin with dbconfig-common. Just create symlink from /usr/share/phpMyAdmin to /usr/share/nginx/html, this will do the trick In my case nginx 1.2.1 below symlink was used- ln -s /usr/share/phpmyAdmin /usr/share/nginx/www Open your web browser and navigate to http://localhost/phpMyAdmin or http://your-server-ip-address/phpMyAdmin or http://127.0.0.1/phpMyAdmin Some extra effort- Making PHP-FPM Use A TCP Connection By default PHP-FPM is listening on the socket /var/run/php5-fpm.sock. It is also possible to make PHP-FPM use a TCP connection. To do this, open /etc/php5/fpm/pool.d/www.conf… vi /etc/php5/fpm/pool.d/www.conf … and make the listen line look as follows: [...] ;listen = /var/run/php5-fpm.sock listen = 127.0.0.1:9000 [...] This will make PHP-FPM listen on port 9000 on the IP 127.0.0.1 (localhost). Make sure you use a port that is not in use on your system. Then reload PHP-FPM: php5-fpm reload Next go through your nginx configuration and all your vhosts and change the line fastcgi_pass unix:/var/run/php5-fpm.sock; to fastcgi_pass 127.0.0.1:9000;, e.g. like this: vi /etc/nginx/sites-available/default [...] location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php5-fpm: #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } [...] Finally reload nginx: service nginx reload Src: https://www.howtoforge.com/installing-nginx-with-php5-fpm-and-mysql-on-ubuntu-14.04-lts-lemp http://www.2daygeek.com/install-lemp-nginx-mariadb-php-phpmyadmin-on-debian/# Administrations Configurations (Linux) DebianLEMP