Source URL
What is LEMP
LEMP is an acronym for Linux, nginx(Pronounced as Engine X), MySQL, PHP. Nginx is a web server like Apach. Nginx is similar to Apache, but better suite for Webservers where resources like memory are limited. Let us now install LEMP in out CubieTruck. My Cubice truck is running on Aruntu.
Step 1: Update & Upgrade
$ sudo apt-get update
$ sudo apt-get upgrade
Step 2: Install nginx and set configuration
Install nginx
$ sudo apt-get -y install nginx
By default, nginx serves it static content out of /usr/share/nginx/www. We need to chage it to
$ sudo mkdir ~/SSD/WordPress/www
Now it's time to create nginx virtual host(actually server blocks, in nginx term) file. In nginx, multiple sites can be hosted from a single server by creating multiple virtual hosts. Let us create a virtual host for testing our nginx installation and to use ~/SSD/WordPress/www as the root for serving its contents instead of the defualt /usr/share/nginx/www.
There are two step in creating a virtual host. First, we need to create a virtual host configuration file in /etc/nginx/sites-available folder, second we need to symlink that file to /etc/nginx/sites-enabled folder.
Before doing so, first we need to unlink the default nginx virtual host configuration from sites-enabled folder.
$ sudo service nginx stop
$ sudo unlink /etc/nginx/sites-enabled/default
Now let us create a most simple virtual host config file. For more information on nginx configuration head on to his
cd /etc/nginx/sites-available/
sudo vi mysite
server{
listen 80;
root ~/SSD/WordPress/www;
index index.html index.htm;
}
Create a symlink for the above created file in the sites-enabled folder.
$ sudo ln -s /etc/nginx/sites-available/myite /etc/nginx/sites-enabled/
Now we have created and enabled our first virtual host, to test it, let us now create a test index.html file.
$ cd ~/SSD/WordPress/www
$ vi index.html
put the below contents in it.
"Welcome to <span class="hiddenSpellError" pre="to " data-mce-bogus="1">nginx</span>" "Hello World"
Start or Restart nginx to use the new virtual host.
$ sudo service nginx start
and type your ipaddress of the cubietruck in any browser which is connected to yout local network.
And you can see "Hello World".
Step 3: MySQL Installation
$ sudo apt-get -y installl mysql-server
During the installation of mySQL server, it will ask for a root password, provide a strong password and note it down in somewhere. We will use it in future.
Step 4: PHP Install
PHP-FPM which is a FastCGI interface that will allow Nginx to send requests to PHP, PHP-APC is an extension to PHP that helps accelerate PHP's performance. PHP5-MySQL is the PHP interface for MySQL database.
sudo apt-get -y install php5-fpm php-apc php5-mysql
Step 5: Configurating PHP for nginx
In this step, we need to configure PHP to work with nginx. Let us restart php5-fpm first, to make sure that APC extension is loaded.
sudo service php5-fpm restart
Now we need to modify our nginx blocks configuration file that we have created in step 2.
$ sudo vi /etc/nginx/sites-available/mysite
Change the contest as shown below
server{
listen 80;
root ~/SSD/WordPress/www;
index index.php index.html index.htm;
location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Now we have added index.php to the index pages and added some more lines to redirect PHP requests to PHP5-FPM. Let us now check if PHP is working properly, by creating a test.php file in the nginx root folder which is now ~/SSD/WordPress/www.
$ cd ~/SSD/WordPress/www
$ vi test.php
phpinfo();
?>
$ sudo service nginx restart
Now type your ip address of cubietruck/test.php, you can see the below page.
Step 6: Installing and configuring PhpMyAdmin (Optional)
PhpMyAdmin is a free and open source tool written in PHP intended to handle the administration of MySQLwith the use of a web browser. It can perform various tasks such as creating, modifying or deleting databases,tables, fields or rows; executing SQL statements; or managing users and permissions.
sudo apt-get install phpmyadmin
During the installation, phpmyadmin will ask you if you want to configure the database with dbconfig. Go ahead and choose yes.
Input MySQL’s database password when prompted and click ok.
When phpmyadmin prompts you to choose a server (either apache or lighttpd) hit tab, and select neither one.
Now to make phpMyAdmin to work with nginx we need to modify the server blocks that we have created earlier.
$ sudo vi /etc/nginx/sites-available/mysite
server{
listen 80;
root ~/SSD/WordPress/www;
index index.php index.html index.htm;
location ~ .php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
Now put your ip address/phpmyadmin, it will load the phpMyAdmin page. It will ask for user name and password. Provide “root” as username and give the mysql password to login.
If you have json problem, open /etx/php5/mods-available/json.ini and uncomment priority=20 and reboot.
[contact-form-7 id="24" title="Karl"]
댓글 없음:
댓글 쓰기