Outils pour utilisateurs

Outils du site


issue64:tutowebdev

Ceci est une ancienne révision du document !


Last month, we installed Apache2 and did a little bit of configuration. This month we will be installing and configuring MySQL, PHP, and CouchDB. MySQL is a relational database, and CouchDB is a non-relational database. We will get familiar with both types of databases over the life of this article. PHP is a server-side language that allows us to do all sorts of amazing things.

CouchDB is the starting point of this article. Even though it is not traditionally part of the LAMP stack, installing it now and learning it will be beneficial to your skills as a web developer. We are not going to go over any configurations for this until it is time to start using it. This way, you will know which settings you want to change, and what you want to change the values to. Start by updating and upgrading your software and then apt-get couchdb:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install couchdb

Yes, it really is that simple to install a lot of things. The next installation is just as easy, and it prompts you only to set a “root” password. Please note, that just because it says root password, this is not referring to the server’s root password. Make a note of this password, as this will identify the user with the ultimate power in the databases. Ok, let’s get to the installing:

sudo apt-get install mysql-server

The next part asks you a few questions regarding the security of your database. I suggest answering with “Y” to all of them. The question specifically asks about remote access with the root user. This disallows any access to MySQL unless you are on the same server (SSH to the server, and then logging in is still allowed in this scenario).

mysql_secure_installation

Now that you are all done with the installation and basic configuration of MySQL, you need to test it to make sure everything is working fine. To login, simply type in “mysql -u root -p” into the terminal. It will prompt you for the password you just set, and, upon successful entry, you will be greeted with the mysql prompt that usually looks like this: “mysql>”.

aliendev@server:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 310 Server version: 5.1.61-0ubuntu0.10.10.1 (Ubuntu)

Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

We are almost done, with just one last thing to get set-up. PHP5 is a widely used server-side language that will help you in the long run (even if you don’t use it). To install it is very simple:

sudo apt-get install php5 php-pear

Going forward, you will want to make sure the following values are set in the php.ini (PHP’s configuration file), and relevant lines are uncommented (the commented lines start with a semicolon, uncommenting them is as easy as removing the semicolon). So, open up the php.ini file with vi (“sudo vi /etc/php5/apache2/php.ini”), and look for these lines – hint: you can type “/” (forward slash) and a term and press enter to search in vi):

max_execution_time = 30

memory_limit = 64M

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

display_errors = Off

log_errors = On

error_log = /var/log/php.log

register_globals = Off

Any time you make changes to the php.ini file, you will need to restart Apache. You can do this simply by using one of the following commands:

sudo /etc/init.d/apache2 restart

sudo service apache2 restart

The very last thing we are going to do is add MySQL support for PHP, and install a PHP package that will add some additional security. Also note, because we are changing something that Apache will need to know, we need to restart it again. We could have waited, but I wanted to point out that there are a few ways to do this and that it needs to become a habit when making changes to Apache.

sudo apt-get install php5-mysql php5-suhosin

sudo service apache2 restart

Congratulations, you officially have a LAMP stack, and we can start developing next month. Cheers!

issue64/tutowebdev.1347570036.txt.gz · Dernière modification : 2012/09/13 23:00 de fredphil91