{"id":3229,"date":"2014-04-25T08:45:12","date_gmt":"2014-04-25T08:45:12","guid":{"rendered":"http:\/\/ubuntuhandbook.org\/?p=3229"},"modified":"2014-04-25T08:45:12","modified_gmt":"2014-04-25T08:45:12","slug":"install-nginx-with-php5-mysql-lemp-in-ubuntu-14-04-server","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2014\/04\/install-nginx-with-php5-mysql-lemp-in-ubuntu-14-04-server\/","title":{"rendered":"Install Nginx with Php5 &#038; Mysql (LEMP) in Ubuntu 14.04 Server"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2014\/04\/web-server-icon.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3230\" alt=\"LEMP Ubuntu 14.04\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2014\/04\/web-server-icon.jpg\" width=\"241\" height=\"204\" \/><\/a><\/p>\n<p>Want to build a website on your Ubuntu Server? Well, LEMP may be a good choice and here&#8217;s how to install and set it up.<\/p>\n<p><b>LEMP<\/b> stands for <b>Linux<\/b>, <b>Nginx<\/b> (pronounced \u201cengine x\u201d), <b>MySQL<\/b> and <b>PHP<\/b>. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. So it\u2019s a good alternative to Apache webserver for building websites on low memory hosts.<\/p>\n<p><b>To get started<\/b>, log in your Ubuntu Server and follow the steps below:<\/p>\n<p><b>1. Install MySQL<\/b><\/p>\n<p>MySQL is a database management system which stores and organizes references to the information the webserver needs.<\/p>\n<p>To install Mysql 5.5.36, run command:<\/p>\n<pre style=\"border: none;\">sudo apt-get install mysql-server mysql-client<\/pre>\n<p>To install Mysql 5.6.16, run:<\/p>\n<pre style=\"border: none;\">sudo apt-get install mysql-server-5.6 mysql-client-5.6<\/pre>\n<p>While the installing process, you&#8217;ll be asked to type a password for MySQL root user.<\/p>\n<p><b>2. Install Nginx<\/b><\/p>\n<p>Nginx 1.4.6 is available in Ubuntu repositories. To install it, run:<\/p>\n<pre style=\"border: none;\">sudo apt-get install nginx<\/pre>\n<p>If you want, install the latest stable Nginx 1.4.7 from PPA:<\/p>\n<pre style=\"border: none;\">sudo apt-get install python-software-properties\n\nsudo add-apt-repository ppa:nginx\/stable\n\nsudo apt-get update\n\nsudo apt-get install nginx<\/pre>\n<p>Once installed, start the web service via:<\/p>\n<pre style=\"border: none;\">sudo service nginx start<\/pre>\n<p>And check out if it is working by going to <span style=\"text-decoration: underline;\"><em>http:\/\/serverip<\/em><\/span><\/p>\n<div id=\"attachment_2078\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/nginxisrunning.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2078\" class=\"size-full wp-image-2078\" alt=\"nginx is working ubuntu 14.04\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/nginxisrunning.jpg\" width=\"520\" height=\"299\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/nginxisrunning.jpg 520w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/nginxisrunning-300x172.jpg 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/a><p id=\"caption-attachment-2078\" class=\"wp-caption-text\">nginx is working ubuntu 14.04<\/p><\/div>\n<p><b>3. Install PHP5<\/b><\/p>\n<p><b>PHP<\/b> is a reflective programming language, which makes it possible for all these different parts to work together.<\/p>\n<p>We can make PHP5 work in nginx through PHP-FPM, which is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.<\/p>\n<p>Run command below to install php5-fpm:<\/p>\n<pre style=\"border: none;\">sudo apt-get install php5-fpm<\/pre>\n<p><b>4. Setup Nginx<\/b><\/p>\n<p>The nginx configuration files are available in <i>\/etc\/nginx\/nginx.conf<\/i>, read this <a href=\"http:\/\/wiki.nginx.org\/NginxFullExample\" target=\"_blank\">configuration example<\/a>.<\/p>\n<p>To modify the default site example:<\/p>\n<pre style=\"border: none;\">sudo vi \/etc\/nginx\/sites-available\/default<\/pre>\n<p>Here you can define the root directory (to put WordPress files there), your site domain name, as well as other settings. See the example below:<\/p>\n<pre style=\"background: #FFFFFF;\">server {\n\tlisten 80 default_server;\n\tlisten [::]:80 default_server ipv6only=on;\n\n\troot <b>\/usr\/share\/nginx\/html<\/b>;\n\tindex index.php index.html index.htm;\n\n\t# Make site accessible from http:\/\/localhost\/\n\tserver_name <b>localhost<\/b>;\n\n\tlocation \/ {\n\n\t\ttry_files $uri $uri\/ \/index.php;\n\n\t}\n\n\tlocation \/doc\/ {\n\t\talias \/usr\/share\/doc\/;\n\t\tautoindex on;\n\t\tallow 127.0.0.1;\n\t\tallow ::1;\n\t\tdeny all;\n\t}\n\n\t#\n\terror_page 500 502 503 504 \/50x.html;\n\tlocation = \/50x.html {\n\t\troot \/usr\/share\/nginx\/html;\n\t}\n\n\tlocation ~ \\.php$ {\n\n\t\t# With php5-fpm:\n                try_files $uri =404;\n\t\tfastcgi_pass unix:\/var\/run\/php5-fpm.sock;\n\t\tfastcgi_index index.php;\n\t\tinclude fastcgi_params;\n\t}\n\n\t# deny access to .htaccess files, if Apache's document root\n\t# concurs with nginx's one\n\t#\n\tlocation ~ \/\\.ht {\n\t\tdeny all;\n\t}\n}<\/pre>\n<p>Remember to restart the web service to apply changes:<\/p>\n<pre style=\"border: none;\">sudo service nginx reload<\/pre>\n<p><b>5. Check if PHP is working<\/b><\/p>\n<p>Create the test file:<\/p>\n<pre style=\"border: none;\">sudo vi \/usr\/share\/nginx\/html\/info.php<\/pre>\n<p>Add following lines and save the file:<\/p>\n<pre style=\"background: #FFFFFF;\">&lt;?php\nphpinfo();\n?&gt;<\/pre>\n<p>Go to <span style=\"text-decoration: underline;\"><em>http:\/\/serverip\/info.php<\/em><\/span> in client&#8217;s web browser and you\u2019ll see:<\/p>\n<div id=\"attachment_2079\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/phpisworking.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2079\" class=\"size-full wp-image-2079\" alt=\"php is working\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/phpisworking.jpg\" width=\"520\" height=\"299\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/phpisworking.jpg 520w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/phpisworking-300x172.jpg 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/a><p id=\"caption-attachment-2079\" class=\"wp-caption-text\">php is working<\/p><\/div>\n<p><b>6 Get MySQL working with PHP:<\/b> Install Xcache (<a href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_PHP_accelerators\" target=\"_blank\">list of PHP accelerators<\/a>), a free and open PHP opcode cacher for caching and optimizing PHP intermediate code, as well as other PHP modules:<\/p>\n<pre style=\"border: none;\">sudo 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 php5-xcache<\/pre>\n<p>Then restart php5:<\/p>\n<pre>sudo service php5-fpm restart<\/pre>\n<p>Now reload <span style=\"text-decoration: underline;\"><em>http:\/\/serverip\/info.php<\/em><\/span> page and scroll down to find out if there\u2019s a section about MySQL:<\/p>\n<div id=\"attachment_2080\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/mysqlisworking.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2080\" class=\"size-full wp-image-2080\" alt=\"mysql is working with php\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/mysqlisworking.jpg\" width=\"520\" height=\"299\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/mysqlisworking.jpg 520w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2013\/10\/mysqlisworking-300x172.jpg 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/a><p id=\"caption-attachment-2080\" class=\"wp-caption-text\">mysql is working with php<\/p><\/div>\n<p>For security reason, remove the info.php after the test:<\/p>\n<pre style=\"border:none;\">sudo rm \/usr\/share\/nginx\/html\/info.php<\/pre>\n<p><b>7. Install Phpmyadmin to manage Mysql Database via web:<\/b><\/p>\n<p>First install phpmyadmin:<\/p>\n<pre style=\"border: none;\">sudo apt-get install phpmyadmin<\/pre>\n<p>During the installation, it will ask you if you want to configure the database with dbconfig. Go ahead and choose yes.<\/p>\n<p>Input MySQL\u2019s database password when prompted and click ok.<\/p>\n<p>When phpmyadmin prompts you to choose a server (either apache or lighttpd) hit tab, and select neither one.<\/p>\n<p>Second, create a symbolic link between phpMyAdmin and your site&#8217;s directory:<\/p>\n<pre style=\"border: none;\">sudo ln -s \/usr\/share\/phpmyadmin\/ \/usr\/share\/nginx\/html<\/pre>\n<p>Restart nginx and finally you&#8217;re able to access phpmyadmin by going to <span style=\"text-decoration: underline;\"><em>http:\/\/serverip\/phpmyadmin<\/em><\/span> and typing Mysql username and password.<\/p>\n<pre style=\"border: none;\">sudo service nginx restart<\/pre>\n<p>Done!<\/p>","protected":false},"excerpt":{"rendered":"<p>Want to build a website on your Ubuntu Server? Well, LEMP may be a good choice and here&#8217;s how to install and set it up. LEMP stands for Linux, Nginx (pronounced \u201cengine x\u201d), MySQL and PHP. The nginx project started with a strong focus on high concurrency, high performance and low memory usage. So it\u2019s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[747,748,855,1059],"class_list":["post-3229","post","type-post","status-publish","format-standard","hentry","category-howtos","category-ubuntu-server-2","tag-lemp","tag-nginx","tag-ubuntu-14-04","tag-web-server"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/3229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=3229"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/3229\/revisions"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=3229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=3229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=3229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}