Showing posts with label LAMP. Show all posts
Showing posts with label LAMP. Show all posts

Thursday, April 23, 2015

Installing full LAMP stack + phpmyadmin on Ubntu 14.04 LTS AWS EC2 instance

Just a step by step tutorial:

1. sudo apt-get update
2. sudo apt-get install apache2
3. Check if apache installed correctly by visiting your servers public IP address:

http://your-servers-ip

4. sudo apt-get install mysql-server php5-mysql #installing mysql
5. sudo mysql_install_db #create database directory structure
6. sudo mysql_secure_installation #run secure installation (just follow the instructions)
7. sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-curl php5-json #install php and some extensions (optionally), like mcrypt, curl and json

You can view all available php5 extensions by running this command in terminal: 

apt-cache search php5-

8. sudo nano /etc/apache2/mods-enabled/dir.conf #place index.php on the first position (instead of index.html by default)

Finally it should look like  

<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl # and so on...
</IfModule>

9. sudo service apache2 restart
10. In order to install phpmyadmin you should have mcrypt php5 module installed and activated

sudo apt-get install php5-mcrypt #downloading mcrypt extension

sudo php5enmod mcrypt #activating mcrypt extension

11. sudo apt-get install phpmyadmin
12. sudo service apache2 restart

Now if you will visit http://your-public-ip/phpmyadmin, phpmyadmin page should appear BUT for me it was 404 not found error. To fix this bug you need to follow steps below:

13. sudo ln -s /usr/share/phpmyadmin /var/www/html #create symlink
14. sudo nano /etc/phpmyadmin/apache.conf #open phpmyadmin apache config file and add this line to the end of a file:

Include /etc/phpmyadmin/apache.conf

15. sudo service apache2 restart #restart apache server and try to visit http://your-public-ip/phpmyadmin

Thursday, July 10, 2014

How to configure SSL under Apache 2 + Laravel

Quick tips on how to setup SSL under LAMP stack + Laravel 4.2 PHP framework.

We need to get certificate itself. In order to run your webpage through HTTPS protocol, we will need 3 files:

  1. SSL certificate private key file (.key)
  2. Certificate Signin Request (.csr)
  3. SSL certificate file (.crt)
  4. SSL chain file (.ca-bundle)

This extensions (.key .crt etc.) can differ. In different guides i saw different extensions, like .pem or .ca, so dont worry about that.

1st and 2nd file we will generate on our server machine; 3rd and 4th file we will get from certification service.

So lets start! We need to open terminal and paste commands below (commands will be explained):

1. cd ~/Documents/SSL
SSL is a custom folder created by me. You can store your certification files wherever you want, I used path above.

2. sudo openssl genrsa -des3 -out private.key 2048
Generating "private.key" file with 2048 bit encryption. We will need this to generate our CSR (2nd file) and later, when we will setup apache virtual hosts.

3. sudo openssl req -new -key private.key -out server.csr
Generating "server.csr" file in order to get our certificate. While this step You will need to fill in some information, that system will request you:

Country Name (2 letter code) [AU]: EE
State or Province Name (full name) [Some-State]: Harjumaa
Locality Name (eg, city) []: Tallinn
Organization Name (eg, company) [Internet Widgits Pty Ltd]: Your Company Name Ltd
Organizational Unit Name (eg, section) []: IT
Common Name (eg, YOUR name) []: www.yourdomain.com
Email Address []: youremail@gmail.com
A challenge password []: (you can leave it blank)
An optional company name []: (you can leave it blank)

Of course you can edit all those fields as you want.

4. Now we'r going to http://www.comodo.com/e-commerce/ssl-certificates/free-ssl-certificate.php and registering our certificate. In order to get certificate, you will need to provide CSR, that we already generated. Opening server.csr with, for example, nano sudo nano server.csr (or gedit, or vim, or download it through filezilla etc.) and copy text in server.csr. It should look like:

-----BEGIN CERTIFICATE REQUEST-----
MIIDUDCCArkCAQAwdTEWMBQGA1UEAxMNdGVzdC50ZXN0LmNvbTESMBAGA1UECxMJ
TWFya2V0aW5nMREwDwYDVQQKEwhUZXN0IE9yZzESMBAGA1UEBxMJVGVzdCBDaXR5
(more encoded data).......
Rq+blLr5X5iQdzyF1pLqP1Mck5Ve1eCz0R9/OekGSRno7ow4TVyxAF6J6ozDaw7e
GisfZw40VLT0/6IGvK2jX0i+t58RFQ8WYTOcTRlPnkG8B/uV
-----END CERTIFICATE REQUEST-----
In "Select the server software used to generate the CSR" field choose Apache-ModSSL (if you use LAMP stack, of course).

In "Select the hash algorithm you would prefer us to use when signing your Certificate" choose anything you want.

Complete the registration. You will need to confirm your domain, because of that confirmation will be sent one one of your domain emails (like admin@yourdomain.com or webmaster@yourdomain.com).

When you will totally complete registration, certificate will be sent to your email in zip archive. This archive will contain 2 files: certificate file (.crt) and chain file (.ca-bundle). Dont ask me, why we need this .ca-bundle, just google it :)

5. Upload this 2 files on your server certificate directory (for me it was ~/Documents/SSL/)

6. Edit your apache virtual host, as now we'r going to use secured connection. You will need to create new secured virtual host:
sudo cp /etc/apache2/sites-available/example.conf /etc/apache2/sites-available/yoursite.com.secured.conf
I dont actually remember name of the example.conf file, but you need to create copy of the virtual host, or just create new one with touch /etc/apache2/sites-available/yoursite.com.secured.conf

7. Add inside <VirtualHost> tag instuctions below, and dont forget to change virtual host port to 433:
SSLEngine on
SSLCertificateFile /home/ubuntu/Documents/SSL/your_domain.crt
SSLCertificateKeyFile /home/ubuntu/Documents/SSL/private.key
SSLCACertificateFile /home/ubuntu/Documents/SSL/your_domain.ca-bundle
8.  sudo a2ensite yoursite.com.secured.conf
To activate this virtual host
Besides your secured virtual host, you must have your regular virtual host with 80 port and without SSLEngine on etc. 

9. Change your Laravel .htaccess text to text below, so it will redirect all regular http request to https
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(yourdomain.com)
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI}%{QUERY_STRING} [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
10. sudo service apache2 restart :)

Thank you.
Here's an example: https://andymarrel.eu
        

Sunday, March 23, 2014

LAMP: Updating PHP from 5.3.x-ubuntu to 5.4.x (custom rep.)

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update; sudo apt-get install php5

Thanks to: http://askubuntu.com/questions/343560/update-server-php-version-to-5-4-10-via-the-command-line

Saturday, November 23, 2013

LAMP: Creating virtual hosts and resolving 500 Internal server error

This guide expects, that you already have web server on your machine.

1. Copy file /etc/apache2/sites-available/default and rename it to your host name. (for example testweb.net. Also your web application must be in /var/www/testweb.net/ directory.) Dont forget to add permissions to your web application directory using
sudo chmod -R 755 /var/www/testweb.net/ For development you can use 777, but it is still not the best practice.
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/testweb.net

2. Configure testweb.net file
gksudo gedit /etc/apache2/sites-available/testweb.net

This command will open testweb.net file in gedit text editor.

ServerName testweb.net
<VirtualHost *:80>
 ServerAdmin admin@mail.com
 ServerName testweb.net
 ServerAlias www.testweb.net
 [...]

DocumentRoot /var/www/testweb.net
I'm using my own hosts configuration file:
    ServerNametestweb.net
    ServerAlias www.testweb.net

    DocumentRoot /var/www/testweb.net
    <Directory /var/www/testweb.net>
        # enable the .htaccess rewrites
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>

    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

3. Activate your host

sudo a2ensite testweb.net

4. Edit /etc/hosts
gksudo gedit /etc/hosts
Add this line to hosts file:

127.0.0.1    testweb.net

5. Now you need to restart your apache service.
sudo service apache2 restart
Voila, your virtual host is now available!

What should you do, if you have 500 Internal Server Error? 

This problem might be caused by .htaccess file in your project root dir. First of all, check your logs (/var/log/apache2/) and try to access your site by this link: localhost/testweb.net. But for me it was not enough, so I found this solution (not sure what this command do, so run it on your own risk T_T)

sudo a2enmod rewrite
sudo service apache2 restart

Here you can read about 500 error solving: http://askubuntu.com/questions/148246/apache2-htaccess

This resource was really helpful: https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts

P.S. YEAH, I know, there are LOTS of english mistakes, sorry for that :(

Wednesday, November 13, 2013

Setting up permissions on Ubuntu for /var/www (web server)

In ubuntu all web projects are in /var/www folder, so you need to set up permissions on writing files, as by default this folder belongs to root user.

1. First of all you need to ensure, that your current user belongs to www-data group. Adding user to www-data group:

sudo adduser username www-data

You can find your username by typing this command:

whoami

2. Next we need to change /var/www folder owner and owner group:

sudo chown username:www-data -R /var/www

3. Next we need to change /var/www permissions to 755 (777 not recommended due security reasons)

sudo chmod 755 -R /var/www
sudo chmod g+s -R /var/www

Information from: http://askubuntu.com/questions/162866/correct-permissions-for-var-www-and-wordpress

Sunday, September 15, 2013

Linux Apache Mysql Php (LAMP) + phpmyadmin

sudo apt-get update
sudo apt-get install apache2
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo mysql_install_db -> activate mysql
sudo /usr/bin/mysql_secure_installation -> installation of mysql
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
sudo vim /etc/apache2/mods-enabled/dir.conf -> add index.php after DirectoryIndex
apt-cache search php5- -> all php5 extensions
sudo apt-get install php5-curl php5-gd -> install extensions

sudo apt-get install phpmyadmiin
sudo vim /etc/apache2/apache2.conf -> add line Include /etc/phpmyadmin/apache.conf
sudo service apache2 restart


source files: /var/www