Posts Tagged ‘mysql’
Fast Symfony2 served on a stable Xubuntu
Ingredients:
Introduction:
This recipe is for people who want to install symfony2 quickly with all dependencies, without having to read the excellent documentation that can be found here:
This recipe can be used by linux users or by windows users that run linux in a virtual machine.
This will get you:
- A working Symfony2 installation
- Pretty URL’s (using mod_rewrite)
- Optimized execution speed (using php5-apc)
- Configured timezone settings and internationalization support (using php5-intl)
- Run as a specific user and not as www-data (using apache2-mpm-itk)
- Created a database and installed a database management tool (phpmyadmin).
The instructions are meant for a development platform. If you use these instructions on a production platform the least you should do is choose a more secure password. NB: You also might want to run Ubuntu Server instead of Xubuntu in such a case.
This will NOT get you:
- A debugging environment (using XDebug)
- An PHP IDE with debugging integration (Eclipse PDT)
For serious web development you might want the above: a full-featured IDE and a step-by-step debugger. This will be discussed in another post.
Instructions:
The lines below with a “-” are actions and the lines with a “$” are commands:
- Download and install Virtualbox
- Download xubuntu iso
- Configure a new Virtual Machine with:
OS set to: Linux/Ubuntu 64
4 cores (assuming you have 8 cores)
2048 MB RAM (assuming you have at least 4096)
20 GB VDI dynamic disk
- Select the Xubuntu iso file in the first run wizard
- Install Xubuntu by following the steps
- Install additional drivers (guest additions) and reboot
- Open up a web browser
- Go to http://symfony.com/download and click download
- Save "Symfony_Standard_Vendors_2.x.xx.tgz" and unpack it
- Move the "Symfony" folder to your home directory and rename it to "public_html"
$ sudo apt-get install lamp-server^ php-apc apache2-mpm-itk php5-intl php5-sqlite phpmyadmin
choose a mysql root password
choose to configure phpmyadmin for apache2
$ sudo a2enmod rewrite
$ sudo nano /etc/php5/apache2/php.ini
NB: use Ctrl-W Ctrl-R to search and replace
search: ;date.timezone =
replace: date.timezone = Europe/Amsterdam
NB: enter your local timezone if you are not in Europe/Amsterdam
(see http://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
search: short_open_tag = On
replace: short_open_tag = Off
$ pwd
NB: note down the output, as this is the path of your home folder (in my case: /home/maurits)
$ id -un
NB: note down the output, as this is your user name (in my case: maurits)
$ id -gn
NB: note down the output, as this is your group name (in my case: maurits)
$ sudo nano /etc/apache2/sites-enabled/000-default
NB: use Ctrl-W Ctrl-R to search and replace
search: /var/www
replace: {YOUR_HOME_FOLDER}/public_html/web
NB: you have to enter the home folder path you found from the pwd command instead of {YOUR_HOME_FOLDER}
$ sudo nano /etc/apache2/sites-enabled/000-default
NB: add the following line under the DocumentRoot
AssignUserId {YOUR_USER_NAME} {YOUR_GROUP_NAME}
NB: you have to enter your user name and group name instead of {YOUR_USER_NAME} {YOUR_GROUP_NAME}
$ sudo service apache2 restart
- Open web browser and go to http://127.0.0.1/phpmyadmin
- Login with root user and chosen root password
- Click "Privileges"
- Click "Add a new User"
- Enter/choose:
username: symfony
host: localhost
password: symfony
retype: symfony
- Select "Create database with same name and grant all privileges"
- Click "Create User"
- Open a web browser and go to http://127.0.0.1/config.php
- verify that symfony does not complain about anything
- click "Configure your Symfony Application online"
- Enter/choose:
Driver: MySQL (PDO)
Host: localhost
Name: symfony
User: symfony
Password: symfony
Password again: symfony
- Let symfony generate a "Global Secret"
- Choose "Next Step"
- Symfony should say: Your distribution is configured!
- Click "Go to the Welcome page"
- Click "Run the Demo"
- Play around with the demo to see that everything works
Bonus instructions:
Some nice tips on how to customize your Xubuntu:
- You can make your Xubuntu panels look like Gnome2
http://namakutux.blogspot.com/2011/11/how-to-make-xfce-looks-like-gnome-2.html - You can replace abiword/gnumeric with the much better libre office:
sudo apt-get remove abiword gnumeric && sudo apt-get install libreoffice - You can replace leafpad with the full-featured gedit:
sudo apt-get remove leafpad && sudo apt-get install gedit
That is it for today, have fun!
Adminer: good alternative for phpMyAdmin
It is not a secret that do a lot of Symfony programming at LeaseWeb. Most of the projects are PHP based and use MySQL as a database. This posts describes a gem that many experienced PHP programmers have not yet heard of.
During software development you often need a tool to quickly search the database, add a column or change a value. Most PHP developers know that phpMyAdmin is a good tool that can provide you with easy access, but only a few know that there is really good alternative for this tool called “Adminer“.
In my opinion Adminer has the advantage that it has a better user experience, but this is not the only advantage it has (or may have). According to the Adminer website there is a long list of reasons why Adminer is better than phpMyAdmin.
If you are really fond of Adminer, you might want to install it in the same way phpMyAdmin is installed. Since it is not yet part of the standard Ubuntu repositories you might want to install it manually. Here are the commands you need for installation (on a Debian based system):
$ sudo su # mkdir /usr/share/adminer # cd /usr/share/adminer # wget "http://www.adminer.org/latest.php" # ln -s latest.php adminer.php # echo "Alias /adminer.php /usr/share/adminer/adminer.php" > /etc/apache2/conf.d/adminer.conf # service apache2 restart # exit $
Once it is installed and you want to update it (it wil indicate when a new version is available):
$ sudo su # cd /usr/share/adminer # wget "http://www.adminer.org/latest.php" # exit $
To uninstall it:
$ sudo su # rm -R /usr/share/adminer # rm /etc/apache2/conf.d/adminer.conf # service apache2 restart # exit $
Try it out and let me know whether you like it or not.
Scalable RDBMS
My name is Mukesh, I worked with fairly large (or medium large) scale websites as my previous assignments – and now in LeaseWeb’s cloud team, as an innovation engineer. When I say large scale I’m talking about a website serving 300 million webpages per day (all rendered within a second), a website storing about half a billion photos & videos, a website with an active user base of ~10 million, a web application with 3000 servers …and so on!
We all know it takes a lot to keep sites like these running especially if the company has decided to run it on commodity hardware. Coming from this background, I’d like to dedicate my first blog post to the subject of scalable databases.
A friend of mine, marketing manager by profession, inspired by technology, asked me why are we using MySQL in knowing that it does not scale (or there is some special harry potter# magic?). He wanted to ask, from what reasons we have chosen MySQL? And are there any plans to move to another database?
Well the answer for later one is easy “No, we’re not planning to move to another database”. The former question however, can’t be answered in a single line.
#Talking of Harry Potter, what do you think about ‘The Deathly Hallows part -II’?
Think about Facebook – a well recognised social networking website. Facebook handles more than 25 billion page views per day; even they use MySQL.
The bottleneck is not MySQL (or any common database). Generally speaking, every database product in the market has the following characteristics to some extent:
- PERSISTENCE: Storage and (random) retrieval of data<
- CONCURRENCY: The ability to support multiple users simultaneously (lock granularity is often an issue here)
- DISTRIBUTION: Maintenance of relationships across multiple databases (support of locality of reference, data replication)
- INTEGRITY: Methods to ensure data is not lost or corrupted (features including automatic two-phase commit, use of dual log files, roll-forward recovery)
- SCALABILITY: Predictable performance as the number of users or the size of the database increase
This post deals about scalability, which we hear quite often when we talk about large systems/big data.
Data volume can be managed if you shard it. If you break the data on different servers at the application level, the scalability of MySQL is not such a big problem. Of course, you cannot make a JOIN with the data from different servers, but choosing a non-relational database doesn’t help either. There is no evidence that even Facebook uses (back in early 2008 its very own) Cassandra as primary storage, and it seems that the only things that’s needed there is a search for incoming messages.
I believe it’s a bad idea to risk your main base on new technology. It would be a disaster to lose or damage the database, and you may not be able to restore everything. Besides, if you’re not a developer of one of these newfangled databases and one of those few who actually use them in combat mode, you can only pray that the developer will fix bugs and issues with scalability as they become available.
In fact, you can go very far on a single MySQL without even caring about a partitioning data at the application level. While it’s easy to scale a server up on a bunch of kernels and tons of RAM, do not forget about replication. In addition, if the server is in front of the memcached layer (which simply scales), the only thing that your database cares is writes. For storing large objects, you can use S3 or any other distributed hash table. Until you are sure that you need to scale the base as it grows, do not shoulder the burden of making the database an order of magnitude more scalable than you need it.
Conclusion!
- Use MySQL or other classic databases for important, persistent data.
- Use caching delivery mechanisms – or maybe even NoSQL – for fast delivery
- Wait until the dust settles, and the next generation, free-semantics relational database rises up.
Tuning Zend framework and Doctrine
In principle, the combination of Zend Framework with Doctrine is not too difficult. But first let’s talk about the preparations. According to the author of Zend Framework, the default file structure of project can be a bit more optimal.
Here is the default structure of the Zend Framework project files:
/
application/
default/
controllers/
layouts/
models/
views/
html/
library/
It can often be that you will have a number of applications (e.g., frontend and backend ), and you want to use the same model for them. In this case, it can be a good practice to create your models folder in library/, in which case the new structure would look as follows:
/
application/
default/
controllers/
layouts/
views/
html/
library/
Model/
In addition, the folder models/ is renamed to Model. We now proceed as follows:
- Download a fresh copy of Doctrine-xxx-Sandbox.tgz from the official website.
- Copy the contents of the lib/folder from the archive to our project library/ folder.
- Create another folder bin/sandbox/ in the root of our project and copy the rest of the archive there (except models/ folder and the index.php file).
Now the structure of our project should look like this:
/
application/
default/
controllers/
layouts/
views/
bin/
sandbox/
data/
lib/
migrations/
schema/
config.php
doctrine
doctrine.php
html/
library/
Doctrine/
Model/
Doctrine.php
Clear the content of the folder bin/sandbox/lib/ – we now have the library in another place.
Now it’s time to configure the Doctrine to work with new file structure.
Change the value of the constant MODELS_PATH in the file bin/sandbox/config.php::
SANDBOX_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'Model'
Next, change the connection settings for the database. Change the value of the DSN constant to reflect your database settings. For example, if you use the DBMS MySQL, the DSN might look like this:
'mysql://root@localhost/mydbname'
Configure include_paths on the first line in the config file, so our script can find files on new locations:
set_include_path( '.' . PATH_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . PATH_SEPARATOR . '.' . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
Then connect the main Doctrine library file directly after installation paths, and set the startup function:
require_once 'Doctrine.php';
/**
* Setup autoload function
*/
spl_autoload_register( array(
'Doctrine',
'autoload'
));
