How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 6*

How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 6

About LAMP


LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.

Set Up

The steps in this tutorial require the user on the virtual private server to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.

Step One—Install Apache


Apache is a free open source software which runs over 50% of the world’s web servers.

To install apache, open terminal and type in this command:

sudo yum install httpd
Once it installs, you can start apache running on your VPS:

sudo service httpd start
That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://12.34.56.789). The page should display the words “It works!” like this.

How to find your Server’s IP address


You can run the following command to reveal your server’s IP address.

ifconfig eth0 | grep inet | awk ‘{ print $2 }’

 

Step Two—Install MySQL


MySQL is a powerful database management system used for organizing and retrieving data on a virtual server

To install MySQL, open terminal and type in these commands:

sudo yum install mysql-server

sudo service mysqld start
During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install.

Once it is done installing, you can set a root MySQL password:

sudo /usr/bin/mysql_secure_installation
The prompt will ask you for your current root password.

Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.

Enter current password for root (enter for none):

OK, successfully used password, moving on…
Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
… Success!

 

Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
… Success!

 

By default, MySQL comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y

– Dropping test database…
… Success!

– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.

Reload privilege tables now? [Y/n] y
… Success!

Cleaning up…
All done!  If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

Step Three—Install PHP


PHP is an open source web scripting language that is widely used to build dynamic webpages.

To install PHP on your virtual private server, open terminal and type in this command:

sudo yum install php php-mysql
Once you answer yes to the PHP prompt, PHP will be installed.

PHP Modules


PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:

yum search php-
Terminal then will display the list of possible modules. The beginning looks like this:

php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Human Language and Character Encoding Support
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP

To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.

yum info name of the module
Once you decide to install the module, type:

sudo yum install name of the module
You can install multiple libraries at once by separating the name of each module with a space.

Congratulations! You now have LAMP stack on your droplet!

We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):

sudo chkconfig httpd on

sudo chkconfig mysqld on

 

Step Four—RESULTS: See PHP on your Server


Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:

sudo nano /var/www/html/info.php
Add in the following line:

<?php
phpinfo();
?>

Then Save and Exit.

Restart apache so that all of the changes take effect on your virtual server:

sudo service httpd restart
Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php

It should look similar to this.

See More

After installing LAMP, you can go on to do more with MySQL (A Basic MySQL Tutorial), Create an SSL Certificate, or Install an FTP Server.

By Etel Sverdlov
https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6

Create MySQL database via command line

Create MySQL database via command line

Often times you’ll find yourself wanting to quickly create a database in your MySQL installation for some project you are working on. Follow this quick guide to do so.

We’re going to create a database named ‘testing’ with a user named ‘test_user’ and a password of ‘test_pass’. We’re going to give him all privileges on this database and allow him to connect only from localhost.

First, log into the mysql shell as a privileged user:

root@localhost:~# mysql -u root -p

Now, create your database:

mysql> CREATE DATABASE testing;

Now, add your user and his access:

mysql> GRANT ALL PRIVILEGES ON testing.* TO test_user@localhost IDENTIFIED BY ‘test_pass’;

All done!

www.linux.org

Why We Love Linux

Privatejetscharter.net: Why We Love Linux

As a private jet charter company, our clientele is expecting refined, efficient, luxury on every leg of their journey. This includes our website and this is the reason Private jets Charter chose Linux and Open Source software to design our site.

Open Source gave Privatejetscharter.net the Flexibility to Grow Quickly

Running a private jet charter company is often like herding cats. Planes and orders arrive from all over the planet on a daily basis and all of this information must be flawlessly handled in order to satisfy our very demanding clients. This is a business that changes quickly and one where having enough of the right planes in the right places is critical.

Open Source software gave us the flexibility to quickly make changes to our software on demand. The lack of proprietary licenses means that we can use a variety of languages and solutions together including Java and PHP without having to worry about predefined limitations established by the software vendor. We simply haven’t enough time to deal with such nonsense.

When we need to grow our business quickly in a remote place like Western Australia there are already enough headaches as it is. Having Open Source software has given Privatejetscharter.net the agility it needs to be better than the competition. Our company has grown substantially during the last few years despite the sluggish economy in the United States and Europe. We attribute a large measure of this success to the use of Open Source and our excellent team.

Open Source Software Provides us with An Extra Layer of Security

Most online businesses are worried about the security of the information on their websites but for Privatejetscharter.net keeping the information about our clients confidential is critical to the survival of our business. Movie stars, sheiks and business moguls count on us to keep their information secure and confidential. Moreover, in the class of people we service, many of them know each other so if there are any problems other clients or potential clients are sure to hear about it. Our planes, crew and website must run flawlessly and quickly to keep our clients happy.

Open Source software gave us an extra level of security and speed that just wasn’t available through proprietary software. Our website has unique demands and we designed customized security for it that we are constantly changing and updating. Unlike static proprietary software that can be studied and then hacked in mass, attacking unique open source sites just isn’t profitable and it is much more difficult.

What Our Engineers Love About Open Source Software

The sky is the limit! Using Open Source software this is truly the case. Privatejetscharter.net is proud to have some of the most talented computer engineers in the business working for us. These are bright guys that wanted the freedom to use their extensive computer skills as they pleased to build the website in a manner that best suited the needs of our business. With Open Source they have this freedom and it has allowed them to produce a fast, amazingly beautiful and useful website that works seamlessly with the rest of our business.

Linux has given us a highly reliable posix compliant operating system and the best of class development tools available today. Our engineers have the freedom to code in a variety of ways and a worldwide support community to count on to answer questions when there are issues.

In a company with less talented individuals the complexity of Open Source and the lack of proprietary “support” might have been an issue. However, in our case our programmer’s experience combined with the vast Open Source support community has meant that our company has been very happy with the results.

In a previous life we used proprietary software and the tech support phone bills alone were a testament to the amount of time that was wasted trying to solve simple problems. In our business there just isn’t time for this type of “support.” A rival company will be more than happy to pick up any passengers we can’t (and these customers won’t come back).

Give Me Free Software or Give Me Death…

This is the new motto at Private jets Charter when it comes to computer software. Our line of business has enormous overhead and some of the strictest safety regulations on the planet. Our profit margins are always at risk and we just can’t afford to constantly update software licenses. This is an added expense that does nothing to improve our bottom line or keep us flying high.

There is a misunderstanding among much of the business community that Open Source software is fine for small blogs but that it can’t handle the needs of their company website. In fact, nothing could be further from the truth. Some of the largest and most prestigious websites on the planet use Linux including the Federal Aviation Administration, the US Department of Defense, Google and DreamWorks Animation to name only a few. Private jets Charter is happy to belong to such a prestigious crowd!

PrivateJetsCharter.net

Install a GoDaddy SSL certificate

Generate certificate for GoDaddy:

openssl genrsa -des3 -out www.sample.com.key 2048
openssl req -new -key www.sample.com.key -out www.sample.com.csr

Give to GoDaddy the contain of www.sample.com.csr

Then you’ll receive a mail on the administrative contact of the domain mail address.
After that you’ll receive from GoDaddy a zip file containing the cert, in our example sample.com.crt.

If you set up a pass when you’ve created the cert file and you want to get rid of it here is how you can remove the pass:

Always backup the original key first (just in case)!

 # cp www.sample.key www.sample.key.orig

Then unencrypt the key with openssl. You’ll need the passphrase for the decryption process:

 # openssl rsa -in www.sample.key -out new.sample.key

Now copy the new.key to the www.key file and you’re done. Next time you restart the web server, it should not prompt you for the passphrase.

mv www.sample.com.key.nopass www.sample.com.key

Then place the key and crt file into /etc/pki/tls/cets

mv sample.com.crt /etc/pki/tls/certs/
mv www.sample.com.key /etc/pki/tls/certs/

Make sure that nobody other then root can access those files:

chmod 0600 /etc/pki/tls/certs/sample.com.crt
chmod 0600 /etc/pki/tls/certs/www.sample.com.key

Configuring apache:

Install mod_ssl for apache:

yum install mod_ssl

Edit /etc/httpd/conf.d/ssl.conf according to this:

#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/pki/tls/certs/sample.com.crt
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/pki/tls/certs/www.sample.com.key
Add document root wich should contain the dir where your webfiles are stored:

DocumentRoot /virtual/web/sites/shared/www.sample.com/html

Add Directory wich should contain path to your web files:
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

Then restart the apache:

/etc/init.d/httpd restart or service httpd restart

Next you need to force http request to https. In order to do that create a .htaccess file inside your web dir containing:

RewriteEngine on
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI}